运维自动化神器ansible之group模块
admin
2023-03-01 04:41:26
0

ansible之group模块

group模块是用来添加或者删除组

首先使用ansible-doc来查看用法

[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.

通过上面的参数列表我们可以了解到group模块有几个重要属性

OPTIONS (= is mandatory):选项前面为=的为必填参数

一、name

= name
        Name of the group to manage.
        type: str

要操作的group的组名,string类型,必填项

1.1、示例

创建一个名字为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,#可以看到changed状态为true,代表已经在主机添加组成功。
    "gid": 1000, 
    "name": "test", 
    "state": "present", 
    "system": false
}

查看主机/etc/group文件验证

[root@note1 ~]# cat /etc/group
test:x:1000:

二、state

- state
        Whether the group should be present or not on the remote host.
        (Choices: absent, present)[Default: present]
        type: str

state用于指定用户组在远程主机上是否被更改或删除,string类型。
有两个选项:absent,present。默认值为present,absent为删除组。

2.1、示例

我们来删除一下刚才创建的组。

[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"
}

三、gid

- gid
        Optional `GID' to set for the group.
        [Default: (null)]
        type: int

gid用于设定用户组gid,int类型,默认值为空

3.1、示例

创建一个gid为1005,名字为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
}

查看主机/etc/group文件,我们可以看到新创建的组gid为1005。

[root@note1 ~]# cat /etc/group
test:x:1005:

四、system

- system
        If `yes', indicates that the group created is a system group.
        [Default: False]
        type: bool

system用于指定创建的用户组是否为系统组,布尔类型,可用选项false,true,默认为false

4.1、示例

创建一个名字为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
}

查看主机/etc/group文件验证

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

可以看到test组的gid为994,gid小于1000为系统组。

相关内容

热门资讯

【第一财经】“喜扣打筒子.有没... 网上科普关于“喜扣打筒子有没有挂”话题很是火热,小编也是针对喜扣打筒子作*弊开挂的方法以及开挂对应的...
【第一消息】“全民如意麻将.辅... 【第一消息】“全民如意麻将.辅助器?”详细开挂教程您好,全民如意麻将这个游戏其实有挂的,确实是有挂的...
终于明白“樱花牛牛.辅助器?”... 家人们!今天小编来为大家解答樱花牛牛透视挂怎么安装这个问题咨询软件客服徽9784099的挂在哪里买很...
我来教教您“闲来贵州麻将.辅助... 有 亲,根据资深记者爆料闲来贵州麻将是可以开挂的,确实有挂(咨询软件无需...
今日重大消息“皇豪众娱牛牛.可... 网上科普关于“皇豪众娱牛牛有没有挂”话题很是火热,小编也是针对皇豪众娱牛牛作*弊开挂的方法以及开挂对...
今日重大通报“乐友棋牌.有没有... 家人们!今天小编来为大家解答乐友棋牌透视挂怎么安装这个问题咨询软件客服徽4282891的挂在哪里买很...
今日重大发现“大富豪app.真... 有 亲,根据资深记者爆料大富豪app是可以开挂的,确实有挂(咨询软件无需...
【第一资讯】“葫芦三娃.到底有... 您好:葫芦三娃这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9784099】很多玩家在这款游戏...
终于明白“新圣游炸金花.是不是... 家人们!今天小编来为大家解答新圣游炸金花透视挂怎么安装这个问题咨询软件客服徽4282891的挂在哪里...
今日重大消息“新起点.到底有挂... 网上科普关于“新起点有没有挂”话题很是火热,小编也是针对新起点作*弊开挂的方法以及开挂对应的知识点,...