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类型,必填项

用法

[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": ,
"name": "test",
"state": "present",
"system": false
}

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

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

二、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为删除组。

用法,我们来删除一下刚才创建的组

[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类型,默认值为空

用法

[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": ,
"name": "test",
"state": "present",
"system": false
}

查看主机/etc/group文件

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

我们可以新创建的组gid为1005

四、system

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

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

用法

[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": ,
"name": "test",
"state": "present",
"system": true
}

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

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

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

运维自动化神器ansible之group模块的更多相关文章

  1. 运维自动化神器ansible之user模块

    运维自动化神器ansible之user模块 一.概述   user模块 可管理远程主机上的 用户,比如创建用户.修改用户.删除用户.为用户创建密钥对等操作. 二.参数介绍   name: 用于指定操作 ...

  2. Ansible运维自动化工具19个常用模块使用实例【转】

    一.模块列表 1.setup 2.ping 3.file 4.copy 5.command 6.shell 7.script 8.cron 9.yum 10.service 11.group 12.u ...

  3. 运维自动化之ansible的安装与使用 转

    运维自动化之ansible的安装与使用 随着服务器数量的增长,我们需要一个批量工具去提高工作效率,之前用的是puppet,ansible的简单,适用让我眼前一亮,决定写一篇ansible从安装到基本配 ...

  4. 运维自动化工具ansible

    企业级自动化运维工具应用实战ansible 公司计划在年底做一次大型市场促销活动,全面冲刺下交易额,为明年的上市做准备.公司要求各业务组对年底大促做准备,运维部要求所有业务容量进行三倍的扩容,并搭建出 ...

  5. 运维自动化之ansible的安装与使用(包括模块与playbook使用)(转发)

    原文  http://dl528888.blog.51cto.com/2382721/1435415 我使用过puppet(地址是http://dl528888.blog.51cto.com/2382 ...

  6. 运维自动化之ansible

    Ansible简介 Ansible是一个简单的自动化运维管理工具,基于Python语言实现,由Paramiko和PyYAML两个关键模块构建,可用于自动化部署应用.配置.编排task(持续交付.无宕机 ...

  7. 自动化运维工具之ansible

    自动化运维工具之ansible   一,ansible简介 ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fab ...

  8. Ansible 运维自动化 ( 配置管理工具 )

    背景 出差背景,要搞项目的自动化部署.因为只直接对接生产分发,机器又非常多,这样以往使用的bat只能作为应急方案了,还是得考虑使用专业化的工具来做这个事情! 当下有许多的运维自动化工具( 配置管理 ) ...

  9. 自动化运维工具之 Ansible 介绍及安装使用

    一.初识Ansible 介绍: Absible 使用 模块(Modules)来定义配置任务.模块可以用标准脚本语言(Python,Bash,Ruby,等等)编写,这是一个很好的做法,使每个模块幂等.A ...

随机推荐

  1. Mac环境IntelliJ IDEA配置JDK提示The selected directory is not a valid home for JDK

    笔者使用mac配置如下: 硬件环境:MacBook Pro 操作系统:MacOS Sierra 10.13.6 开发工具:IntelliJ IDEA 2016.x JDK版本:已有Open JDK 8 ...

  2. 数据库常用SQL语句(二):多表连接查询

    前面主要介绍了单表操作时的相关查询语句,接下来介绍一下多表之间的关系,这里主要是多表数据记录的查询,也就是如何在一个查询语句中显示多张表的数据,这也叫多表数据记录的连接查询. 在实现连接查询时,首先是 ...

  3. 你真的了解Grid布局吗?

    Grid网格布局 概述:Grid将容器划分为一个个网格,通过任意组合不同的网格,做出你想想要的布局 Grid与flex布局相似,将整个Grid分为了容器与子项(格子) Grid容器的三个重要的概念: ...

  4. 浅谈独立特征(independent features)、潜在特征(underlying features)提取、以及它们在网络安全中的应用

    1. 关于特征提取 0x1:什么是特征提取 特征提取研究的主要问题是,如何在数据集未明确表示结果的前提下,从中提取出重要的潜在特征来.和无监督聚类一样,特征提取算法的目的不是为了预测,而是要尝试对数据 ...

  5. FreeSql (十四)批量更新数据

    FreeSql支持丰富的更新数据方法,支持单条或批量更新,在特定的数据库执行还可以返回更新后的记录值. var connstr = "Data Source=127.0.0.1;Port=3 ...

  6. Java之BigDecimal详解

    一.BigDecimal概述 ​ Java在java.math包中提供的API类BigDecimal,用来对超过16位有效位的数进行精确的运算.双精度浮点型变量double可以处理16位有效数,但在实 ...

  7. Hive中的数据库(Database)和表(Table)

    在前面的文章中,介绍了可以把Hive当成一个"数据库",它也具备传统数据库的数据单元,数据库(Database/Schema)和表(Table). 本文介绍一下Hive中的数据库( ...

  8. 工厂/Builder,桥接/策略

    1.工厂 vs 抽象工厂 工厂方法模式: 用来加工.生产对象的类.比如说我想要一个汽车类,但是我总不能现场给你造个车出来对吧?于是我找到工厂类,然后工厂帮我把发动机型号选好,轮胎装好,油漆喷好,然后把 ...

  9. springboot jsp,过滤器,拦截器

    springboot使用jsp,过滤器,拦截器(拦截器与过滤器区别重点) jsp使用配置 一 创建springboot项目在maven中暂时只添加两个Dependencies :devtools(热部 ...

  10. 外部服务器使用jedis操作redis数据库

    使用maven获取jedis的包,我本来想去找jedis的jar包的,但是没找到. (maven)     <dependency> <groupId>redis.client ...