How to run Ansible without hosts file

2020-05-20 08:20发布

How to run Ansible without hosts file?

just like:

$ ansible --"Some Options" IP  -a 'uptime'

标签: shell ansible
3条回答
对你真心纯属浪费
2楼-- · 2020-05-20 08:45

Hosts can be given to ansible using three ways

  • Using inventory path in ansible.cfg which is /etc/ansible/host by default

  • Using hosts file

    ansible -i /tmp/hosts -a 'uptime'
    
  • Using hosts ip as comma separated host list. Take care of the comma in the end of the list

    ansible -i "192.168.1.16,192.168.1.80:2222," -a 'uptime'   
    

From ansible --help you can get -i option description

-i INVENTORY, --inventory-file=INVENTORY
                    specify inventory host path
                    (default=/etc/ansible/hosts) or comma separated host
                    list.
查看更多
SAY GOODBYE
3楼-- · 2020-05-20 08:45

If you want run playbook at once or some more and not whole list, you can try with -l|--limit "your.node.local"

ansible-playbook -i inventory.hosts --limit your.node.local user.yml
查看更多
我想做一个坏孩纸
4楼-- · 2020-05-20 08:58

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
查看更多
登录 后发表回答