0

I have ansible filtering option defined with following playbook. But when executed with centos user it is not filtering by user to run. I have to run this playbook 3 times with 3 different user:

1. centos 
2. ec2-user
3. admin 

This is how I am executing

1. ansible-playbook -i inventory -u admin   group_by.yaml
2. ansible-playbook -i inventory -u ec2-user   group_by.yaml
3. ansible-playbook -i inventory -u centos   group_by.yaml

The problem is remote_user is not working. It is filtering and grouping.

--- 
- name: Run tasks based on OS
  hosts: all 
  tasks: 
    - name: Group OS
      group_by: 
        key: "{{ ansible_distribution }}"

- hosts: CentOS
  become: yes
  become_user: root
  remote_user: centos
  tasks:
    - name: Install on centos 
      package: 
        name: telnet
        state: absent

- hosts: Amazon
  become: yes
  become_user: root
  remote_user: ec2-user
  tasks:
    - name: Install on ec2 
      package: 
        name: telnet

- hosts: Debian
  become: yes
  become_user: root
  remote_user: admin
  tasks:
    - name: Install on debian 
      package: 
        name: telnet

I have run the command already multiple times. it is picking my default user. Remote_user is not working in playbook.

  • 2
    I am not sure but the above won't work with different user. the `group_by` var would map to the ansible fact per host and run the associated tasks. but in all cases it would assume the user is same across all the hosts and will try to ssh using that user to gather the facts. so the best use case would be to use same user for different version of same linux distro – error404 Jun 08 '19 at 16:57
  • 1
    As reported by @error404, you've hit a chicken-and-egg problem. You need to run the setup module (i.e. gather_facts in your first play) to know the distribution in order to decide which user to use... but you need to know which user to use to run the setup module... unsolvable. – Zeitounator Jun 10 '19 at 13:07

0 Answers0