Home:ALL Converter>Ansible run playbook on IP in CLI, load variables from inventory

Ansible run playbook on IP in CLI, load variables from inventory

Ask Time:2021-03-06T15:54:35         Author:NeverEndingQueue

Json Formatter

I normally run playbook like this: ansible-playbook -i live nginx.yml.

My hosts are defined in live/inventory and variables are defined in live/group_vars.

In need to run this playbook on a dynamic IP host where I need to provide IP as an argument in the CLI.

I can achieve it with this syntax: ansible-playbook -i 113.45.97.11, nginx.yml, however I lose the possibility of loading the -i live inventory with required variables.

Is there any way to load the variables from live directory?

I've tried: --extra-vars "@live", but then I get

ERROR! an error occurred while trying to read the file '/home/tomek/data/bomcheck-ansible/live': [Errno 21] Is a directory: b'/home/tomek/data/bomcheck-ansible/live'

as it seems it can't read the directory.

What are the options? Basically I am trying to run playbook, along with the variables defined in the inventory, on a host defined dynamically via command line.

Author:NeverEndingQueue,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/66503544/ansible-run-playbook-on-ip-in-cli-load-variables-from-inventory
yy