nf9
nf9

Reputation: 1

ansible auto user selection in playbook

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

Upvotes: -1

Views: 102

Answers (2)

nf9
nf9

Reputation: 1

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.

Upvotes: -1

Nikolaj Š.
Nikolaj Š.

Reputation: 1986

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.

- name: Set the system user name for Ubuntu
  set_fact:
    linux_system_user: ubuntu
  when: ansible_os_family == 'Debian'

- name: Set the system user name for CentOS
  set_fact:
    linux_system_user: centos
  when: ansible_distribution == 'CentOS'

- name: Set the system user name for RedHat
  set_fact:
    linux_system_user: root
  when: ansible_distribution == 'RedHat'

Upvotes: 1

Related Questions