Question:
I am using the host file as below,
1 2 3 |
[qa-workstations] 10.39.19.190 ansible_user=test ansible_ssh_pass=test |
I am using below command to execute “whoami” command in host
1 2 3 4 |
root@Svr:~/ansible# ansible all -a "whoami" -i /etc/ansible/host 10.39.19.190 | success | rc=0 >> root |
ansible by default trying to use user name in which I have logged in, i.e root instead of test user which I have specified in host file
It works fine when I try to pass the username in ansible cli command
1 2 3 4 |
root@Svr:~/ansible# ansible all -a "whoami" -i /etc/ansible/host -u test 10.39.19.190 | success | rc=0 >> test |
But its not possible for me to pass username every time in CLI as different host uses different username. Also I don’t have a key pair generated for each host, because host machine keeps changing often
version used:
1 2 3 |
ansible 1.5.4 Ubuntu 14.04 LTS |
Answer:
Create an ansible.cfg in your playbook directory or modify the “global” ansible.cfg
Note: Only 1 configuration file is processed. First one wins in the below list.
http://docs.ansible.com/ansible/intro_configuration.html
- ANSIBLE_CONFIG (an environment variable)
- ansible.cfg (in the current directory)
- .ansible.cfg (in the home directory)
- /etc/ansible/ansible.cfg
1 2 3 |
[defaults] remote_user=test |