0
votes

Actually I've defined remote_user variable for each host group. But remote_user value is not taken from defined one. Rather its using top assigned value.

Ansible version:

# ansible --version
ansible 2.3.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Jul  1 2016, 15:12:24) [GCC 5.4.0 20160609]

Playbook file : info.yml

---
- hosts: all
  remote_user: demo 
  roles:
  - common

- hosts: devlocal
  remote_user: root
  become: yes
  roles:
  - common

- hosts: testlocal
  remote_user: test
  become: yes
  roles:
  - common

when I run the playbook for hosts [ devlocal] , the users name is taken from first assignment [ i.e : "demo" ]. Actually it should use the remote_user "root" in my case.

logs :

# ansible-playbook  -i hosts -l devlocal info.yml  --ask-pass -vvvv
Using /etc/ansible/ansible.cfg as config file
SSH password: 
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/__init__.pyc

PLAYBOOK: site.yml ********************************************************************************************************************************
3 plays in site.yml

PLAY [all] ****************************************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/system/setup.py
<10.11.12.213> ESTABLISH SSH CONNECTION FOR USER: demo

Someone please help what was an issue here. Thanks in advance

2
why the question was downgraded. any reasons ?KMG

2 Answers

0
votes

Someone please help what was an issue here.

The issue here is that you specified the first play to run as demo:

- hosts: all
  remote_user: demo 
  roles:
  - common

And Ansible runs it as demo which seems not to be your objective.

That's why Ansible provides inventory mechanism, so you can specify connection details per host, not in plays.

0
votes

I've defined remote_user variable for each host group

Wrong. You've defined remote_user for each play and not host group.
Hosts and groups are defined via inventory.
So you should defined devlocal and testlocal groups with ansible_user assigned.

And have single play:

- hosts: all
  roles:
  - common