公告
财富商城
积分规则
提问
发文
2020-05-20 08:20发布
你好瞎i
How to run Ansible without hosts file?
just like:
$ ansible --"Some Options" IP -a 'uptime'
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
ansible --help
-i
-i INVENTORY, --inventory-file=INVENTORY specify inventory host path (default=/etc/ansible/hosts) or comma separated host list.
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
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
最多设置5个标签!
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
Using hosts ip as comma separated host list. Take care of the comma in the end of the list
From
ansible --help
you can get-i
option descriptionIf you want run playbook at once or some more and not whole list, you can try with -l|--limit "your.node.local"
you can do like this:
Note the
,
at the end of the IP address, or it will be considered a hosts inventory filename.Here is an example for reference: