一、概述
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
}