Ansible当中常用的模块

Ansible当中常用的模块

​ ansible 默认提供了很多模块来供我们使用。在 Linux 中,我们可以通过 ansible-doc -l 命令查看到当前 ansible 都支持哪些模块,通过 ansible-doc -s 模块名 又可以查看该模块有哪些参数可以使用。

1.ansible常用模块使用的详解

ansible日常的模块有一下几种:

  • ping
  • raw
  • 模板
  • 复制
  • shell
  • yum
  • 服务
  • group
  • 命令
  • 脚本

ansible常用模块raw、command、shell的区别“

  • 这三个模块都有共同点,都有在受管主机上执行很多命令”这里不包括全部可以执行的命令“

  • shell模块调用的/bin/sh指令执行

  • 命令模块不是调用的shell的指令,所以没有bash的环境变量

  • 原始的很多地方和shell 类似,更多的地方建议使用shell 和命令模块。但是使用旧版本python,如果需要原始版本,又或者是客户端是路由器,没有安装python 模块,则需要使用raw模块了

    Ansible user模块主要用于操作系统用户、组、权限、密码等操作

    system默认创建为普通用户,为yes则创建系统用户
    append添加一个新的组
    comment添加描述信息
    -createhome给用户创建家目录
    force强制删除用户
    group创建用户主组
    groups将用户加入组或者附属组添加
    home指定用户的家目录
    password指定用户的密码,为加密密码
    remove删除用户
    shell设置用户的shell登录环境
    uid设置用户ID
    update_password修改用户密码
    state用户状态,默认为present,表示新建用户
    name表示状态,是否create、remove、modify

    2.ansible常用模块【ping】命令

    ​ ping模块用于检查故障回复机器是否连通,常用很简单,不知道,主机是否在线,则pong

[root@centos8-1 ~]# ansible  all -m ping
192.168.100.147 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
[root@centos8-1 ~]# 

3.ansible常用模块之【命令】模块

​ 命令模块用于在远程主机上执行命令,ansible默认就是使用命令模块(command)

注:命令模块有一个缺陷就是不能使用管道符和执行功能

[root@centos8-1 ~]# ansible  all -a 'ls /tmp'   //在这里查看受管主机tmp下的东西
192.168.100.147 | CHANGED | rc=0 >>
ansible_command_payload_hm0a6ith
ks-script-3olmjuxx
systemd-private-588e679a634b40f6964e3a19aa2625ec-chronyd.service-bXq6Xo
vmware-root_918-2697532712
vmware-root_933-3988752732
vmware-root_934-2731086592
vmware-root_936-2697532681
vmware-root_937-4013854423
[root@centos8-1 ~]# 

[root@centos8-1 ~]# ansible  all -a 'touch /tmp/test'  //我们在受管主机tmp下面创建一个test,创建成功。
[WARNING]: Consider using the file module with state=touch rather than running 'touch'.  If you need to use command
because file is insufficient you can add 'warn: false' to this command task or set 'command_warnings=False' in
ansible.cfg to get rid of this message.
192.168.100.147 | CHANGED | rc=0 >>
[root@centos8-1 ~]# 

[root@centos8-1 ~]# ansible  all -a 'ls /tmp'   //我们载查看发现里面有我们创建的test文件
192.168.100.147 | CHANGED | rc=0 >>
ansible_command_payload_8d64zsar
ks-script-3olmjuxx
systemd-private-588e679a634b40f6964e3a19aa2625ec-chronyd.service-bXq6Xo
test
vmware-root_918-2697532712
vmware-root_933-3988752732
vmware-root_934-2731086592
vmware-root_936-2697532681
vmware-root_937-4013854423
[root@centos8-1 ~]# 

注:在这里演示一下command模块,注意它是不支持管道符和重定向的。

