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

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
主站蜘蛛池模板: 温泉县| 白银市| 宿松县| 晋中市| 吉水县| 永平县| 阿尔山市| 精河县| 开鲁县| 县级市| 抚远县| 太仆寺旗| 揭阳市| 藁城市| 蓬莱市| 天峨县| 尼木县| 根河市| 铜山县| 石狮市| 文登市| 滕州市| 鄂州市| 西平县| 天全县| 三门峡市| 依安县| 太仆寺旗| 沙湾县| 平舆县| 平乡县| 屯昌县| 孝义市| 温宿县| 政和县| 平谷区| 岚皋县| 象州县| 东乡族自治县| 孙吴县| 五华县|