Rackspace and AWX

Hi,

I am trying to get AWX going with our Rackspace cloud. I already have Ansible & Tower scripts running for our cloud. At the moment I have two issues:

  1. I cannot provision new VMs because pyrax is not installed. This is a Python module. How do I add this to AWX?

  2. I cannot get an inventory. I can see the openstack inventory plugin, but I can’t see any documentation on how to configure this for Rackspace. Should I be be using this plugin or a custom script?

Larry Singer

Howdy Larry,

At one time we did support Rackspace inventory and modules directly (in downstream Tower). This was deprecated in our last major release and was removed several months ago from our mainline development branch. We did this because we actually found it difficult to maintain the shared dependencies between pyrax and openstack.

It might be totally possible to support these but you’ll need to update the the container image and rebuild (in the form of updating the requirements files). In the process of deprecating this the inventory source was removed. If you solve the dependency issues then you can import the inventory script into the custom inventory script system and add a username/password credential source for it.

If you can get it to work let us know… pyrax gave us a whole lot of grief.

Hi Matthew,

Thank you for your reply.

I am happy to try to use the openstack inventory and Ansible modules. I can’t find any doco on how to configure these. Are you able to point me in the right direction?

Larry Singer

I am getting stack traces when running the openstack plugin:

2017-09-29 03:44:25,668 INFO awx.main.commands.inventory_import Updating inventory 2: Rackspace
2017-09-29 03:44:25,681 DEBUG awx.main.commands.inventory_import Using system install of ansible-inventory CLI: /usr/bin/ansible-inventory 2
017-09-29 03:44:25,681 INFO awx.main.commands.inventory_import Reading Ansible inventory source: /usr/lib/python2.7/site-packages/awx/plugins/inventory/openstack.py
Traceback (most recent call last): File “/usr/bin/awx-manage”, line 9, in load_entry_point(‘awx==1.0.0.561’, ‘console_scripts’, ‘awx-manage’)()
File “/usr/lib/python2.7/site-packages/awx/init.py”, line 107, in manage execute_from_command_line(sys.argv)
File “/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/init.py”, line 354, in execute_from_command_line utility.execute()
File “/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/init.py”, line 346, in execute self.fetch_command(subcommand).run_from_argv(self.argv)
File “/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/base.py”, line 394, in run_from_argv self.execute(*args, **cmd_options)
File “/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/base.py”, line 445, in execute output = self.handle(*args, **options)
File “/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/base.py”, line 661, in handle return self.handle_noargs(**options)
File “/usr/lib/python2.7/site-packages/awx/main/management/commands/inventory_import.py”, line 979, in handle_noargs self.is_custom)
File “/usr/lib/python2.7/site-packages/awx/main/management/commands/inventory_import.py”, line 234, in load_inventory_source is_custom=is_custom).load()
File “/usr/lib/python2.7/site-packages/awx/main/management/commands/inventory_import.py”, line 179, in load data = self.command_to_json(base_args + [‘–list’])
File “/usr/lib/python2.7/site-packages/awx/main/management/commands/inventory_import.py”, line 163, in command_to_json self.method, proc.returncode, stdout, stderr))
RuntimeError: ansible-inventory failed (rc=4) with stdout:

stderr:
ERROR! Could not parse inventory source /usr/lib/python2.7/site-packages/awx/plugins/inventory/openstack.py with available plugins:
Plugin script failed: Inventory script (/usr/lib/python2.7/site-packages/awx/plugins/inventory/openstack.py) had an execution error: Error fetching server list on devstack::

Plugin ini failed: /usr/lib/python2.7/site-packages/awx/plugins/inventory/openstack.py:48: Expected key=value host variable assignment, got: argparse

I think this is because the Openstack inventory plugin imports packages os_client_config and shade and these are installed in the Docker container. I am not having any success in adding these either manually through the container shell, or via the install script.

os-client-config is installed both in our AWX environment:

https://github.com/ansible/awx/blob/devel/requirements/requirements.txt#L116

and in the ansible execution environment:

https://github.com/ansible/awx/blob/devel/requirements/requirements_ansible.txt#L75

So you don’t need to install it by hand… this looks like it could be some other issue.

If you try to run the inventory script from inside of the container what does it look like?

