Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Group module of operation and maintenance automation artifact ansible

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Group module of ansible

The group module is used to add or remove groups

First use ansible-doc to see the usage

[root@note0 ansible] # ansible-doc-s group- name: Add or remove groups group: gid: # Optional `GID' to set for the group. Local: # Forces the use of "local" command alternatives on platforms that implement it. This is useful in environments that use centralized authentication when you want to manipulate the local groups. (e.g. It uses `lgroupadd' instead of `groupadd'). This requires that these commands exist on the targeted host, otherwise it will be a fatal error. Name: # (required) Name of the group to manage. Non_unique: # This option allows to change the group ID to a non-unique value. Requires `gid'. Not supported on macOS or BusyBox distributions. State: # Whether the group should be present or not on the remote host. System: # If `yes', indicates that the group created is a system group.

From the above parameter list, we can see that the group module has several important properties.

OPTIONS (= is mandatory): the parameter preceded by = is required.

1. Name= name Name of the group to manage. Type: group name of the group to be operated by str, string type, required entry 1.1, example

Create a group named test.

[root@note0 ~] # ansible local-m group-a "name=test" 176.16.128.1 | CHANGED = > {"ansible_facts": {"discovered_interpreter_python": "/ usr/bin/python"}, "changed": true,# can see that the changed status is true, indicating that the group has been successfully added to the host. "gid": 1000, "name": "test", "state": "present", "system": false}

View host / etc/group file verification

[root@note1] # cat / etc/grouptest:x:1000: II. State- state Whether the group should be present or not on the remote host. (Choices: absent, present) [Default: present] type: strstate is used to specify whether the user group is changed or deleted on the remote host, the string type. There are two options: absent,present. The default value is present,absent to delete the group. 2.1, example

Let's delete the group we just created.

[root@note0 ~] # ansible local-m group-a "name=test state=absent" 176.16.128.1 | CHANGED = > {"ansible_facts": {"discovered_interpreter_python": "/ usr/bin/python"}, "changed": true, "name": "test", "state": "absent"} III, gid- gid Optional `GID' to set for the group. [Default: (null)] type: intgid is used to set the gid,int type of user group. The default value is empty 3.1and example

Create a group with a gid of 1005 and the name test.

[root@note0 ~] # ansible local-m group-a "name=test gid=1005 state=present" 176.16.128.1 | CHANGED = > {"ansible_facts": {"discovered_interpreter_python": "/ usr/bin/python"}, "changed": true, "gid": 1005, "name": "test", "state": "present", "system": false}

Looking at the host / etc/group file, we can see that the newly created group gid is 1005.

[root@note1 ~] # cat / etc/grouptest:x:1005: IV. System- system If `yes', indicates that the group created is a system group. [Default: False] type: boolsystem is used to specify whether the created user group is a system group, Boolean type, and the available option false,true. Default is false4.1, example

Create a system group named test.

[root@note0 ~] # ansible local-m group-a "name=test state=present system=true" 176.16.128.1 | CHANGED = > {"ansible_facts": {"discovered_interpreter_python": "/ usr/bin/python"}, "changed": true, "gid": 994, "name": "test", "state": "present", "system": true}

View host / etc/group file verification

[root@note1 ~] # cat / etc/grouptest:x:994:

You can see that the gid of the test group is 994 and the gid is less than 1000 as the system group.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report