Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add user and group without a password using Ansible?

I need to add group and user without password (nologin user) using Ansible script.

I execute the following command:

$ansible-playbook deploy_nagios_client.yml -i hosts -e hosts=qa1-jetty -v

Below is main.yml

---

# Create Nagios User and Group 
  - name: Add group "nagios"
    group: name=nagios
    become: true

  - name: Add user "nagios"  
    user: name=nagios groups=nagios password="" shell=/bin/bash append=yes comment="Nagios nologin User" state=present
    become: true

Result

like image 850
Levintovich Avatar asked Mar 29 '16 16:03

Levintovich


People also ask

How do I add users to Ansible?

First, log in to the Ansible controller host, 2. Run the following commands to create the ~/ansible_create_user directory and change to that directory. This directory will contain the playbook and all the required configuration files that you'll use to invoke the Ansible create user module.


1 Answers

If you want to create a nologin user, you should specify that to the shell argument like this:

  - name: Add user "nagios"  
    user:
      name: nagios
      groups: nagios
      shell: /sbin/nologin
      create_home: no
      append: yes
      comment: "Nagios nologin User"
      state: present
    become: true
like image 133
user2599522 Avatar answered Sep 20 '22 09:09

user2599522