Pages

Saturday, 23 November 2019

EX294: Create a static host inventory file

This blog is just a simple example of static inventories, more information can be found at Ex294: Inventories.

1 Default inventory file

The default inventory file is /etc/ansible/hosts, which will be created automatically during the installation of Ansible.

2 Using non-default inventory files

Both "ansible" and "ansible-playbook" support a command-line option "-i" or "--inventory" to specify inventory.

ansible all -i ./myhosts -m shell -a 'hostname'
ansible-playbook --inventory=./myhosts playbook.yml

3 A simple static inventory file example

[web]
www1
www2

[web:vars]
ansible_ssh_user=user01

[db]
db1 foo=bar
db2

[centos]
www1
db1

[win2016]
www2
db2


No comments:

Post a Comment