18-Ansible常用模块-group模块

一、概述

group 模块可以帮助我们管理远程主机上的组。

二、常用参数

  • name参数: 必须参数,用于指定要操作的组名称。
  • state参数: 用于指定组的状态,两个值可选,present,absent,默认为 present,设置为absent 表示删除组。
  • gid参数: 用于指定组的gid。

三、示例

1.确保all主机中存在名为 testgroup 的组。

[root@Ansible ~]# ansible all -m group -a 'name=testgroup'             
192.168.0.161 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "gid": 1002,
    "name": "testgroup",
    "state": "present",
    "system": false
}

2.删除all主机中存在名为 testgroup2 的组,删除成功的前提是不能有用户把被删除的组当成主组。

[root@Ansible ~]# ansible all -m group -a 'name=testgroup2 state=absent'
192.168.0.161 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "name": "testgroup2",
    "state": "absent"
}

3.确保all主机中存在名为 testgroup 的组,并且确定 testgroup 组的id为1008。

[root@Ansible ~]# ansible all -m group -a 'name=testgroup gid=1100' 
192.168.0.161 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "gid": 1100,
    "name": "testgroup",
    "state": "present",
    "system": false
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值