用playbook编写httpd的安装配置启动服务
1.准备受控主机和控制主机各一台,都是8.0版本
2.关闭防火墙
- 在playbook里,配置yum仓库,下载网络源,安装httpd,启动服务
[root@ansible playbook]# ls
1.yml httpd.yml myplay.yml
[root@ansible playbook]# vi httpd.yml
---
- name: 下载repo
hosts: 192.168.152.131
tasks:
- name: repo位置
template: src=/files/yum/CentOS-Base.repo dest=/etc/yum.repos.d/
- name: 安装httpd
dnf: name=httpd state=present
- name: 启动httpd服务
service: name=httpd state=restarted enabled=yes
- 运行playbook
[root@ansible playbook]# ansible-playbook httpd.yml
PLAY [下载repo] ******************************************************************
TASK [Gathering Facts] *********************************************************
ok: [192.168.152.131]
TASK [repo位置] ****************************************************************