Matthew,

I run sudo docker exec -it awx_task /bin/bash to get into the container, then:
[root@awx awx]# /usr/lib/python2.7/site-packages/awx/plugins/inventory/openstack.py
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/awx/plugins/inventory/openstack.py", line 60, in <module>
import os_client_config
ImportError: No module named os_client_config

Is this running the wrong install of Python? I remember seeing something about running embedded python somewhere, but I can’t find any doco on it.

Larry

you’ll need to activate the virtualenv:

$ source /var/lib/awx/venv/awx/bin/activate
$ /usr/lib/python2.7/site-packages/awx/plugins/inventory/openstack.py

Matthew,

I got the plugin running inside the container, but it is not running from the inventory. This appears to be related to Issue https://github.com/ansible/awx/issues/268 . This points me at the code I need to look at, which appears to only support devstack. I’ll see what I can do to make this work.

Larry

Matthew,

I have been trying to trace the execution of this by inserting logger statements. This is my understanding so far:

The Inventory Source refresh in the UI calls class AnsibleInventoryLoader in /awx/main/management/commands/inventory_import.py. This runs the command

/usr/bin/ansible-inventory -i /usr/lib/python2.7/site-packages/awx/plugins/inventory/openstack.py --list

An environment variable OS_CLIENT_CONFIG_FILE points to a temporary file with the settings to get the inventory. (I need to change the contents of this file to support Rackspace.)

The class RunInventoryUpdate in /awx/main/tasks.py prepares the temporary settings file.

I cannot see RunInventoryUpdate being called.

I have changed the data that is output by RunInventoryUpdate (/usr/lib/python2.7/site-packages/awx/main/tasks.py in Docker container awx_task), but the temporary settings file is not changing when I refresh the inventory.

Can you tell me where RunInventoryUpdate (or some other code) is preparing the temporary settings file?

Larry

The task container will need to be restarted before it picks up the changes that you are making in tasks.py

You might consider using the development environment rather than the production environment when working with this: https://github.com/ansible/awx/blob/devel/CONTRIBUTING.md

Matthew,

Thanks, restarting the container worked. I’ll see if I can work out what needs be changed to support this in the codebase.

Larry

Hi,

I would like some guidance on the best way to implement some changes to support Rackspace inventories using the openstack inventory plugin. This can be done without major changes to the codebase. The method build_private_data() in RunInventoryUpdate in awx/main/tasks.py needs to be changed to be able to generate a file that supports Rackspace (and retain backward compatibility for devstack). The file needs to contain the rax data as shown in awx/plugins/inventory/openstack.yml rather than the devstack data.

To do this we need to be able to tell the difference between a devstack inventory and a Rackspace inventory. I have identified a few ways this could be done:

  • Create a new credentials type for Rackspace and supply these to the inventory source.
  • Reuse the OpenStack credentials type: Username, Password and Project fields would remain the same, Host field would be “rackspace” to identify that these are Rackspace credentials, Domain Name field could be reused to hold region names.
  • Use variables on the inventory source to identify a Rackspace source: profile: rackspace, region_name: SYD

Thanks in advance.

Larry Singer

I’m a bit confused Larry. Do you want to get Rackspace Dynamic Inventory Script to work in Tower or OpenStack Dynamic Inventory Script?

FYI, this was the commit that removed support for Rackspace in Tower https://github.com/ansible/awx/commit/cfb633e8a643b0190fa07b6204b339a1d336cbb3

Christopher,

I am trying to use terms from the AWX UI, rather than from Ansible Tower. The OpenStack inventory source (dynamic inventory) can support Rackspace if different parameters are passed to the inventory plugin. This is about the best way to get those parameters to the OpenStack plugin.

Larry

I reckon I’d prefer a standalone credential… but I will point out that we removed support for rax originally because of the dependency conflict. If you can make it work then I’m all ears.

Matthew,

The old Rackspace inventory (and the ansible modules) used a package pyrax. This has been deprecated by Rackspace. The openstack inventory plugin in AWX does allow access to Rackspace without any extra packages. So we should be able to support Rackspace without Pyrax.

I will have a go at a separate credential for Rackspace.

Larry

Excellent, carry on then!