-1

I am using dynamic inventory and i didn't find anything about how to run a playbook with more than one user. When i configure a specific remote user in my ansible.cfg file, the ssh connection works only for the OS types that uses that specific user. I am not even sure where should it be configured? In the playbook itself i have configured to go to a different OS types. I know it works with static inventory file as well, but i have no idea how to configure it with dynamic inventory. I am using ansible galaxy role to run as ansible playbook: https://galaxy.ansible.com/geerlingguy/docker I tried configuring group_vars but it doesn't work. I need to be able to ssh to all of the instances i have using different users, using the same playbook.

This is how my dynamic inventory looks like:

plugin: aws_ec2

regions:

  - "us-east-1"

keyed_groups:

  - key: tags.Ansible

  - key: tags.Name


filters:

  tag:Ansible:

    - ubuntu

    - redhat


compose:

  ansible_host: public_ip_address

This is the playbook i run:

---

# docker.yml


- name: Use a galaxy role to install docker

  hosts: "all"

  become: true


  roles:

    - role: "geerlingguy.docker"

      tags: ["docker"]
Diana
  • 1
  • 2
    Post the output of `ansible-inventory --list --yaml`. [edit] the question and make it [mre]. Make it minimal. Omit the role. Focus on the problem `ssh connection works only for the OS types that use that specific user`. Simple task `- ping:` would do the testing. You have to get the OS type from the inventory. Otherwise, you'll have to connect to the host and find the OS type on your own. But, you can't connect without knowing the user. – Vladimir Botka Mar 08 '23 at 22:02
  • 1
    Don't stop typing after writing "but it doesn't work" as, by itself, [it does not accurately describe your problem](https://idownvotedbecau.se/itsnotworking/). Moreover describing precisely what does not work might help people getting your exact problem which is absolutely not clear as the current question is written. – Zeitounator Mar 08 '23 at 22:03

1 Answers1

0

This is the answer to my question:

# demo.aws_ec2.yml
plugin: amazon.aws.aws_ec2
regions:
  - us-east-1
keyed_groups:
  # add hosts to tag_Name_value groups for each aws_ec2 host's tags.Name variable.
  - key: tags.Ansible
    prefix: tag_Name_
    separator: ""
filters:
  tag:Ansible:
    - ubuntu
    - redhat
    
groups:
  # add hosts to the group ubuntu or redhat
  ubuntu: "'ubuntu' in (tags|list)"
  redhat: "'redhat' in (tags|list)"
  
compose:
  ansible_host: public_ip_address
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Diana
  • 1