运维自动化神器ansible之group模块
发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,ansible之group模块group模块是用来添加或者删除组首先使用ansible-doc来查看用法[root@note0 ansible]# ansible-doc -s group- name
千家信息网最后更新 2026年11月02日运维自动化神器ansible之group模块
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/grouptest:x:1000:二、state
- state Whether the group should be present or not on the remote host. (Choices: absent, present)[Default: present] type: strstate用于指定用户组在远程主机上是否被更改或删除,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: intgid用于设定用户组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/grouptest:x:1005:四、system
- system If `yes', indicates that the group created is a system group. [Default: False] type: boolsystem用于指定创建的用户组是否为系统组,布尔类型,可用选项false,true,默认为false4.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/grouptest:x:994:可以看到test组的gid为994,gid小于1000为系统组。
主机
示例
类型
模块
名字
文件
用户
用户组
系统
参数
验证
重要
两个
代表
属性
布尔
状态
面的
e.g.
神器
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
华服互联网科技怎么样
互联网金融监管科技数据
与互联网科技公司
互联网医疗科技
互联网的科技创新
中国 科技 互联网
美国互联网科技
广州宏创互联网科技
沃里互联网科技
互联网科技论坛
剑昆互联网络科技有限公司临桂
团飞科技与伯堂互联网服务平台
贵州叶脉互联网科技有限公司所属行业
福建科技产业互联网发展
赶超互联网科技 微信多开
南通创西澳互联网科技有限公司
富国互联网金融科技混合基金
广州有谷有贝互联网科技有限公司
广州燕处互联网科技有限公司
科技互联网专业务虚会材料
联恩商钥互联网科技有限公司
海南科技产业互联网平台
湖南洣水互联网科技有限公司扣款
东莞新华互联网科技学校
高科技互联网发展前景如何
高科技互联网套路
工业互联网科技创业
九思连强互联网电子科技有限公司
宁波跨境商互联网科技有限公司
互联网对科技影响