The user management module
As suggested by its name, this module is for user management on a Linux system. As an example, we will make a playbook that creates a system user named install to be used later to manage the remote machine. The playbook script is as follows :
---
- name: Linux Module running
hosts: servers
become: yes
gather_facts: false
tasks:
- name: create a system user to be used by Ansible
user:
name: install
state: present
shell: /bin/bash
group: sudo
system: yes
hidden: yes
ssh_key_file: .ssh/id_rsa
expires: -1
You can always add -v or -vvv if you want extra output when running a playbook. The following screenshot shows the output of a normal run and one with the -v option:
The same module can also be used to remove the user, either by changing their state to absent or disabling them by changing their shell to /bin/nologin. For some clustered environments, some users shared by the systems must have the same UID to be able to run tasks via the jobs handlers. The uid option can allow a particular user to have a selection of specific UIDs when creating hosts, although this is not recommended.
The modules have many special return values, which can be collected for pipelining with other modules. The most useful modules are the following:
- home: Shows the home directory for the user
- ssh_public_key: Allows the key print to be put into a file for multiple purposes
- uid: Shows the UID of the newly created user