[root@centos8-1 ~]# ansible  all -a "echo 'hello world' > /tmp/test"
192.168.100.147 | CHANGED | rc=0 >>
hello world > /tmp/test
[root@centos8-1 ~]# 
[root@localhost tmp]# cat test    //上面虽然成功了,但是我们查看是没有的。
[root@localhost tmp]# 

[root@centos8-1 ~]# ansible  all -a 'ps -ef|grep vsftpd'   //这里我们用管道符直接报错。
192.168.100.147 | FAILED | rc=1 >>
error: unsupported SysV option

Usage:
 ps [options]

 Try 'ps --help <simple|list|output|threads|misc|all>'
  or 'ps --help <s|l|o|t|m|a>'
 for additional help text.

For more details see ps(1).non-zero return code
[root@centos8-1 ~]# 

4.ansible常用模块【raw】

​ raw模块用于在远程主机上执行命令,其支持管道符与生成(raw模块是支持管道符的。也支持重定向,这就是raw模块和command模块的区别所在)

[root@centos8-1 ~]# ansible  all -m raw -a "echo 'hello world' > /tmp/test"   //这里我们执行重定向成功
192.168.100.147 | CHANGED | rc=0 >>
Shared connection to 192.168.100.147 closed.
[root@centos8-1 ~]#

[root@centos8-1 ~]# ansible  all -m raw -a 'ps -ef|grep vsftpd'   //这里我们执行管道符也成功
192.168.100.147 | CHANGED | rc=0 >>
root       54668   54667  0 09:13 pts/2    00:00:00 bash -c ps -ef|grep vsftpd
root       54684   54668  0 09:13 pts/2    00:00:00 grep vsftpd
Shared connection to 192.168.100.147 closed.
[root@centos8-1 ~]# 

5,ansible常用模块【shell】

​ shell 模块用于在控制机上执行管理机上的脚本,自行在控制机上执行命令

注:在这里需要注意的是,它执行的不是受管主机上的脚本, 而是管理机上的脚本

[root@centos8-1 ~]# ansible all -m shell -a "echo '123' | passwd --stdin jyi"   //首先我们受管主机上是由jyi这个用户的。
192.168.100.147 | CHANGED | rc=0 >>
更改用户 jyi 的密码 。
passwd:所有的身份验证令牌已经成功更新。
[root@centos8-1 ~]# 

6.ansible常用模块指脚本【script】

​ 脚本模块用于在控制机上执行主控机上的脚本

注:这里是执行控制机上的脚本,在受管主机上运行。

[root@centos8-1 ~]# ll /etc/ansible/scripts/   //首先我们自己写一个脚本
总用量 4
-rw-r--r-- 1 root root 55 7月  17 09:52 shen.sh
[root@centos8-1 ~]#  ansible all -m script -a '/etc/ansible/scripts/shen.sh &>/tmp/test'    //然后执行脚本
192.168.100.147 | CHANGED => {
    "changed": true,
    "rc": 0,
    "stderr": "Shared connection to 192.168.100.147 closed.\r\n",
    "stderr_lines": [
        "Shared connection to 192.168.100.147 closed."
    ],
    "stdout": "",
    "stdout_lines": []
}
[root@centos8-1 ~]# 

[root@localhost ~]# ll   //这边查看发现创建成功
总用量 4
-rw-r--r--  1 root root    0 7月  17 09:57 aaa
-rw-------. 1 root root 1087 7月  13 02:34 anaconda-ks.cfg
-rw-r--r--  1 root root    0 7月  17 09:57 jjj
drwxr-xr-x  2 root root   21 7月  17 09:44 scripts
-rw-r--r--  1 root root    0 7月  17 09:57 shen
drwxr-xr-x  2 root root    6 7月  15 06:00 shunzichishi
-rw-r--r--  1 root root    0 7月  17 09:49 testdir
-rw-r--r--  1 root root    0 7月  17 09:57 yyy
[root@localhost ~]# 

7.ansible常用模块之模板【template】

