Get the App
SLTechnology News&Howtos  ›  Servers  › 

Group module of operation and maintenance automation artifact ansible

Shulou Source: shulou.com Published: 2022-06-02 10:44:09 10月04日 Update

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.

Tags: Host example type module name file user user group system parameter authentication important two representative attribute Boolean status faceted e.g. artifact Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Microsoft Linux MariaDB Shulou Tech Info