Created
April 1, 2021 20:33
-
-
Save jyotisp/fdd0ce517c3bb267f05cede1558e80b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: webserver | |
tasks: | |
- name: "Installing httpd" | |
package: | |
name: "httpd" | |
state: present | |
- name: "Installing php" | |
package: | |
name: "php" | |
state: present | |
- name: "copying the file" | |
copy: | |
src: "/root/index.php" | |
dest: "/var/www/html/" | |
- name: "Handling the firewall" | |
firewalld: | |
state: enabled | |
port: 80/tcp | |
permanent: yes | |
- name: "Starting the service" | |
service: | |
name: "httpd" | |
state: started | |
- hosts: loadbalancer | |
tasks: | |
- name: "Installing the haproxy" | |
package: | |
name: "haproxy" | |
state: present | |
- name: "updating the haproxy.cfg file" | |
blockinfile: | |
path: /etc/haproxy/haproxy.cfg | |
block: | | |
{% for i in groups['webserver'] %} | |
server app{{ loop.index }} {{ i }}:80 check | |
{% endfor %} | |
notify: "restart the service" | |
- lineinfile: | |
path: /etc/haproxy/haproxy.cfg | |
regexp: "bind *:5000" | |
# insertafter: "frontend main" | |
line: "bind *:8080" | |
notify: "restart the service" | |
- firewalld: | |
state: enabled | |
port: 8080/tcp | |
permanent: yes | |
- service: | |
name: "haproxy" | |
state: started | |
handlers: | |
- name: "restart the service" | |
service: | |
name: "haproxy" | |
state: restarted | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment