Linux高级运维-playbook-httpd
1.查看控制机和受控机是否ping通
[root@afei ~]# ansible all -m ping
192.168.240.134 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}
2.查看受控主机有没有yum网络源
[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Base.repo redhat.repo
3.在控制机上用playbook编写安装httpd
[root@afei ~]# cd /playbook/
[root@afei playbook]# vim myplay.yml
---
- hosts: 192.168.240.134
vars:
package_name: httpd
tasks:
- name: feige
yum:
name: '{{ package_name }}'
state: present
- name: start feige
service:
name: httpd
state: restarted
enabled: yes
~
4.用ansible-playbook安装并启动服务
[root@afei playbook]# ansible-playbook myplay.yml
PLAY [192.168.240.134] *********************************************************
TASK [Gathering Facts] *********************************************************
ok: [192.168.240.134]
TASK [feige] *******************************************************************
ok: [192.168.240.134]
TASK [start feige] *************************************************************
changed: [192.168.240.134]
PLAY RECAP *********************************************************************
192.168.240.134 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
5.检查受控主机httpd是否安装成功
[root@localhost ~]# rpm -qa|grep httpd
httpd-2.4.37-21.module_el8.2.0+382+15b0afa8.x86_64
httpd-filesystem-2.4.37-21.module_el8.2.0+382+15b0afa8.noarch
centos-logos-httpd-80.5-2.el8.noarch
httpd-tools-2.4.37-21.module_el8.2.0+382+15b0afa8.x86_64
6.查看192.168.240.134的页面