1、使用ansible的playbook实现自动化安装httpd
1、安装ansible
[root@C76 ~]# yum install ansible -y
2、配置ssh免密认证
[root@C76 ~]# ssh-keygen -t rsa
[root@C76 ~]# ssh-copy-id 192.168.44.131
3、添加管理主机
[root@C76 ~]# vim /etc/ansible/hosts
[webservers]
192.168.44.131
4创建必要的文件目录
[root@C76 ansible]# tree
.
├── hosts_list
├── httpd.yml
└── roles
└── httpd
└── tasks
└── main.yml
5、配置主机清单
[root@C76 ansible]# cat hosts_list
[httpd]
192.168.44.131
6、配置主配置文件
[root@C76 ansible]# cat httpd.yml
- hosts:
- httpd
roles:
- httpd
7、写main.yml部署文件
[root@C76 ansible]# vim /etc/ansible/roles/httpd/tasks/main.yml
- name: install httpd
yum:
name: httpd
state: present
- name: enable httpd.service
systemd:
name: httpd.service
enabled: true
state: started
- name: stop firewalld.service
systemd:
name: firewalld.service
enabled: false
state: stopped
- name: disable selinux
selinux:
state: disabled