Install dynamic-inventory as console_script

If you want to store openstack_deploy content you want it's content
to be relevant. However, at the moment it's quite hard to predict how
inventory will be generated if/when adding some new host to it.

Installing dynamic_inventory script as a console_script will allow you
to create quite simple tox env to update openstack_inventory.json
on local machine right after changing config and simplify life of
operator. Also this way you don't need to clone openstack-ansible

Change-Id: I6119b0bfc27d173610657f39ebb717e0a18b247e
This commit is contained in:
Dmitriy Rabotyagov 2022-11-02 18:24:10 +01:00 committed by Dmitriy Rabotyagov
parent 79fc2a604d
commit 9dc3e8b213
3 changed files with 56 additions and 2 deletions

View File

@ -2,7 +2,8 @@ Generating the Inventory
======================== ========================
The script that creates the inventory is located at The script that creates the inventory is located at
``inventory/dynamic_inventory.py``. ``inventory/dynamic_inventory.py`` and installed into the ansible-runtime
virtualenv as ``openstack-ansible-inventory``.
This section explains how ansible runs the inventory, and how This section explains how ansible runs the inventory, and how
you can run it manually to see its behavior. you can run it manually to see its behavior.
@ -22,6 +23,14 @@ Run the following command:
# from the root folder of cloned OpenStack-Ansible repository # from the root folder of cloned OpenStack-Ansible repository
inventory/dynamic_inventory.py --config /etc/openstack_deploy/ inventory/dynamic_inventory.py --config /etc/openstack_deploy/
Dynamic inventory script is also installed inside virtualenv as a script. So
alternatively you can run following:
.. code-block:: bash
source /opt/ansible-runtime/bin/activate
openstack-ansible-inventory --config /etc/openstack_deploy/
This invocation is useful when testing changes to the dynamic inventory script. This invocation is useful when testing changes to the dynamic inventory script.
Inputs Inputs
@ -125,3 +134,40 @@ debugging the inventory script's behavior. The output is written to
The ``inventory.log`` file is appended to, not overwritten. The ``inventory.log`` file is appended to, not overwritten.
Like ``--check``, this flag is not invoked when running from ansible. Like ``--check``, this flag is not invoked when running from ansible.
Running with tox
~~~~~~~~~~~~~~~~
In some cases you might want to generate inventory on operator local machines
after altering openstack_user_config.yml or env.d/conf.d files. Given that
you already have ``openstack_deploy`` directory on such machine, you can create
tox.ini file in that directory with following content:
.. code-block::
[tox]
envlist = generate_inventory
[testenv]
skip_install = True
usedevelop = True
allowlist_externals =
bash
[testenv:generate_inventory]
basepython = python3
deps = -rhttps://opendev.org/openstack/openstack-ansible/raw/branch/master/requirements.txt
install_command =
pip install -c https://releases.openstack.org/constraints/upper/master {packages} git+https://opendev.org/openstack/openstack-ansible@master
commands =
osa-dynamic-inventory --config {toxinidir}
Then you can run a command to generate inventory using tox:
.. code-block:: bash
tox -e generate_inventory
As a result you will get your openstack_user_config.json updated. You can use
this method also to verify validity of the inventory.

View File

@ -75,7 +75,11 @@ def args(arg_list):
return vars(parser.parse_args(arg_list)) return vars(parser.parse_args(arg_list))
if __name__ == '__main__': def main():
all_args = args(sys.argv[1:]) all_args = args(sys.argv[1:])
output = generate.main(**all_args) output = generate.main(**all_args)
print(output) print(output)
if __name__ == '__main__':
main()

View File

@ -25,3 +25,7 @@ universal = 1
[files] [files]
packages = osa_toolkit packages = osa_toolkit
[entry_points]
console_scripts =
openstack-ansible-inventory = inventory.dynamic_inventory:main