Last active
May 5, 2023 23:16
-
-
Save lilongen/ebc11f69ae2ba48971c77527d5c02fab to your computer and use it in GitHub Desktop.
How to run Ansible without specifying the inventory but the host directly?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Question: | |
. How to run Ansible without specifying the inventory but the host directly? | |
. Run a playbook or command with arbitrary host not in the inventory hosts list? | |
. run ansible with arbitrary host/ip without inventory? | |
Answer: | |
Surprisingly, the trick is to append a , | |
The host parameter preceding the , can be either a hostname or an IPv4/v6 address. | |
ansible all -i example.com, | |
ansible all -i 93.184.216.119, | |
ansible-playbook -i example.com, playbook.yml # Requires 'hosts: all' in the playbook |
Just to add some explanation to this: this is because <ip|host>,
is being processed by the host_lists
ansible inventory plugin which dynamically creates an inventory from a series of targets separated by commas. If there aren't commas on your target specification the plugin won't trigger and thus, won't create the inventory.
I'm a bit unclear still on what is going on here. does this mean that example.com will be defined to reach 93.184.216.119?
can this ansible all -i ip1,ip2-m shell -a "ifconfig"
. be executed on two machine?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good trick!