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
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With