Petit stack
This commit is contained in:
11
examples/016_tasks_handlers/hosts
Normal file
11
examples/016_tasks_handlers/hosts
Normal 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
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
tasks:
|
tasks:
|
||||||
- name: install tools
|
- name: install tools
|
||||||
apt: name={{item}} state=present update_cache=yes
|
apt: name={{item}} state=present update_cache=yes
|
||||||
with_items:
|
loop:
|
||||||
- python-httplib2
|
- python3-httplib2
|
||||||
|
|
||||||
- name: install nginx
|
- name: install nginx
|
||||||
apt: name=nginx state=present update_cache=yes
|
apt: name=nginx state=present update_cache=yes
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
---
|
---
|
||||||
- hosts: all
|
- hosts: all
|
||||||
tasks:
|
tasks:
|
||||||
- name: get server hostname
|
- name: Ping to servers
|
||||||
|
ping:
|
||||||
|
- name: Get hostname
|
||||||
command: hostname
|
command: hostname
|
||||||
|
register: hostname
|
||||||
|
- name: Show hostname with message
|
||||||
|
debug:
|
||||||
|
msg: "The hostname of this server is {{ hostname.stdout }}"
|
||||||
|
|||||||
@@ -30,38 +30,38 @@
|
|||||||
tasks:
|
tasks:
|
||||||
- name: verify end-to-end index response
|
- name: verify end-to-end index response
|
||||||
uri: url=http://{{item}} return_content=yes
|
uri: url=http://{{item}} return_content=yes
|
||||||
with_items: groups.loadbalancer
|
loop: groups.loadbalancer
|
||||||
register: lb_index
|
register: lb_index
|
||||||
|
|
||||||
- fail: msg="index failed to return content"
|
- fail: msg="index failed to return content"
|
||||||
when: "'Hello, from sunny' not in item.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
|
- name: verify end-to-end db response
|
||||||
uri: url=http://{{item}}/db return_content=yes
|
uri: url=http://{{item}}/db return_content=yes
|
||||||
with_items: groups.loadbalancer
|
loop: groups.loadbalancer
|
||||||
register: lb_db
|
register: lb_db
|
||||||
|
|
||||||
- fail: msg="db failed to return content"
|
- fail: msg="db failed to return content"
|
||||||
when: "'Database Connected from' not in item.content"
|
when: "'Database Connected from' not in item.content"
|
||||||
with_items: "{{lb_db.results}}"
|
loop: "{{lb_db.results}}"
|
||||||
|
|
||||||
- hosts: loadbalancer
|
- hosts: loadbalancer
|
||||||
tasks:
|
tasks:
|
||||||
- name: verify backend index response
|
- name: verify backend index response
|
||||||
uri: url=http://{{item}} return_content=yes
|
uri: url=http://{{item}} return_content=yes
|
||||||
with_items: groups.webserver
|
loop: groups.webserver
|
||||||
register: app_index
|
register: app_index
|
||||||
|
|
||||||
- fail: msg="index failed to return content"
|
- fail: msg="index failed to return content"
|
||||||
when: "'Hello, from sunny {{item.item}}!' not in item.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
|
- name: verify backend db response
|
||||||
uri: url=http://{{item}}/db return_content=yes
|
uri: url=http://{{item}}/db return_content=yes
|
||||||
with_items: groups.webserver
|
loop: groups.webserver
|
||||||
register: app_db
|
register: app_db
|
||||||
|
|
||||||
- fail: msg="db failed to return content"
|
- fail: msg="db failed to return content"
|
||||||
when: "'Database Connected from {{item.item}}!' not in item.content"
|
when: "'Database Connected from {{item.item}}!' not in item.content"
|
||||||
with_items: "{{app_db.results}}"
|
loop: "{{app_db.results}}"
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
---
|
---
|
||||||
# handlers file for apache2
|
# handlers file for apache2
|
||||||
|
- name: restart apache2
|
||||||
|
service: name=apache2 state=restarted
|
||||||
@@ -1,2 +1,37 @@
|
|||||||
---
|
---
|
||||||
# tasks file for apache2
|
# 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
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
- name: install tools
|
- name: install tools
|
||||||
apt: name={{item}} state=present update_cache=yes
|
apt: name={{item}} state=present update_cache=yes
|
||||||
with_items:
|
loop:
|
||||||
- curl
|
- curl
|
||||||
- python-httplib2
|
- python3-httplib2
|
||||||
|
|||||||
10
examples/016_tasks_handlers/site.yml
Normal file
10
examples/016_tasks_handlers/site.yml
Normal 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
|
||||||
|
|
||||||
@@ -1,43 +1,8 @@
|
|||||||
---
|
---
|
||||||
- hosts: webserver
|
- hosts: webserver
|
||||||
become: true
|
become: true
|
||||||
tasks:
|
roles:
|
||||||
- name: install web components
|
|
||||||
apt: name={{item}} state=present update_cache=yes
|
|
||||||
with_items:
|
|
||||||
- apache2
|
- apache2
|
||||||
- libapache2-mod-wsgi
|
|
||||||
- python-pip
|
|
||||||
- python-virtualenv
|
|
||||||
- python-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
|
|
||||||
|
|
||||||
handlers:
|
|
||||||
- name: restart apache2
|
|
||||||
service: name=apache2 state=restarted
|
|
||||||
|
|||||||
Reference in New Issue
Block a user