ansible模块应用
使用firewalld模块配置防火墙策略
---
- name:
hosts: all
tasks:
- name: 安装防火墙
yum:
name: firewalld
- name: 开启防火墙服务
service:
name: firewalld
state: started
enabled: yes
- name: 设置防火墙规则
firewalld:
zone: public # 设置zone
port: 80/tcp
permanent: yes # 永久生效
immediate: yes # 现在就生效
state: enabled # 启用策略
[c8 root ~]# firewall-cmd --list-ports --permanent
80/tcp
[c8 root ~]# firewall-cmd --list-ports
80/tcp
[c8 root ~]#
template模块
# 将变量写在文件中
welcome to {{ ansible_hostname }} on {{ ansible_ztuzex7lqa.ipv4.address }}
---
- name: template模块演示
hosts: all
tasks:
- name: 将index.html文件复制到节点,并将其中的变量替换为对应的值
template:
src: ~/play/template/index.html
dest: /var/www/html/index.html
[c8 root /var/www/html]# cat index.html
welcome to c8 on 10.147.17.65
[rhel7-gjb root /var/www/html]# cat index.html
welcome to rhel7-gjb on 10.147.17.40