The rax module returns data about the nodes it creates, like IP addresses, hostnames, and login passwords. By registering the return value of the step, it is possible used this data to dynamically add the resulting hosts to inventory (temporarily, in memory). This facilitates performing configuration actions on the hosts in a follow-on task. In the following example, the servers that were successfully created using the above task are dynamically added to a group called "raxhosts", with each nodes hostname, IP address, and root password being added to the inventory.
With the host group now created, the next play in this playbook could now configure servers belonging to the raxhosts group.
.. code-block:: yaml
- name: Configuration play
- name: Configuration play
hosts: raxhosts
hosts: raxhosts
...
@@ -141,7 +144,6 @@ With the host group now created, a second play in your provision playbook could
...
@@ -141,7 +144,6 @@ With the host group now created, a second play in your provision playbook could
- ntp
- ntp
- webserver
- webserver
The method above ties the configuration of a host with the provisioning step. This isn'talwayswhatyouwant,andleadsus
The method above ties the configuration of a host with the provisioning step. This isn'talwayswhatyouwant,andleadsus
tothenextsection.
tothenextsection.
...
@@ -150,41 +152,28 @@ to the next section.
...
@@ -150,41 +152,28 @@ to the next section.
HostInventory
HostInventory
``````````````
``````````````
Once your nodes are spun up, you'llprobablywanttotalktothemagain.
Onceyournodesarespunup,you'll probably want to talk to them again. The best way to handle his is to use the "rax" inventory plugin, which dynamically queries Rackspace Cloud and tells Ansible what nodes you have to manage. You might want to use this even if you are spinning up Ansible via other tools, including the Rackspace Cloud user interface. The inventory plugin can be used to group resources by metadata, region, OS, etc. Utilizing metadata is highly recommended in "rax" and can provide an easy way to sort between host groups and roles. If you don'twanttousethe``rax.py``dynamicinventoryscript,youcouldalsostillchoosetomanuallymanageyourINIinventoryfile,thoughthisislessrecommended.
directory and be sure the scripts are chmod +x, and the INI-based ones are not.
.._raxpy:
.._raxpy:
rax.py
rax.py
++++++
++++++
To use the rackspace dynamic inventory script, copy ``rax.py`` from ``plugins/inventory`` into your inventory directory and make it executable. You can specify credentials for ``rax.py`` utilizing the ``RAX_CREDS_FILE`` environment variable.
When utilizing a standard ini formatted inventory file (as opposed to the inventory plugin), it may still be adventageous to retrieve discoverable hostvar information from the Rackspace API.