​ 模板模块用于生成一个模板,将其传输到远程主机上。

[root@centos8-1 ~]# cd /etc/yum.repos.d/     //查看本地源是没有163.repo的。
[root@centos8-1 yum.repos.d]# ls
CentOS-Stream-AppStream.repo         CentOS-Stream-Media.repo       epel-next-testing.repo
CentOS-Stream-BaseOS.repo            CentOS-Stream-PowerTools.repo  epel-playground.repo
CentOS-Stream-Debuginfo.repo         CentOS-Stream-RealTime.repo    epel.repo
CentOS-Stream-Extras.repo            epel-modular.repo              epel-testing-modular.repo
CentOS-Stream-HighAvailability.repo  epel-next.repo                 epel-testing.repo
[root@centos8-1 yum.repos.d]# curl -o CentOS7-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo    //下载163.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1572  100  1572    0     0  11309      0 --:--:-- --:--:-- --:--:-- 11309
[root@centos8-1 yum.repos.d]# cd
[root@centos8-1 ~]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@centos8-1 ~]# sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@centos8-1 ~]# ansible all -m template -a 'src=/etc/yum.repos.d/CentOS7-Base-163.repo dest=/etc/yum.repos.d/163.repo'    //执行命令
192.168.100.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "checksum": "60b8868e0599489038710c45025fc11cbccf35f2",
    "dest": "/etc/yum.repos.d/163.repo",
    "gid": 0,
    "group": "root",
    "md5sum": "5a3e688854d9ceccf327b953dab55b21",
    "mode": "0644",
    "owner": "root",
    "size": 1462,
    "src": "/root/.ansible/tmp/ansible-tmp-1626530546.7166886-152498-195821358369608/source",
    "state": "file",
    "uid": 0
}
[root@centos8-1 ~]# 
[root@localhost yum.repos.d]# ls     //然后我们到受管主机上查看发现有163.repo
163.repo                      CentOS-Stream-Debuginfo.repo         CentOS-Stream-Media.repo
CentOS-Stream-AppStream.repo  CentOS-Stream-Extras.repo            CentOS-Stream-PowerTools.repo
CentOS-Stream-BaseOS.repo     CentOS-Stream-HighAvailability.repo  CentOS-Stream-RealTime.repo
[root@localhost yum.repos.d]# 

8.ansible常用模块之yum

​ yum 模块用于在指定节点机器上通过 yum 管理软件,其支持的参数主要有两个

  • name:要管理的包名
  • state:要进行的操作

状态常用的值:

  • 最新:安装软件
  • 安装:安装软件
  • 当前:安装软件
  • 移除:卸软件
  • 缺席:卸软件

name参数:必须参数,用于指定需要管理的软件包,比如 nginx。

state参数:用于指定软件包的状态 ,默认值为。present,表示确保软件包已经安装,除了。present,其他可用值有 installed、latest、absent、removed,其中 installed 与present 等效,latest 表示安装 yum 中最新的版本,absent 和 removed 等效,表示删除对应的软件包。

disable_gpg_check参数:用于禁用对 rpm 包的公钥 gpg 验证。默认值为 no,表示不禁用验证,设置为 yes 表示禁用验证,即不验证包,直接安装。在对应的 yum 源没有开启 gpg 验证的情况下,需要将此参数的值设置为 yes,否则会报错而无法进行安装。

enablerepo参数:用于指定安装软件包时临时启用的 yum 源。假如你想要从A源中安装软件,但是你不确定A源是否启用了,你可以在安装软件包时将此参数的值设置为 yes,即使A源的设置是未启用,也可以在安装软件包时临时启用A源。

disablerepo参数:用于指定安装软件包时临时禁用的 yum 源。某些场景下需要此参数,比如,当多个 yum 源中同时存在要安装的软件包时,你可以使用此参数临时禁用某个源,这样设置后,在安装软件包时则不会从对应的源中选择安装包。

