diff --git a/apache/README.md b/apache/README.md new file mode 100644 index 0000000..b929a98 --- /dev/null +++ b/apache/README.md @@ -0,0 +1,23 @@ +Building a simple Apache Server and deploying index.html using Ansible Playbooks. +------------------------------------------- + +These playbooks require Ansible 1.2. + +These playbooks are meant to be a reference and starter's guide to building +Ansible Playbooks. These playbooks were tested on CentOS 6.x so we recommend +that you use CentOS or RHEL to test these modules. + +The Apache server can be on a single node or multiple nodes. The inventory file +'hosts' defines the nodes in which the stacks should be configured. + + [webservers] + localhost + +Here the webserver would be configured on the local host. This can be deployed +using the following command: + + ansible-playbook -i hosts site.yml + +Once done, you can check the results by browsing to http://localhost/index.php. +You should see a simple test page and a list of databases retrieved from the +database server. diff --git a/apache/group_vars/all b/apache/group_vars/all new file mode 100644 index 0000000..b4c54cc --- /dev/null +++ b/apache/group_vars/all @@ -0,0 +1,3 @@ +--- +# Variables listed here are applicable to all host groups + diff --git a/apache/group_vars/webservers b/apache/group_vars/webservers new file mode 100644 index 0000000..1e3e433 --- /dev/null +++ b/apache/group_vars/webservers @@ -0,0 +1,3 @@ +--- +# The variables file used by the playbooks in the webservers group. +# These don't have to be explicitly imported by vars_files: they are autopopulated. diff --git a/apache/hosts b/apache/hosts new file mode 100644 index 0000000..be8d78f --- /dev/null +++ b/apache/hosts @@ -0,0 +1,2 @@ +[webservers] +web1 diff --git a/apache/roles/apache/handlers/main.yml b/apache/roles/apache/handlers/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/apache/roles/apache/tasks/deploy_site.yml b/apache/roles/apache/tasks/deploy_site.yml new file mode 100644 index 0000000..955109c --- /dev/null +++ b/apache/roles/apache/tasks/deploy_site.yml @@ -0,0 +1,9 @@ +--- +# These tasks are responsible for copying the latest dev/production code from +# the version control system. + +- name: Copy the code from repository + git: repo={{ repository }} dest=/var/www/html/ + +- name: Creates the index.html file + template: src=index.html.j2 dest=/var/www/html/index.html diff --git a/apache/roles/apache/tasks/install_apache.yml b/apache/roles/apache/tasks/install_apache.yml new file mode 100644 index 0000000..be09217 --- /dev/null +++ b/apache/roles/apache/tasks/install_apache.yml @@ -0,0 +1,13 @@ +--- +# These tasks install apache. + +- name: install packages + yum: name=httpd state=present + when: ansible_os_family == "RedHat" + +- name: install packages + apt: name=apache2 state=present + when: ansible_os_family == "Debian" + +- name: http service state + service: name=httpd state=started enabled=yes diff --git a/apache/roles/apache/tasks/main.yml b/apache/roles/apache/tasks/main.yml new file mode 100644 index 0000000..1786709 --- /dev/null +++ b/apache/roles/apache/tasks/main.yml @@ -0,0 +1,3 @@ +--- +- include: install_apache.yml +- include: copy_code.yml diff --git a/apache/roles/apache/templates/index.html.j2 b/apache/roles/apache/templates/index.html.j2 new file mode 100644 index 0000000..9822a1c --- /dev/null +++ b/apache/roles/apache/templates/index.html.j2 @@ -0,0 +1,10 @@ + + + Ansible Application + + +
+ Homepage +
+ + diff --git a/apache/roles/common/handlers/main.yml b/apache/roles/common/handlers/main.yml new file mode 100644 index 0000000..e6989f3 --- /dev/null +++ b/apache/roles/common/handlers/main.yml @@ -0,0 +1,3 @@ +--- +# Handler to handle common notifications. Handlers are called by other plays. +# See http://ansible.cc/docs/playbooks.html for more information about handlers. diff --git a/apache/roles/common/tasks/main.yml b/apache/roles/common/tasks/main.yml new file mode 100644 index 0000000..889f705 --- /dev/null +++ b/apache/roles/common/tasks/main.yml @@ -0,0 +1,2 @@ +--- +# This playbook contains common plays that will be run on all nodes. diff --git a/apache/site.yml b/apache/site.yml new file mode 100644 index 0000000..3e0f9ab --- /dev/null +++ b/apache/site.yml @@ -0,0 +1,16 @@ +--- +# This playbook deploys, update and config apache. + +- name: common config + hosts: all + user: root + + roles: + - common + +- name: apache + hosts: webservers + user: root + + roles: + - apache