[deyu1@kvm19 ansible]$ cat roles.yml --- - name: install httpd hosts: webservers roles: - apache - name: use balancer hosts: balancers roles: - balancer
[deyu1@kvm19 ansible]$ ansible-playbook roles.yml TASK [Gathering Facts] ********************************************************* ok: [kvm13] ok: [kvm14] TASK [apache : install the latest version of Apache] *************************** ok: [kvm14] ok: [kvm13] TASK [apache : Start service httpd] ******************************************** ok: [kvm13] ok: [kvm14] TASK [apache : Enable service firewalld] *************************************** ok: [kvm13] ok: [kvm14] TASK [apache : firewalld add http service] ************************************* ok: [kvm14] ok: [kvm13] TASK [apache : Template a file] ************************************************ ok: [kvm13] ok: [kvm14] PLAY [use balancer] ************************************************************ TASK [Gathering Facts] ********************************************************* ok: [kvm15] TASK [balancer : Download and install haproxy] ********************************* changed: [kvm15] TASK [balancer : Configure the haproxy cnf file with hosts] ******************** changed: [kvm15] TASK [balancer : Start the haproxy service] ************************************ changed: [kvm15] RUNNING HANDLER [balancer : restart haproxy] *********************************** changed: [kvm15] PLAY RECAP ********************************************************************* kvm13 : ok=6 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 kvm14 : ok=6 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 kvm15 : ok=5 changed=4 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[deyu1@kvm19 ansible]$ curl http://kvm15/ curl: (7) Failed to connect to kvm15 port 80: No route to host
[deyu1@kvm19 ansible]$ ssh kvm15 [deyu1@kvm15 ~]$ curl http://kvm15/ Welcome to kvm13.deyu.wang on 192.168.122.13 [deyu1@kvm15 ~]$ curl http://kvm15/ Welcome to kvm14.deyu.wang on 192.168.122.14 [deyu1@kvm15 ~]$ exit logout Connection to kvm15 closed.