enablerepo 参数和 disablerepo 参数可以同时使用。

如果想使用 yum 来管理软件,请确保执行机器上的 yum 源无异常。

//我们在受管主机上先查看一下是否按钻过了vsftpd。
[root@localhost ~]# rpm -qa | grep vsftpd     //受管主机上没有vsftpd
[root@localhost ~]# 
//然后我们执行yum模块给受管主机安装vsftpd
[root@centos8-1 ~]# ansible all -m yum -a "name=vsftpd state=present"
192.168.100.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "msg": "",
    "rc": 0,
    "results": [
        "Installed: vsftpd-3.0.3-34.el8.x86_64"
    ]
}
[root@centos8-1 ~]# 
//然后我们再在受管主机上查看一下vsftpd
[root@localhost ~]# rpm -qa | grep vsftpd
vsftpd-3.0.3-34.el8.x86_64
[root@localhost ~]# 

9.ansible常用模块【copy】

​ 复制模块用于复制文件至远程控制机,copy 模块的作用就是拷贝文件,copy 模块是将 ansible 管理主机上的文件拷贝到受管主机中。

[root@centos8-1 ~]# ls /etc/ansible/scripts/    //查看管理主机的文件
shen.sh
[root@centos8-1 ~]# ansible all -m copy -a "src=/etc/ansible/scripts/shen.sh dest=/opt/scripts/"    //执行copy命令
192.168.100.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "checksum": "b89bcd481aa3f32fc6618662278cc97ae81bca60",
    "dest": "/scripts/shen.sh",
    "gid": 0,
    "group": "root",
    "md5sum": "e7e03ce0725f1422211d5473000a1559",
    "mode": "0644",
    "owner": "root",
    "size": 55,
    "src": "/root/.ansible/tmp/ansible-tmp-1626531678.6432827-187211-59080505311434/source",
    "state": "file",
    "uid": 0
}
[root@centos8-1 ~]# 
[root@localhost opt]# ls     //然后我们在受管主机上查看,里面是有这个文件的
scripts  sss  vaf
[root@localhost opt]# cd scripts/
[root@localhost scripts]# ls
shen.sh
[root@localhost scripts]# 

10.ansible常用模块之组【group】

群组模块用于在监控机上添加或删除组。

– gid 设置组id

– name 需要管理组的名称

– state 执行状态,absent删除,present创建(默认)

[root@centos8-1 ~]# ansible all -m group -a "name=shen gid=1234 state=present"    //在受管主机创建组
192.168.100.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "gid": 1234,
    "name": "shen",
    "state": "present",
    "system": false
}
[root@centos8-1 ~]# 
[root@centos8-1 ~]# ansible all -m group -a "name=shen gid=1234   state=absent"     //删除受管主机刚刚创建的组
192.168.100.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "name": "shen",
    "state": "absent"
}
[root@centos8-1 ~]# 

11.ansible常用模块之用户【user】

用户模块用于管理管理机的用户账号

– name - 用户名

– uid - uid

– group - gid或者groupname

– state - 执行状态,absent删除、present创建(默认)

– shell - 登录shell,/bin/bash(默认),/sbin/nologin/

– create_home 创建用户时,是否创建家目录 create_home=no

– password -用户密码,不能使用明文,需要使用openssl加密后的密码,需要使用双引号

[root@centos8-1 ~]# ansible all -m user -a 'name=mysql uid=306 system=yes create_home=no shell=/sbin/nologin state=present'     在受控机上添加一个系统用户,用户名为mysql,uid为306,设置其shell为/sbin/nologin,无家目录
192.168.100.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "comment": "",
    "create_home": false,
    "group": 306,
    "home": "/home/mysql",
    "name": "mysql",
    "shell": "/sbin/nologin",
    "state": "present",
    "system": true,
    "uid": 306
}
[root@centos8-1 ~]# 
[root@centos8-1 ~]# ansible 192.168.100.147 -m shell -a 'grep mysql /etc/passwd'    //查看受管主机刚刚创建的用户
192.168.100.147 | CHANGED | rc=0 >>
mysql:x:306:306::/home/mysql:/sbin/nologin
[root@centos8-1 ~]# 

