I have a simple playbook that I run on new managed nodes for Ansible
the playbook has 3 roles : create ansible admin user on destination host , copy ssh key , sets sudo no passwd for ansible user
I have Rhel based nodes and also debian based nodes
for Rhel I use root , for debian root not used by default and I keep it that way so I have a different admin user called sysadmin
I am trying to find a way that the playbook will identify the OS and choose either root or sysadmin user to run the Play , and also use a proper password from a file in ansible vault
thanks
this is the playbook
-
name: init managed node
user: root
hosts: init_clients
become: yes
gather_facts: yes
ignore_errors: no
vars:
user: ansible-admin
passwd: password-hashroles:
- create_admin_user
- set_authorized_key
- set_no_pass
2
Answers
My issue is that Ansible still needs to run the first Playbook as some user if that user is the same for all systems (root for example).
That's ok if the user is not the same.
I have to run the playbook once for Rhel and once for Debian and then change the "user" statement to a differener user.
100% real code. But if I didn’t have it at my fingertips, I would skip answering this question, as there’s no indication of any effort on your part.