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

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
主站蜘蛛池模板: 平湖市| 和顺县| 柳林县| 兴业县| 望奎县| 高雄县| 安泽县| 永寿县| 神木县| 襄城县| 六枝特区| 阳信县| 多伦县| 沿河| 雅安市| 剑阁县| 淳安县| 藁城市| 龙山县| 龙南县| 宜兰县| 德化县| 富阳市| 晋宁县| 望都县| 广灵县| 喀什市| 扶风县| 山西省| 巴马| 闻喜县| 吴忠市| 司法| 德庆县| 九龙坡区| 泗阳县| 宁阳县| 徐州市| 瑞昌市| 漳州市| 新昌县|