修改mysql用户的uid为9999

[root@centos8-1 ~]# ansible all -m user -a 'name=mysql uid=9999'   执行修改命令 
192.168.100.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "append": false,
    "changed": true,
    "comment": "",
    "group": 306,
    "home": "/home/mysql",
    "move_home": false,
    "name": "mysql",
    "shell": "/sbin/nologin",
    "state": "present",
    "uid": 366
}
[root@centos8-1 ~]# 
[root@localhost ~]# id mysql      //查看发现uidi已经改成9999
uid=9999(mysql) gid=306(mysql) 组=306(mysql)
[root@localhost ~]# 

删除刚刚在受管主机上创建的mysql用户

[root@centos8-1 ~]# ansible all -m user -a "name=mysql state=absent"
192.168.100.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "force": false,
    "name": "mysql",
    "remove": false,
    "state": "absent"
}
[root@centos8-1 ~]# 
[root@localhost ~]# id mysql     //已经删除了mysql用户
id: “mysql”:无此用户
[root@localhost ~]# 

12.ansible常用模块之服务【service】

服务模块用于管理监管机上的服务。

​ service 模块可以帮助我们管理远程主机上的服务。比如,启动或停止远程主机中的 nginx 服务。

​ name参数:此参数用于指定需要操作的服务名称,比如 nginx。
​ state参数:此参数用于指定服务的状态,比如,我们想要启动远程主机中的 nginx,则可以将 state 的值设置为 started;如果想要停止远程主机中的服务,则可以将 state 的值设置为 stopped。此参数的可用值有 started、stopped、restarted、reloaded。
​ enabled参数:此参数用于指定是否将服务设置为开机 启动项,设置为 yes 表示将对应服务设置为开机启动,设置为 no 表示不会开机启动。

注:受管主机已经按章vsftpd服务,我们用命令启动vsftpd服务

