How to run Ansible without hosts file?
just like:
$ ansible --"Some Options" IP -a 'uptime'
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.
This is a second method to run ansible playbook locally. You can also explicitly define your localhost in your inventory file. your inventory file can be at the default location /etc/ansible/hosts or a customized ansible_hosts file in your present working directory.
You can use the option --list-hosts. It will show all the host IPs from your inventory file.
Note: Ansible does not require root access; however, if you choose to use a non-root user, you must configure the appropriate sudo permissions for the tasks you want to accomplish. You will be prompted for the root password for servera, which will allow your SSH key to be installed on the remote host.
you can do like this:
ansible all -i "<hostname-or-ip>," -a 'uptime'
Note the ,
at the end of the IP address, or it will be considered a hosts inventory filename.
Here is an example for reference:
ansible all -i "192.168.33.100," -a 'uptime'
192.168.33.100 | SUCCESS | rc=0 >>
12:05:10 up 10 min, 1 user, load average: 0.46, 0.23, 0.08
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