AKAI TSUKI

System development or Technical something

use ansible configuration file "ansible.cfg"

I execute following command to specify inventory file "hosts" and vault password file "vault.txt".
By preparing ansible.cfg, I don't have to specify inventory file path and vault password file path every time.

[root@cent7devops ansible-test]# ansible-playbook -i hosts site.yml --vault-id vault.txt -l node01

I show prepared files.

[root@cent7devops ansible-test]# ls -1 ansible.cfg hosts vault.txt
ansible.cfg
hosts
vault.txt
[root@cent7devops ansible-test]#
[root@cent7devops ansible-test]# cat ansible.cfg
[defaults]
inventory=./hosts
vault_password_file=./vault.txt
[root@cent7devops ansible-test]#
[root@cent7devops ansible-test]# cat hosts
[grp_node]
node01 ansible_host=172.16.10.111 ansible_user=root
node02 ansible_host=172.16.10.112 ansible_user=root
node03 ansible_host=172.16.10.113 ansible_user=root
[root@cent7devops ansible-test]#

Then, The command shown at the beginning is as follows.

[root@cent7devops ansible-test]# ansible-playbook site.yml -l node01