Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Ansible playbook without inventory

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?

like image 609
x-yuri Avatar asked Jul 04 '16 14:07

x-yuri


People also ask

Can you run an Ansible playbook without inventory?

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.

How to run an Ansible playbook on a specific host?

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.

How do I run ansible in Python?

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 .

What is the difference between--connection and--inventory in 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.

How do I retrieve the configuration of an ansible device?

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)


1 Answers

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 
like image 193
x-yuri Avatar answered Sep 22 '22 23:09

x-yuri