@ -46,12 +46,20 @@ DOCUMENTATION = '''
- public_ipv6
- public_ipv6
- hostname
- hostname
- id
- id
variables :
description : ' set individual variables: keys are variable names and
values are templates . Any value returned by the
L ( Scaleway API , https : / / developer . scaleway . com / #servers-server-get)
can be used . '
type : dict
'''
'''
EXAMPLES = '''
EXAMPLES = '''
# scaleway_inventory.yml file in YAML format
# scaleway_inventory.yml file in YAML format
# Example command line: ansible-inventory --list -i scaleway_inventory.yml
# Example command line: ansible-inventory --list -i scaleway_inventory.yml
# use hostname as inventory_hostname
# use the private IP address to connect to the host
plugin : scaleway
plugin : scaleway
regions :
regions :
- ams1
- ams1
@ -59,13 +67,25 @@ regions:
tags :
tags :
- foobar
- foobar
hostnames :
hostnames :
- public_ipv4
- hostname
variables :
ansible_host : private_ip
state : state
# use hostname as inventory_hostname and public IP address to connect to the host
plugin : scaleway
hostnames :
- hostname
regions :
- par1
variables :
ansible_host : public_ip . address
'''
'''
import json
import json
from ansible . errors import AnsibleError
from ansible . errors import AnsibleError
from ansible . plugins . inventory import BaseInventoryPlugin
from ansible . plugins . inventory import BaseInventoryPlugin , Constructable
from ansible . module_utils . scaleway import SCALEWAY_LOCATION
from ansible . module_utils . scaleway import SCALEWAY_LOCATION
from ansible . module_utils . urls import open_url
from ansible . module_utils . urls import open_url
from ansible . module_utils . _text import to_native
from ansible . module_utils . _text import to_native
@ -152,7 +172,7 @@ extractors = {
}
}
class InventoryModule ( BaseInventoryPlugin ):
class InventoryModule ( BaseInventoryPlugin , Constructable ):
NAME = ' scaleway '
NAME = ' scaleway '
def _fill_host_variables ( self , host , server_info ) :
def _fill_host_variables ( self , host , server_info ) :
@ -163,7 +183,6 @@ class InventoryModule(BaseInventoryPlugin):
" organization " ,
" organization " ,
" state " ,
" state " ,
" hostname " ,
" hostname " ,
" state "
)
)
for attribute in targeted_attributes :
for attribute in targeted_attributes :
self . inventory . set_variable ( host , attribute , server_info [ attribute ] )
self . inventory . set_variable ( host , attribute , server_info [ attribute ] )
@ -175,7 +194,6 @@ class InventoryModule(BaseInventoryPlugin):
if extract_public_ipv4 ( server_info = server_info ) :
if extract_public_ipv4 ( server_info = server_info ) :
self . inventory . set_variable ( host , " public_ipv4 " , extract_public_ipv4 ( server_info = server_info ) )
self . inventory . set_variable ( host , " public_ipv4 " , extract_public_ipv4 ( server_info = server_info ) )
self . inventory . set_variable ( host , " ansible_host " , extract_public_ipv4 ( server_info = server_info ) )
if extract_private_ipv4 ( server_info = server_info ) :
if extract_private_ipv4 ( server_info = server_info ) :
self . inventory . set_variable ( host , " private_ipv4 " , extract_private_ipv4 ( server_info = server_info ) )
self . inventory . set_variable ( host , " private_ipv4 " , extract_private_ipv4 ( server_info = server_info ) )
@ -233,6 +251,9 @@ class InventoryModule(BaseInventoryPlugin):
self . inventory . add_host ( group = group , host = hostname )
self . inventory . add_host ( group = group , host = hostname )
self . _fill_host_variables ( host = hostname , server_info = host_infos )
self . _fill_host_variables ( host = hostname , server_info = host_infos )
# Composed variables
self . _set_composite_vars ( self . get_option ( ' variables ' ) , host_infos , hostname , strict = False )
def parse ( self , inventory , loader , path , cache = True ) :
def parse ( self , inventory , loader , path , cache = True ) :
super ( InventoryModule , self ) . parse ( inventory , loader , path )
super ( InventoryModule , self ) . parse ( inventory , loader , path )
self . _read_config_data ( path = path )
self . _read_config_data ( path = path )