本篇博客的内容在上一篇博客ansible搭建的基础上完成:自动化运维工具Ansible的搭建
一、Ansible的command默认模块的简单使用
1、在ansible1上执行
test指ansible中test组,-m后指定模块 -a后加这个模块的参数

注意:command模块为默认的模块,如果不-m指定的话,默认使用的command模块
二、copy模块
1、copy
查看
三、file模块
查看docker2某文件的权限
更改权限:
四、yum模块
查看yum模块的使用方法:
[[email protected] ansible]$ ansible-doc yum
注意:我们现在使用的是普通用户,没有执行yum命令的权力:
先配置devops用户的sudo权限:
[[email protected] ~]# vim /etc/sudoers
====================================
93 devops ALL=(ALL) NOPASSWD: ALL
+++++++++++++++++++++++++++++++++++++++++
[[email protected] ~]# vim /etc/sudoers
====================================
93 devops ALL=(ALL) NOPASSWD: ALL
- ansible2
ansible常用模块(command、copy、file、yum、service、firewalld) - ansible3 在docker2-3上,下载httpd服务
ansible常用模块(command、copy、file、yum、service、firewalld)
#一定要加入-b选项,否则会报错
[[email protected] ansible]$ ansible test -m yum -a 'name=httpd state=present' -b
查看是否下载成功:
不加-b可以在ansible的配置文件里面配置:
[[email protected] ansible]$ vim ansible.cfg
==========================================
[defaults]
inventory = inventory
[privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=False
- test组
- webservers组
卸载:
五、service模块
启动db组的httpd服务:
测试:
[[email protected] ansible]$ curl 172.25.70.3
这是ansible3的httpd服务的默认发布页,不太直观,我们写一个发布页:
六、firewalld模块
如何在开启防火墙的情况下,正常使用httpd服务呢?
首先开启防火墙
测试:
[[email protected] ansible]$ curl ansible3
把httpd服务加入防火墙白名单: