How to specify a username in a host file

I am using the host file as shown below

[qa-workstations]
10.39.19.190 ansible_user=test ansible_ssh_pass=test

I use the command below to execute the whoami command in the host

root@Svr:~/ansible# ansible all -a "whoami" -i /etc/ansible/host
10.39.19.190 | success | rc=0 >>
root

by default, it tries to use the username in which I logged in, i.e. root instead of the test user that I specified in the host file

It works fine when I try to pass the username in the unsible cli command

root@Svr:~/ansible# ansible all -a "whoami" -i /etc/ansible/host -u test
10.39.19.190 | success | rc=0 >>
test

But I will not be able to pass the username every time in the CLI, because the other host uses a different username. Also I do not have a key pair generated for each host, because the host machine often changes

Used version

:

 ansible 1.5.4 
 Ubuntu 14.04 LTS
+4
source share
2 answers

ansible.cfg "global" ansible.cfg

. . . http://docs.ansible.com/ansible/intro_configuration.html

  • ANSIBLE_CONFIG ( )
  • ansible.cfg( )
  • .ansible.cfg( )
  • /etc/ansible/ansible.cfg
[defaults]
remote_user=test
+1

Ansible ansible_user .

, mysql-host.mydomain , , mysql:

[docker-hosts]
mysql-host.mydomain ansible_user=mysql

, , ansible_ssh_user

http://docs.ansible.com/ansible/faq.html#how-do-i-handle-different-machines-needing-different-user-accounts-or-ports-to-log-in-with

+5

Source: https://habr.com/ru/post/1620546/


All Articles