[ansible] Doing useradd with multiple linux servers


ubs3 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 ubs1 ubs2 ubs3

There are predefined linux servers hostnames, these hostnames have to be within the /etc/ansible/hosts in order to execute the yaml.

Yaml for creating user

--- # start of YAML file
- hosts: linux # ubs1,ubs2,ubs3 defined in /etc/ansible/hosts
  become: true # required privilege escalation
  become_user: root # escalated to root, i.e. sudo
   - name: create user # name for this task
     user: # user module see https://docs.ansible.com/ansible/latest/modules/user_module.html
       name: unixadm # username to be created.
       group: sudo # join this user to sudo group
       shell: /bin/bash # allow unixadm to use /bin/bash
       password: $6$jhdI.QNeBQQd5YLI$L1nUAC0utehr.kHzaurps5a1i.y5k4.LQ9bo/WjE8O0DSaHnUy/H9wyKwmzla/Ijc/02SUvWTypt4KsQCdZ9C. # Use https://www.mkpasswd.net/index.php to generate hash password
       state: present # present means i want username to exist, hence creating a user.
... # end of YAML file

I used an online mkpasswd to generate the hash for a password.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s