Consider if I want to check something quickly. Something that doesn't really need connecting to a host (to check how ansible
itself works, like, including of handlers or something). Or localhost
will do. I'd probably give up on this, but man page says:
-i PATH, --inventory=PATH
The PATH to the inventory, which defaults to /etc/ansible/hosts. Alternatively, you can use a comma-separated list of hosts or a single host with a trailing comma host,.
And when I run ansible-playbook
without inventory, it says:
[WARNING]: provided hosts list is empty, only localhost is available
Is there an easy way to run playbook against no host, or probably localhost
?
So, it seems this isn't widely used or documented, but it is possible to run a playbook without passing through an inventory file. It's very handy when trying to deploy hosts but you don't want to need to manage static files with host entries.
By Default, Ansible would run the playbook on the host group which is mentioned in the playbook with hosts: directive. But if you want to ignore all those hosts specified in the playbook and run it locally. You can use this method. In this way. The hosts directive would be ignored and your task would run only on localhost.
If you are running Ansible in a virtual environment, you will also need to add the variable ansible_python_interpreter=/path/to/venv/bin/python Create and run your first network Ansible Playbook ¶ If you want to run this command every day, you can save it in a playbook and run it with ansible-playbook instead of ansible .
--connection – tells ansible to run the file locally. -- inventory – tells ansible to consider this host name as an inventory [ Comma at the end is IMPORTANT] -- limit – Limiting to only this host.
Instead of manually connecting and running a command on the network device, you can retrieve its configuration with a single, stripped-down Ansible command: the host group (s) to which the command should apply (in this case, all) the inventory (-i, the device or devices to target - without the trailing comma -i points to an inventory file)
As @ydaetskcoR suggested, it's as follows:
$ ansible-playbook playbook.yml -i localhost, -k
And test playbook, for that matter
- hosts: all tasks: - debug: msg=test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With