Skip to content

Commit

Permalink
Add openstack ansible playbook
Browse files Browse the repository at this point in the history
  • Loading branch information
Remy committed Jul 20, 2014
1 parent 055fbc6 commit 9cc0deb
Show file tree
Hide file tree
Showing 18 changed files with 726 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Ansible

My ansible playbooks.

* lighttpd-nodes is used for installing and configuring lighttpd with an ssl certificate as I want it.
* lighttpd-nodes is used for installing and configuring lighttpd.
* raymon is used to deploy my little status monitoring applicaton server: [Ray-Mon](https://raymii.org/cms/p_Bash_PHP_Server_Status_Monitor)
* start is for the app by Bas ten Feld: [start](https://github.com/develup/start)
* munin-client is used to install munin client, it has the [hostedmunin.com](http://hostedmunin.com) servers by default, but you can essily define your own.
Expand All @@ -13,6 +13,7 @@ My ansible playbooks.
* sudo is to set up sudo as I like it, with an admin group and such.
* vpn is used to set ip an IPSEC/L2TP VPN server with local user (PAM/UNIX) authentication [as described here](https://raymii.org/s/tutorials/IPSEC_L2TP_vpn_with_Ubuntu_12.04.html)
* tor is used to set up a tor relay node
* openstack-example is used for the following tutorial: []()

Playbooks are here merely for example for others and reference.

Expand All @@ -23,7 +24,7 @@ Playbooks are here merely for example for others and reference.

Unless otherwise stated:

Copyright (C) 2013 Remy van Elst
Copyright (C) 2014 Remy van Elst

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
4 changes: 4 additions & 0 deletions openstack-example/files/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
header('Location: site/');
exit;
?>
25 changes: 25 additions & 0 deletions openstack-example/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---

- name: restart nginx
service:
name: nginx
state: restarted
enabled: yes

- name: restart keepalived
service:
name: keepalived
state: restarted
enabled: yes

- name: restart mysql
service:
name: mysql
state: restarted
enabled: yes

- name: restart apache2
service:
name: apache2
state: restarted
enabled: yes
47 changes: 47 additions & 0 deletions openstack-example/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
- name: Create Instances
hosts: 127.0.0.1
connection: local
vars_files:
- "vars/main.yml"
tasks:
- include: tasks/create-instances.yml

# Both lbs group and app group but only execute on lbs group. Otherwise
# facts about app group are not gathered and config fails
- name: Configure LoadBalancers
hosts: lbs:app
vars_files:
- "vars/main.yml"
user: root
tasks:
- include: tasks/configure-lbs.yml
when: '"{{ inventory_hostname }}" in "{{ groups.lbs }}"'
- include: tasks/keepalived.yml
when: '"{{ inventory_hostname }}" in "{{ groups.lbs }}"'
handlers:
- include: handlers/main.yml

- name: Configure Databases
hosts: dbs
vars_files:
- "vars/main.yml"
user: root
tasks:
- include: tasks/configure-dbs.yml
- include: tasks/keepalived.yml
handlers:
- include: handlers/main.yml

- name: Configure App Server
hosts: app
vars_files:
- "vars/main.yml"
user: root
tasks:
- include: tasks/configure-gluster-app.yml
- include: tasks/configure-app.yml
handlers:
- include: handlers/main.yml


37 changes: 37 additions & 0 deletions openstack-example/tasks/configure-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
- apt:
name="{{ item }}"
state=latest
update_cache=yes
with_items:
- php5-mysql
- python-pip
- php5
- libapache2-mod-php5
- php5-mcrypt
- vim
- git
- ntp

- git:
repo: https://github.com/WordPress/WordPress.git
dest: /var/www/html/site
force: yes
update: no
when: '"{{ inventory_hostname }}" == "{{ groups.app[0] }}"'


- file:
dest: /var/www/html/index.html
state: absent

- template:
src: wp-config.php.j2
dest: /var/www/html/site/wp-config.php
when: '"{{ inventory_hostname }}" == "{{ groups.app[0] }}"'


- copy:
src: index.php
dest: /var/www/html/index.php
when: '"{{ inventory_hostname }}" == "{{ groups.app[0] }}"'
80 changes: 80 additions & 0 deletions openstack-example/tasks/configure-dbs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
- apt:
name="{{ item }}"
state=latest
update_cache=yes
with_items:
- mysql-server
- python-mysqldb
- vim
- git
- ntp

- template:
src: my.cnf.j2
dest: /etc/mysql/my.cnf
notify:
- restart mysql

- fetch:
src: /etc/mysql/debian.cnf
flat: yes
dest: "/tmp/my.cnf.{{ ansible_hostname }}"

- copy:
src: "/tmp/my.cnf.{{ ansible_hostname }}"
dest: /root/.my.cnf

- mysql_user:
user: ""
state: "absent"

- mysql_user:
name: "{{ mysql_user }}"
password: "{{ mysql_password }}"
host: "%"
priv: '{{ mysql_user }}.*:ALL'
state: present

- mysql_db:
name: "{{ mysql_user }}"
state: present

- mysql_user:
name: "replicator"
host: "%"
password: "{{ mysql_password }}"
priv: "*.*:REPLICATION SLAVE"
state: present
notify:
- restart mysql

- stat: path=/etc/mysql/ansible.repl
register: check_sql_path

- mysql_replication:
mode: changemaster
master_host: "{{ groups.dbs[1] }}"
master_user: replicator
master_password: "{{ mysql_password }}"
when: check_sql_path.stat.exists == false and '{{ inventory_hostname }}' == '{{ groups.dbs[0] }}'
register: sqlresult0
notify:
- restart mysql

- mysql_replication:
mode: changemaster
master_host: "{{ groups.dbs[0] }}"
master_user: replicator
master_password: "{{ mysql_password }}"
when: check_sql_path.stat.exists == false and '{{ inventory_hostname }}' == '{{ groups.dbs[1] }}'
register: sqlresult1
notify:
- restart mysql

- command: touch /etc/mysql/repl.ansible
when: check_sql_path.stat.exists == false and '{{ inventory_hostname }}' == '{{ groups.dbs[1] }}'

- command: touch /etc/mysql/repl.ansible
when: check_sql_path.stat.exists == false and '{{ inventory_hostname }}' == '{{ groups.dbs[1] }}'

48 changes: 48 additions & 0 deletions openstack-example/tasks/configure-gluster-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
# boot bug in standard 14.04 packages: https://bugs.launchpad.net/ubuntu/+source/glusterfs/+bug/1268064
- apt_repository:
repo: 'ppa:semiosis/ubuntu-glusterfs-3.4'
state: present
update_cache: yes

- apt:
name: "{{ item }}"
state: installed
update_cache: yes
with_items:
- glusterfs-server
- glusterfs-client

- file:
path: "{{ gluster_brick_dir }}"
state: directory

- shell: "gluster peer probe {{ item }}"
with_items:
- "{{ groups.app }}"

- shell: 'echo {{ groups.app }} | sed -e "s/\]//g" -e "s/, u/, /g" -e "s/\[u//g" -e "s%,%:{{ gluster_brick_dir }} %g; s%$%:{{ gluster_brick_dir }}%"'
register: gluster_bricks
connection: local

- shell: 'gluster volume info {{ gluster_volume }} ||
gluster volume create {{ gluster_volume }} transport tcp replica 2
{{ gluster_bricks.stdout }} force'
when: '"{{ inventory_hostname }}" == "{{ groups.app[0] }}"'

- wait_for:
delay: 15
timeout: 15

- shell: 'gluster volume info {{ gluster_volume }} | grep "Status: Started" ||
gluster volume start {{ gluster_volume }}'

- file:
path: "/var/www/html"
state: directory

- mount:
name: /var/www/html
fstype: glusterfs
src: "{{ groups.app[0] }}:{{ gluster_volume }}"
state: mounted
41 changes: 41 additions & 0 deletions openstack-example/tasks/configure-lbs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
- apt_repository:
repo: 'ppa:nginx/stable'
state: present
update_cache: yes

- apt:
name: "{{ item }}"
state: latest
update_cache: yes
with_items:
- nginx
- vim
- git
- ntp

- file:
dest: /var/cache/nginx
state: directory
owner: www-data

- template:
src: nginx-lb.conf.j2
dest: /etc/nginx/sites-available/lbs.conf
notify:
- restart nginx

- file:
src: /etc/nginx/sites-available/lbs.conf
dest: /etc/nginx/sites-enabled/lbs.conf
state: link
notify:
- restart nginx

- file:
dest: /etc/nginx/sites-enabled/default
state: absent
notify:
- restart nginx


Loading

0 comments on commit 9cc0deb

Please sign in to comment.