Merge "Install dynamic-inventory as console_script"

This commit is contained in:
Zuul 2022-12-07 18:52:57 +00:00 committed by Gerrit Code Review
commit 38e72826a0
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
``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
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
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.
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.
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))
if __name__ == '__main__':
def main():
all_args = args(sys.argv[1:])
output = generate.main(**all_args)
print(output)
if __name__ == '__main__':
main()

View File

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