Petit stack

This commit is contained in:
2026-05-12 18:38:47 +02:00
parent 52e636b8e5
commit 8f477950d8
9 changed files with 79 additions and 50 deletions

View File

@@ -0,0 +1,11 @@
[control]
192.168.11.10
[database]
192.168.11.20
[loadbalancer]
192.168.11.30
[webserver]
192.168.11.40

View File

@@ -4,8 +4,8 @@
tasks:
- name: install tools
apt: name={{item}} state=present update_cache=yes
with_items:
- python-httplib2
loop:
- python3-httplib2
- name: install nginx
apt: name=nginx state=present update_cache=yes

View File

@@ -1,5 +1,11 @@
---
- hosts: all
tasks:
- name: get server hostname
- name: Ping to servers
ping:
- name: Get hostname
command: hostname
register: hostname
- name: Show hostname with message
debug:
msg: "The hostname of this server is {{ hostname.stdout }}"

View File

@@ -30,38 +30,38 @@
tasks:
- name: verify end-to-end index response
uri: url=http://{{item}} return_content=yes
with_items: groups.loadbalancer
loop: groups.loadbalancer
register: lb_index
- fail: msg="index failed to return content"
when: "'Hello, from sunny' not in item.content"
with_items: "{{lb_index.results}}"
loop: "{{lb_index.results}}"
- name: verify end-to-end db response
uri: url=http://{{item}}/db return_content=yes
with_items: groups.loadbalancer
loop: groups.loadbalancer
register: lb_db
- fail: msg="db failed to return content"
when: "'Database Connected from' not in item.content"
with_items: "{{lb_db.results}}"
loop: "{{lb_db.results}}"
- hosts: loadbalancer
tasks:
- name: verify backend index response
uri: url=http://{{item}} return_content=yes
with_items: groups.webserver
loop: groups.webserver
register: app_index
- fail: msg="index failed to return content"
when: "'Hello, from sunny {{item.item}}!' not in item.content"
with_items: "{{app_index.results}}"
loop: "{{app_index.results}}"
- name: verify backend db response
uri: url=http://{{item}}/db return_content=yes
with_items: groups.webserver
loop: groups.webserver
register: app_db
- fail: msg="db failed to return content"
when: "'Database Connected from {{item.item}}!' not in item.content"
with_items: "{{app_db.results}}"
loop: "{{app_db.results}}"

View File

@@ -1,2 +1,4 @@
---
# handlers file for apache2
- name: restart apache2
service: name=apache2 state=restarted

View File

@@ -1,2 +1,37 @@
---
# tasks file for apache2
- name: install web components
apt: name={{item}} state=present update_cache=yes
loop:
- apache2
- libapache2-mod-wsgi
- python3-pip
- python3-virtualenv
- python3-mysqldb
- name: ensure apache2 started
service: name=apache2 state=started enabled=yes
- name: ensure mod_wsgi enabled
apache2_module: state=present name=wsgi
notify: restart apache2
- name: copy demo app source
copy: src=demo/app/ dest=/var/www/demo mode=0755
notify: restart apache2
- name: copy apache virtual host config
copy: src=demo/demo.conf dest=/etc/apache2/sites-available mode=0755
notify: restart apache2
- name: setup python virtualenv
pip: requirements=/var/www/demo/requirements.txt virtualenv=/var/www/demo/.venv
notify: restart apache2
- name: de-activate default apache site
file: path=/etc/apache2/sites-enabled/000-default.conf state=absent
notify: restart apache2
- name: activate demo apache site
file: src=/etc/apache2/sites-available/demo.conf dest=/etc/apache2/sites-enabled/demo.conf state=link
notify: restart apache2

View File

@@ -1,6 +1,6 @@
---
- name: install tools
apt: name={{item}} state=present update_cache=yes
with_items:
loop:
- curl
- python-httplib2
- python3-httplib2

View File

@@ -0,0 +1,10 @@
---
- import_playbook: playbooks/hostname.yml
- import_playbook: database.yml
- import_playbook: webserver.yml
- import_playbook: loadbalancer.yml
- import_playbook: control.yml
- import_playbook: playbooks/stack_status.yml
- import_playbook: playbooks/stack_restart.yml
- import_playbook: playbooks/stack_status.yml

View File

@@ -1,43 +1,8 @@
---
- hosts: webserver
become: true
tasks:
- name: install web components
apt: name={{item}} state=present update_cache=yes
with_items:
- apache2
- libapache2-mod-wsgi
- python-pip
- python-virtualenv
- python-mysqldb
roles:
- apache2
- name: ensure apache2 started
service: name=apache2 state=started enabled=yes
- name: ensure mod_wsgi enabled
apache2_module: state=present name=wsgi
notify: restart apache2
- name: copy demo app source
copy: src=demo/app/ dest=/var/www/demo mode=0755
notify: restart apache2
- name: copy apache virtual host config
copy: src=demo/demo.conf dest=/etc/apache2/sites-available mode=0755
notify: restart apache2
- name: setup python virtualenv
pip: requirements=/var/www/demo/requirements.txt virtualenv=/var/www/demo/.venv
notify: restart apache2
- name: de-activate default apache site
file: path=/etc/apache2/sites-enabled/000-default.conf state=absent
notify: restart apache2
- name: activate demo apache site
file: src=/etc/apache2/sites-available/demo.conf dest=/etc/apache2/sites-enabled/demo.conf state=link
notify: restart apache2
handlers:
- name: restart apache2
service: name=apache2 state=restarted