Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Ansible without hosts file

Tags:

shell

ansible

How to run Ansible without hosts file?

just like:

$ ansible --"Some Options" IP  -a 'uptime'
like image 238
xiaoxiaoguo Avatar asked Jun 06 '16 08:06

xiaoxiaoguo


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.

Can you run Ansible on localhost?

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.

How do I see Ansible hosts?

You can use the option --list-hosts. It will show all the host IPs from your inventory file.

Does Ansible need to run as root?

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.


1 Answers

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
like image 108
Arbab Nazar Avatar answered Oct 10 '22 16:10

Arbab Nazar