[root@centos8-1 ~]# ansible all -m service -a 'name=vsftpd state=started'
192.168.100.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "name": "vsftpd",
    "state": "started",
    "status": {
        "ActiveState": "inactive",
        "AllowedCPUs": "",       
        "AllowedMemoryNodes": "",   //后面内容很多,这里省略
[root@centos8-1 ~]# ansible all -m shell -a 'systemctl is-active vsftpd'     //查看受管主机已经启动vsftpd服务
192.168.100.147 | CHANGED | rc=0 >>
active
[root@centos8-1 ~]# 
[root@centos8-1 ~]# ansible all -m service -a 'name=vsftpd enabled=yes'   //设置vsftpd开机自启动
192.168.100.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "enabled": true,
    "name": "vsftpd",
    "status": {
        "ActiveState": "active",    //此处内容省略。。。。。。
[root@centos8-1 ~]# ansible all -m service -a 'name=vsftpd state=stopped'  //停止vsftpd服务
192.168.100.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": true,
    "name": "vsftpd",
    "state": "stopped",
    "status": {
        "ActiveState": "active",   //此处内容省略。。。。。。
 [root@centos8-1 ~]# ansible all -m shell -a 'systemctl is-active vsftpd'  //查看已经停止服务
192.168.100.147 | FAILED | rc=3 >>
inactivenon-zero return code
[root@centos8-1 ~]#        

13.ansible常用命令之【lineinfle】

​ 我们可以借助 lineinfile 模块,确保”某一行文本”存在于指定的文件中,或者确保从文件中删除指定的”文本”(即确保指定的文本不存在于文件中),还可以根据正则表达式,替换”某一行文本”。

path参数 :必须参数,指定要操作的文件。

line参数 : 使用此参数指定文本内容。

regexp参数 :使用正则表达式匹配对应的行,当替换文本时,如果有多行文本都能被匹配,则只有最后面被匹配到的那行文本才会被替换,当删除文本时,如果有多行文本都能被匹配,这么这些行都会被删除。

state参数:当想要删除对应的文本时,需要将state参数的值设置为absent,absent为缺席之意,表示删除,state的默认值为present。

backup参数:是否在修改文件之前对文件进行备份。

create参数 :当要操作的文件并不存在时,是否创建对应的文件。

//首先在受管主机上创建一下文件,并且写入内容
[root@localhost opt]# cat test 
111
aef
gsgs
hsgser
bxgxb
[root@localhost opt]# 
[root@centos8-1 ~]# ansible all -m lineinfile -a 'path=/opt/test line="@@test@@"'    //然后执行命令,将参数插入到末尾
192.168.100.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "msg": "line added"
}
[root@centos8-1 ~]# 
[root@centos8-1 ~]# ansible all -m shell -a "cat /opt/test"   //查看发现加入成功
192.168.100.147 | CHANGED | rc=0 >>
111
aef
gsgs
hsgser
bxgxb
@@test@@
[root@centos8-1 ~]# 

删除

[root@centos8-1 ~]# ansible all -m lineinfile -a 'path=/opt/test line="@@test@@" state=absent'    //删除刚刚加入的参数
192.168.100.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "found": 1,
    "msg": "1 line(s) removed"
}
[root@centos8-1 ~]# 
[root@centos8-1 ~]# ansible all -m shell -a "cat /opt/test"    //查看发现删除成功
192.168.100.147 | CHANGED | rc=0 >>
111
aef
gsgs
hsgser
bxgxb
[root@centos8-1 ~]# 

使用regexp参数替换文本时,当有多行文本都能被匹配,只有最后被匹配到的行才会被替换:

[root@centos8-1 ~]# ansible all -m lineinfile -a 'path=/opt/test regexp="aef" line="##test##"'    //执行命令替换
192.168.100.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "msg": "line replaced"
}
[root@centos8-1 ~]# 
[root@centos8-1 ~]# ansible all -m shell -a "cat /opt/test"    //替换成功
192.168.100.147 | CHANGED | rc=0 >>
111
##test##
gsgs
hsgser
bxgxb
[root@centos8-1 ~]# 

使用regexp参数删除文本时,当有多行文本都能被匹配,这些行都会被删除:

[root@centos8-1 ~]# ansible all -m lineinfile -a 'path=/opt/test regexp="##test##" state=absent'     //执行删除
192.168.100.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "found": 1,
    "msg": "1 line(s) removed"
}
[root@centos8-1 ~]#   
[root@centos8-1 ~]# ansible all -m shell -a "cat /opt/test"    //查看删除成功
192.168.100.147 | CHANGED | rc=0 >>
111
gsgs
hsgser
bxgxb
[root@centos8-1 ~]# 

使用insertafter插入文本到指定行后

[root@centos8-1 ~]# ansible all -m lineinfile -a 'path=/opt/test insertafter="gsgs" line="insert test"'    //执行成功
192.168.100.147 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "backup": "",
    "changed": true,
    "msg": "line added"
}
[root@centos8-1 ~]# 
[root@centos8-1 ~]# ansible all -m shell -a "cat /opt/test"     //查看加入成功
192.168.100.147 | CHANGED | rc=0 >>
111
gsgs
insert test
hsgser
bxgxb
[root@centos8-1 ~]# 

14.ansible常用模块之管理防火墙【firewalld】

firewalld模块用来添加、删除防火墙规则。

[root@centos8-1 ~]# ansible all -m service -a 'name=firewalld state=started enabled=true'
192.168.100.147 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "enabled": true,
    "name": "firewalld",   //此处省略。。。。。。
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Lfei5120

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值