官术网_书友最值得收藏!

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
主站蜘蛛池模板: 寿光市| 合江县| 新竹县| 文安县| 洪雅县| 聂荣县| 滁州市| 上高县| 青龙| 蚌埠市| 玉溪市| 洛浦县| 巴林左旗| 陇川县| 抚松县| 都昌县| 衡山县| 双峰县| 陕西省| 合水县| 龙岩市| 金坛市| 虹口区| 黑山县| 绥棱县| 抚顺市| 淮安市| 巴彦淖尔市| 南昌市| 南昌市| 浦江县| 鄂尔多斯市| 海门市| 噶尔县| 广饶县| 广东省| 如皋市| 镇原县| 龙南县| 炉霍县| SHOW|