`ansible -m ping` does not honor ansible.cfg's remote_user

42 views
Skip to first unread message

Yassen Damyanov

unread,
Dec 12, 2018, 5:22:36 AM12/12/18
to Ansible Project
Hi all,

Trying to ping a host prepared to accept the ping as a remote user root, I get:

$ ansible -m ping master -vvv
ansible 2.7.4
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/ydamyanov/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ydamyanov/.venv/ansible/lib/python3.7/site-packages/ansible
  executable location = /home/ydamyanov/.venv/ansible/bin/ansible
  python version = 3.7.1 (default, Oct 20 2018, 21:59:34) [GCC 5.4.0 20160609]
Using /etc/ansible/ansible.cfg as config file
/etc/ansible/hosts did not meet host_list requirements, check plugin documentation if this is unexpected
/etc/ansible/hosts did not meet script requirements, check plugin documentation if this is unexpected
Parsed /etc/ansible/hosts inventory source with ini plugin
META: ran handlers
<10.11.12.13> ESTABLISH SSH CONNECTION FOR USER: None
<10.11.12.13> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/ydamyanov/.ansible/cp/6f8bec829a 10.11.12.13 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
<10.11.12.13> (255, b'', b'Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n')
master | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n",
    "unreachable": true
}

which I would expect if I have no remote_user option set in the config:

$ cat /etc/ansible/ansible.cfg
[global]
inventory = /etc/ansible/hosts
remote_user = root

$ cat /etc/ansible/hosts
[k8s]
master  ansible_ssh_host=10.11.12.13


If I specify the remote user explicitly on the command line, it works as expected:

$ ansible -m ping master -u root
master | SUCCESS => {
    "changed": false,
    "ping": "pong"
}



Why does not ansible honor the remote_user option from the config? Am I missing something?

Thanks for your help!


Kai Stian Olstad

unread,
Dec 12, 2018, 7:35:35 AM12/12/18
to ansible...@googlegroups.com
On 12.12.2018 11:22, Yassen Damyanov wrote:
> which I would expect if I have no remote_user option set in the config:
>
> $ cat /etc/ansible/ansible.cfg
> [global]
> inventory = /etc/ansible/hosts
> remote_user = root

There is no section called global in ansible.cfg, but you have one
called defaults that takes inventory and remote_user

https://github.com/ansible/ansible/blob/devel/examples/ansible.cfg#L10

--
Kai Stian Olstad

Yassen Damyanov

unread,
Dec 12, 2018, 11:47:42 AM12/12/18
to Ansible Project

On Wednesday, December 12, 2018 at 2:35:35 PM UTC+2, Kai Stian Olstad wrote:
There is no section called global in ansible.cfg, but you have one
called defaults that takes inventory and remote_user

That was it, Kai, thanks a bunch.

Issuing a warning for such nonsense section names found looks like a good idea to me.

Cheers,
-YD
Reply all
Reply to author
Forward
0 new messages