From ab703e2a321aad071fc78349499859103e6f6ea6 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Wed, 22 Apr 2020 21:39:02 -0400 Subject: [PATCH] Add feature docs and document development tooling --- docs/inventory/inventory_plugins.md | 32 ++++++++----- tools/collections/README.md | 34 ++++++++++++++ tools/collections/clone_vendor.sh | 71 +++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 11 deletions(-) create mode 100644 tools/collections/README.md create mode 100644 tools/collections/clone_vendor.sh diff --git a/docs/inventory/inventory_plugins.md b/docs/inventory/inventory_plugins.md index 00a763b361..01bf66fea6 100644 --- a/docs/inventory/inventory_plugins.md +++ b/docs/inventory/inventory_plugins.md @@ -1,8 +1,12 @@ # Transition to Ansible Inventory Plugins -Inventory updates have changed from using scripts, which are vendored as executable Python scripts, to using dynamically-generated YAML files which conform to the specifications of the `auto` inventory plugin. These are then parsed by their respective inventory plugin. +Inventory updates have changed from using deprecated inventory scripts, to using dynamically-generated YAML files which are parsed by their respective inventory plugin. -The major organizational change is that the inventory plugins are part of the Ansible core distribution, whereas the same logic used to be a part of AWX source. +In Ansible 2.8, the inventory plugins which are part of the Ansible core distribution were used. +This only applied to a few select sources. + +In all other circumstances, inventory imports make use of the inventory plugin from vendored collections. +Those collections are downloaded from Ansible Galaxy at the time of packaging building the container image. ## Prior Background for Transition @@ -14,11 +18,10 @@ AWX used to maintain logic that parsed `.ini` inventory file contents, in additi The CLI entry point `ansible-inventory` was introduced in Ansible 2.4. In Tower 3.2, inventory imports began running this command as an intermediary between the inventory and the import's logic to save content to the database. Using `ansible-inventory` eliminates the need to maintain source-specific logic, relying on Ansible's code instead. This also enables consistent data structure output from `ansible-inventory`. There are many valid structures that a script can provide, but the output from `ansible-inventory` will always be the same, thus the AWX logic to parse the content is simplified. This is why even scripts must be ran through the `ansible-inventory` CLI. -Along with this switchover, a backported version of `ansible-inventory` was provided, which supports Ansible versions 2.2 and 2.3. - ### Removal of Backport +Along with the `ansible-inventory` switchover, a backported version of `ansible-inventory` was provided, which supported Ansible versions 2.2 and 2.3. In AWX 3.0.0 (and Tower 3.5), the backport of `ansible-inventory` was removed, and support for using custom virtual environments was added. This set the minimum version of Ansible necessary to run _any_ inventory update to 2.4. @@ -30,9 +33,21 @@ In AWX 4.0.0 (and Tower 3.5) inventory source types start to switch over to plug To see in which version the plugin transition will happen, see `awx/main/models/inventory.py` and look for the source name as a subclass of `PluginFileInjector`, and there should be an `initial_version`, which is the first version that was deemed (via testing) to have sufficient parity in the content for its inventory plugin returns. For example, `openstack` will begin using the inventory plugin in Ansible version 2.8. If you run an OpenStack inventory update with Ansible 2.7.x or lower, it will use the script. -The eventual goal is for all source types to have moved to plugins. For any given source, after the `initial_version` for plugin use is higher than the lowest supported Ansible version, the script can be removed and the logic for script credential injection will also be removed. +At some point, scripts will be removed and the script-related (for credentials and configuration) logic will also be removed. -For example, after AWX no longer supports Ansible 2.7, the script `awx/plugins/openstack_inventory.py` will be removed. + +### Management of Collections + +Collections are used for inventory imports starting in Ansible 2.9, and each collection has its own versioning independently from Ansible. +Versions for those collections are set in the requirements file `requirements/collections_requirements.yml`. + +The location of vendored collections is set by the file-only setting `INVENTORY_COLLECTIONS_ROOT`. +For development purposes, this can be changed so that you can test against development versions of those collections. +Instructions for doing this are in `tools/collections`. + +If, for some reason, you need to change the version of a particular collection used in inventory imports, +you can use the `ansible-galaxy` tool to update the collection inside of the `INVENTORY_COLLECTIONS_ROOT`. +Note that the logic for building the inventory file is written and tested only for the version pinned in the requirements file. ## Changes to Expect in Imports @@ -54,11 +69,6 @@ More `hostvars` will appear if the inventory plugins are used. To maintain backw A small number of `hostvars` will be lost because of general deprecation needs. -#### Host Names - -In many cases, the host names will change. In all cases, accurate host tracking will still be maintained via the host `instance_id`. - - ## Writing Your Own Inventory File If you do not want any of this compatibility-related functionality, then you can add an SCM inventory source that points to your own file. You can also apply a credential of a `managed_by_tower` type to that inventory source that matches the credential you are using, as long as it is not `gce` or `openstack`. diff --git a/tools/collections/README.md b/tools/collections/README.md new file mode 100644 index 0000000000..932a846014 --- /dev/null +++ b/tools/collections/README.md @@ -0,0 +1,34 @@ +### Inventory Updates Cross-Development with Collections + +Inventory updates in production use vendored collections baked into the image, +which are downloaded from Ansible Galaxy in the build steps. + +This gives instructions to short-circuit that process for a faster development process. + +Running this script will do a `git clone` for all the relevant collections +into the folder `awx/plugins/collections`. + +``` +source tools/collections/clone_vendor.sh +``` + +After this is completed, you must change the path where the server looks +for the vendored inventory collections. +Add this line to your local settings: + +``` +INVENTORY_COLLECTIONS_ROOT = '/awx_devel/awx/plugins/collections' +``` + +Then when you run an inventory update of a particular type, it should +use the cloned collection. +This allows you to cd into a particular collection, add remotes, +change branches, etc. + +#### Extra Build Steps + +This will not work correctly in all circumstances. +Some collections make changes at build-time. + +In particular, the foreman inventory plugin needs the NAME attribute changed to +the fully-qualified collection name, and will fail if this is not done. diff --git a/tools/collections/clone_vendor.sh b/tools/collections/clone_vendor.sh new file mode 100644 index 0000000000..06f6e19956 --- /dev/null +++ b/tools/collections/clone_vendor.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +base_dir=awx/plugins/collections/ansible_collections + +if [ ! -d "$base_dir/azure/azcollection" ] +then + mkdir -p $base_dir/azure + git clone https://github.com/ansible-collections/azure.git $base_dir/azure/azcollection +else + echo "Azure collection already exists" +fi + +if [ ! -d "$base_dir/ansible/amazon" ] +then + mkdir -p $base_dir/ansible + git clone https://github.com/ansible-collections/ansible.amazon.git $base_dir/ansible/amazon +else + echo "Amazon collection already exists" +fi + +if [ ! -d "$base_dir/theforeman/foreman" ] +then + mkdir -p $base_dir/theforeman + git clone https://github.com/theforeman/foreman-ansible-modules.git $base_dir/theforeman/foreman +else + echo "foreman collection already exists" +fi + +if [ ! -d "$base_dir/google/cloud" ] +then + mkdir -p $base_dir/google + git clone https://github.com/ansible-collections/ansible_collections_google.git $base_dir/google/cloud +else + echo "google collection already exists" +fi + +if [ ! -d "$base_dir/openstack/cloud" ] +then + mkdir -p $base_dir/openstack + git clone https://github.com/openstack/ansible-collections-openstack.git $base_dir/openstack/cloud +else + echo "openstack collection already exists" +fi + +if [ ! -d "$base_dir/community/vmware" ] +then + mkdir -p $base_dir/community + git clone https://github.com/ansible-collections/vmware.git $base_dir/community/vmware +else + echo "VMWare collection already exists" +fi + +if [ ! -d "$base_dir/ovirt/ovirt_collection" ] +then + mkdir -p $base_dir/ovirt + git clone $base_dir/ovirt/ovirt_collection +else + echo "Ovirt collection already exists" +fi + +if [ ! -d "$base_dir/awx/awx" ] +then + mkdir -p $base_dir/awx + ln -s $(shell pwd)/awx_collection $base_dir/awx/awx + git clone $base_dir/awx/awx +else + echo "awx collection already exists" +fi + +echo "-- confirmation of what is installed --" +ANSIBLE_COLLECTIONS_PATHS=awx/plugins/collections ansible-galaxy collection list