commit e1e343667a13feb4060fb785e6d8e743d59d0d25 Author: Guillem Hernandez Sola Date: Fri May 30 09:53:45 2025 +0200 Added all files diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..a242a50 --- /dev/null +++ b/.gitignore @@ -0,0 +1,78 @@ + +# Created by https://www.gitignore.io/api/macos,windows,vagrant,ansible,visualstudiocode + +### Ansible ### +*.retry + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Vagrant ### +# General +.vagrant/ + +# Log files (if you are creating logs in debug mode, uncomment this) +# *.logs + +### Vagrant Patch ### +*.box + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + + +# End of https://www.gitignore.io/api/macos,windows,vagrant,ansible,visualstudiocode \ No newline at end of file diff --git a/README.md b/README.md new file mode 100755 index 0000000..f2b5b31 --- /dev/null +++ b/README.md @@ -0,0 +1,229 @@ +[![Agile611](https://www.agile611.com/wp-content/uploads/2020/09/cropped-logo-header.png)](http://www.agile611.com/) + +# Agile611 Ansible Training + +This repository contains the code examples from the configuration management tools Ansible. It uses Vagrant to demonstrate these tools in practice. + +## Requirements + +For Ansible, it is necessary to install [Ansible](http://docs.ansible.com/ansible/intro_installation.html) on the host machine. This repo uses a Vagrant box based on Ubuntu and we will use APT to install ansible. + +## Example code + +Clone this repository with: + +```shell +git clone https://bitbucket.org/agile611/startusingansible.git +``` + +## Initial configuration + +* Start environment, we are going to need 4 ubuntu boxes (Ansible, Alfa, Bravo, Charlie) + +```shell +vagrant up +vagrant ssh ansible +``` + +* Starting workspace on ansible box + +```shell +vagrant@ansible$ sudo apt-get update +vagrant@ansible$ sudo apt-get install ansible -y +``` + +* Check your ansible installation checking the response from this command: + +```shell +vagrant@ansible$ ansible localhost -m setup +``` + +* Create a ssh key to connect to the webserver box just pressing enter to the requested questions: + +```shell +vagrant@ansible$ ssh-keygen +vagrant@ansible$ cat /home/vagrant/.ssh/id_rsa.pub +``` + +* Copy /home/vagrant/.ssh/id_rsa.pub into the clipboard on webserver box and execute: + +```shell +vagrant@alfa$ sudo -s +root@alfa# mkdir /root/.ssh +root@alfa# echo 'full contents of id_rsa.pub from ansible node' > /root/.ssh/authorized_keys +root@alfa# chmod 700 /root/.ssh +root@alfa# chmod 640 /root/.ssh/authorized_keys +``` + +* Check if you can connect to the webserver using the ssh key (not prompting a password). + +```shell +vagrant@ansible$ ssh root@192.168.0.2 +``` + +If you can connect, the initial config is done. Repeat this for Bravo and Charlie Vms. + +### IMPORTANT NOTE +Priority order from the config files: +* ANSIBLE_CONFIG (environment variable POSIX) +* ansible.cfg (current folder) +* ~/.ansible.cfg (user home from the executor) +* /etc/ansible/ansible.cfg (general file) + +## Test the environment + +* Setup Ansible Inventory on the ansible box, create the following folders: + +```shell +vagrant@ansible$ mkdir example_ansible +vagrant@ansible$ mkdir example_ansible/hosts +vagrant@ansible$ nano example_ansible/hosts/all +``` + +And on the file `hosts/all` and the following lines: + +```ini +[alfa] +192.168.0.2 + +[bravo] +192.168.0.3 +``` + +* Check if everything works executing the following command: + +```shell +vagrant@ansible$ cd example_ansible +vagrant@ansible$ ansible -i hosts -u root -m ping all +``` + +* What happen? + +The expected response is as follows: + +```shell +192.168.0.2 | SUCCESS => { + "changed": false, + "ping": "pong" +} +``` + +## Initial configuration and first yaml file + +* Create the file `request.yml` + +```yaml +--- +- hosts: webserver + + tasks: + - name: What system are you? + command: uname -a + register: info + + - name: print var + debug: var=info + + - name: print field + debug: var=info.stdout + + - name: What your name? + command: hostname + register: info + + - name: Give me your name + debug: var=info.stdout +``` + +* Execute the following command to show what tasks are we going to execute: + +```shell + +vagrant@ansible$ ansible-playbook -i hosts/all -u root request.yml --list-hosts --list-tasks +``` + +* Execute the following command to perform the tasks described before: + +```shell +vagrant@ansible$ ansible-playbook -i hosts/all -u root request.yml +``` + +### IMPORTANT NOTE + +The user root is used here for testing purposes and to make the environment easier to implement. Note that it is also the user which has the ssh key installed. You can add the ssh key to the user you in order to execute Ansible commands. + +### More examples (on examples folder) + +* 000_initial_examples +* 001_apt +* 002_become +* 003_with_items +* 004_services +* 005_stack_restart +* 006_notify_handlers +* 007_files_copy +* 008_pip +* 009_files +* 010_templates +* 011_lineinfile +* 012_mysql_management +* 013_wait_for +* 014_stack_status +* 015_roles +* 016_tasks_handlers +* 017_files_templates +* 018_site_yml +* 019_facts +* 020_defaults +* 021_vars +* 022_with_dict +* 023_selective_removal +* 024_continued +* 025_vars_files_group_vars +* 026_vault + +## Problems provisioning the box + +If you have problems provisioning the box, you can download it directly from [here](https://app.vagrantup.com/bento/boxes/ubuntu-20.04/versions/202112.19.0/providers/virtualbox.box) + +After that you need to know the path of the box and execute the following command: + +```shell + vagrant box add /The/Path/From/Your/Downloaded/box/bento-ubuntu-20-04.box --name bento/ubuntu-20.04 + vagrant init bento/ubuntu-20.04 +``` + +The init command creates a VagrantFile with your initial configuration. On the same folder where this Vagrantfile is, please execute to following command: + +```shell + vagrant up +``` + +After that, please connect to the box using the following command: + +```shell + vagrant ssh +``` + +If you get a terminal from the box, your environment is ready. + +## Common networking problems + +If you have proxies or VPNs running on your machine, it is possible that Vagrant is not able to provision your environment. + +Please check your connectivity before. + +## Support + +This tutorial is released into the public domain by [Agile611](http://www.agile611.com/) under Creative Commons Attribution-NonCommercial 4.0 International. + +[![License: CC BY-NC 4.0](https://img.shields.io/badge/License-CC_BY--NC_4.0-lightgrey.svg)](https://creativecommons.org/licenses/by-nc/4.0/) + + +This README file was originally written by [Guillem Hernández Sola](https://www.linkedin.com/in/guillemhs/) and is likewise released into the public domain. + +Please contact Agile611 for further details. + +* [Agile611](http://www.agile611.com/) +* Laureà Miró 309 +* 08950 Esplugues de Llobregat (Barcelona) \ No newline at end of file diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..9ea6272 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,59 @@ +Vagrant.configure(2) do |config| + # Máquina de control para el agente Ansible + config.vm.define "ansible" do |ansible| + ansible.vm.box = "bento/ubuntu-24.04" # Imagen base Ubuntu 24.04 + ansible.vm.network "private_network", ip: "192.168.11.10" # IP privada + ansible.vm.hostname = "ansible" # Nombre de host + ansible.vm.synced_folder ".", "/home/vagrant/sync", type: "rsync" # Carpeta sincronizada + ansible.vm.provider "virtualbox" do |vb| + vb.memory = 512 # Memoria RAM asignada + vb.cpus = 1 # Número de CPUs asignadas + end + ansible.vm.provision :shell, :path => "ansible.sh" # Script de aprovisionamiento + end + + # Máquina para la base de datos + config.vm.define "database" do |database| + database.vm.box = "bento/ubuntu-24.04" + database.vm.network "private_network", ip: "192.168.11.20" + database.vm.hostname = "database" + database.vm.synced_folder ".", "/home/vagrant/sync", type: "rsync" + database.vm.provision :shell, :path => "ansible.sh" + database.vm.network "forwarded_port", guest: 80, host: 8081 # Redirección del puerto 80 + database.vm.network "forwarded_port", guest: 3306, host: 3306 # Redirección del puerto MySQL + database.vm.provider "virtualbox" do |vb| + vb.memory = 512 + vb.cpus = 1 + end + end + + # Máquina para el balanceador de carga + config.vm.define "loadbalancer" do |loadbalancer| + loadbalancer.vm.box = "bento/ubuntu-24.04" + loadbalancer.vm.network "private_network", ip: "192.168.11.30" + loadbalancer.vm.hostname = "loadbalancer" + loadbalancer.vm.synced_folder ".", "/home/vagrant/sync", type: "rsync" + loadbalancer.vm.provision :shell, :path => "ansible.sh" + loadbalancer.vm.network "forwarded_port", guest: 80, host: 8080 # Redirección del puerto 80 + loadbalancer.vm.network "forwarded_port", guest: 3306, host: 33061 # Redirección del puerto MySQL alternativo + loadbalancer.vm.provider "virtualbox" do |vb| + vb.memory = 512 + vb.cpus = 1 + end + end + + # Máquina para el servidor web + config.vm.define "webserver" do |webserver| + webserver.vm.box = "bento/ubuntu-24.04" + webserver.vm.network "private_network", ip: "192.168.11.40" + webserver.vm.hostname = "webserver" + webserver.vm.synced_folder ".", "/home/vagrant/sync", type: "rsync" + webserver.vm.provision :shell, :path => "ansible.sh" + webserver.vm.network "forwarded_port", guest: 80, host: 80 # Redirección del puerto 80 + webserver.vm.network "forwarded_port", guest: 3306, host: 33062 # Redirección del puerto MySQL alternativo + webserver.vm.provider "virtualbox" do |vb| + vb.memory = 512 + vb.cpus = 1 + end + end + end \ No newline at end of file diff --git a/ansible.sh b/ansible.sh new file mode 100644 index 0000000..8127e16 --- /dev/null +++ b/ansible.sh @@ -0,0 +1,6 @@ +apt-get update +apt install software-properties-common -y +apt-add-repository ppa:ansible/ansible +apt-get install ansible net-tools -y +# Add vagrant user to sudoers +echo "vagrant ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/vagrant \ No newline at end of file diff --git a/examples/000_example/group_vars/all b/examples/000_example/group_vars/all new file mode 100755 index 0000000..6f2aaac --- /dev/null +++ b/examples/000_example/group_vars/all @@ -0,0 +1,3 @@ +--- +httpd_port: 80 +ntpserver: 192.168.0.2 diff --git a/examples/000_example/group_vars/webservers b/examples/000_example/group_vars/webservers new file mode 100755 index 0000000..2514c06 --- /dev/null +++ b/examples/000_example/group_vars/webservers @@ -0,0 +1,7 @@ +iface: '{{ ansible_default_ipv4.interface }}' +apache_test_message: hello world +apache_max_keep_alive_requests: 113 +apache_docroot: /var/www/html +sites_available: /etc/httpd/conf/sites-available +sites_enabled: /etc/httpd/conf/sites-enabled +lameapp_version: 1 diff --git a/examples/000_example/hosts b/examples/000_example/hosts new file mode 100755 index 0000000..5e5fc9c --- /dev/null +++ b/examples/000_example/hosts @@ -0,0 +1,2 @@ +[webservers] +192.168.0.2 \ No newline at end of file diff --git a/examples/000_example/roles/apache/README.md b/examples/000_example/roles/apache/README.md new file mode 100755 index 0000000..225dd44 --- /dev/null +++ b/examples/000_example/roles/apache/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/000_example/roles/apache/defaults/main.yml b/examples/000_example/roles/apache/defaults/main.yml new file mode 100755 index 0000000..596f53c --- /dev/null +++ b/examples/000_example/roles/apache/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for apache \ No newline at end of file diff --git a/examples/000_example/roles/apache/handlers/main.yml b/examples/000_example/roles/apache/handlers/main.yml new file mode 100755 index 0000000..d65a488 --- /dev/null +++ b/examples/000_example/roles/apache/handlers/main.yml @@ -0,0 +1,4 @@ +--- +# handlers file for apache +- name: restart apache + service: name=apache2 state=restarted diff --git a/examples/000_example/roles/apache/meta/main.yml b/examples/000_example/roles/apache/meta/main.yml new file mode 100755 index 0000000..7223799 --- /dev/null +++ b/examples/000_example/roles/apache/meta/main.yml @@ -0,0 +1,57 @@ +galaxy_info: + author: your name + description: your description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + + min_ansible_version: 1.2 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # Optionally specify the branch Galaxy will use when accessing the GitHub + # repo for this role. During role install, if no tags are available, + # Galaxy will use this branch. During import Galaxy will access files on + # this branch. If Travis integration is configured, only notifications for this + # branch will be accepted. Otherwise, in all cases, the repo's default branch + # (usually master) will be used. + #github_branch: + + # + # platforms is a list of platforms, and each platform has a name and a list of versions. + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. \ No newline at end of file diff --git a/examples/000_example/roles/apache/tasks/main.yml b/examples/000_example/roles/apache/tasks/main.yml new file mode 100755 index 0000000..ec2922b --- /dev/null +++ b/examples/000_example/roles/apache/tasks/main.yml @@ -0,0 +1,19 @@ +--- +# tasks file for apache +- name: install apache + apt: name=apache2 state=present update-cache=yes + +- name: copy index.html + template: + src: index.html.j2 + dest: /var/www/html/index.html + +- name: copy httpd conf + template: + src: httpd.conf.j2 + dest: /etc/apache2 + notify: restart apache + +- name: start apache + service: + name: apache2 state=started enabled=yes diff --git a/examples/000_example/roles/apache/templates/httpd.conf.j2 b/examples/000_example/roles/apache/templates/httpd.conf.j2 new file mode 100755 index 0000000..dd2e0fb --- /dev/null +++ b/examples/000_example/roles/apache/templates/httpd.conf.j2 @@ -0,0 +1,225 @@ +# {{ ansible_managed }} + +# This is the main Apache server configuration file. It contains the +# configuration directives that give the server its instructions. +# See http://httpd.apache.org/docs/2.4/ for detailed information about +# the directives and /usr/share/doc/apache2/README.Debian about Debian specific +# hints. +# +# +# Summary of how the Apache 2 configuration works in Debian: +# The Apache 2 web server configuration in Debian is quite different to +# upstream's suggested way to configure the web server. This is because Debian's +# default Apache2 installation attempts to make adding and removing modules, +# virtual hosts, and extra configuration directives as flexible as possible, in +# order to make automating the changes and administering the server as easy as +# possible. + +ServerName {{ apache2_server_name|default(ansible_fqdn) }} + +# It is split into several files forming the configuration hierarchy outlined +# below, all located in the /etc/apache2/ directory: +# +# /etc/apache2/ +# |-- apache2.conf +# | `-- ports.conf +# |-- mods-enabled +# | |-- *.load +# | `-- *.conf +# |-- conf-enabled +# | `-- *.conf +# `-- sites-enabled +# `-- *.conf +# +# +# * apache2.conf is the main configuration file (this file). It puts the pieces +# together by including all remaining configuration files when starting up the +# web server. +# +# * ports.conf is always included from the main configuration file. It is +# supposed to determine listening ports for incoming connections which can be +# customized anytime. +# +# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/ +# directories contain particular configuration snippets which manage modules, +# global configuration fragments, or virtual host configurations, +# respectively. +# +# They are activated by symlinking available configuration files from their +# respective *-available/ counterparts. These should be managed by using our +# helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See +# their respective man pages for detailed information. +# +# * The binary is called apache2. Due to the use of environment variables, in +# the default configuration, apache2 needs to be started/stopped with +# /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not +# work with the default configuration. + + +# Global configuration +# + +# +# ServerRoot: The top of the directory tree under which the server's +# configuration, error, and log files are kept. +# +# NOTE! If you intend to place this on an NFS (or otherwise network) +# mounted filesystem then please read the Mutex documentation (available +# at ); +# you will save yourself a lot of trouble. +# +# Do NOT add a slash at the end of the directory path. +# +#ServerRoot "/etc/apache2" + +# +# The accept serialization lock file MUST BE STORED ON A LOCAL DISK. +# +Mutex file:${APACHE_LOCK_DIR} default + +# +# PidFile: The file in which the server should record its process +# identification number when it starts. +# This needs to be set in /etc/apache2/envvars +# +PidFile ${APACHE_PID_FILE} + +# +# Timeout: The number of seconds before receives and sends time out. +# +Timeout 300 + +# +# KeepAlive: Whether or not to allow persistent connections (more than +# one request per connection). Set to "Off" to deactivate. +# +KeepAlive On + +# +# MaxKeepAliveRequests: The maximum number of requests to allow +# during a persistent connection. Set to 0 to allow an unlimited amount. +# We recommend you leave this number high, for maximum performance. +# +MaxKeepAliveRequests 100 + +# +# KeepAliveTimeout: Number of seconds to wait for the next request from the +# same client on the same connection. +# +KeepAliveTimeout 5 + + +# These need to be set in /etc/apache2/envvars +User ${APACHE_RUN_USER} +Group ${APACHE_RUN_GROUP} + +# +# HostnameLookups: Log the names of clients or just their IP addresses +# e.g., www.apache.org (on) or 204.62.129.132 (off). +# The default is off because it'd be overall better for the net if people +# had to knowingly turn this feature on, since enabling it means that +# each client request will result in AT LEAST one lookup request to the +# nameserver. +# +HostnameLookups Off + +# ErrorLog: The location of the error log file. +# If you do not specify an ErrorLog directive within a +# container, error messages relating to that virtual host will be +# logged here. If you *do* define an error logfile for a +# container, that host's errors will be logged there and not here. +# +ErrorLog ${APACHE_LOG_DIR}/error.log + +# +# LogLevel: Control the severity of messages logged to the error_log. +# Available values: trace8, ..., trace1, debug, info, notice, warn, +# error, crit, alert, emerg. +# It is also possible to configure the log level for particular modules, e.g. +# "LogLevel info ssl:warn" +# +LogLevel warn + +# Include module configuration: +IncludeOptional mods-enabled/*.load +IncludeOptional mods-enabled/*.conf + +# Include list of ports to listen on +Include ports.conf + + +# Sets the default security model of the Apache2 HTTPD server. It does +# not allow access to the root filesystem outside of /usr/share and /var/www. +# The former is used by web applications packaged in Debian, +# the latter may be used for local directories served by the web server. If +# your system is serving content from a sub-directory in /srv you must allow +# access here, or in any related virtual host. + + Options FollowSymLinks + AllowOverride None + Require all denied + + + + AllowOverride None + Require all granted + + + + Options FollowSymLinks + AllowOverride None + Require all granted + + +# +# Options Indexes FollowSymLinks +# AllowOverride None +# Require all granted +# + + + + +# AccessFileName: The name of the file to look for in each directory +# for additional configuration directives. See also the AllowOverride +# directive. +# +AccessFileName .htaccess + +# +# The following lines prevent .htaccess and .htpasswd files from being +# viewed by Web clients. +# + + Require all denied + + + +# +# The following directives define some format nicknames for use with +# a CustomLog directive. +# +# These deviate from the Common Log Format definitions in that they use %O +# (the actual bytes sent including headers) instead of %b (the size of the +# requested file), because the latter makes it impossible to detect partial +# requests. +# +# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended. +# Use mod_remoteip instead. +# +LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined +LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined +LogFormat "%h %l %u %t \"%r\" %>s %O" common +LogFormat "%{Referer}i -> %U" referer +LogFormat "%{User-agent}i" agent + +# Include of directories ignores editors' and dpkg's backup files, +# see README.Debian for details. + +# Include generic snippets of statements +IncludeOptional conf-enabled/*.conf + +# Include the virtual host configurations: +IncludeOptional sites-enabled/*.conf + +# vim: syntax=apache ts=4 sw=4 sts=4 sr noet \ No newline at end of file diff --git a/examples/000_example/roles/apache/templates/index.html.j2 b/examples/000_example/roles/apache/templates/index.html.j2 new file mode 100755 index 0000000..c8da5d9 --- /dev/null +++ b/examples/000_example/roles/apache/templates/index.html.j2 @@ -0,0 +1,6 @@ +{{ apache_test_message }} {{ ansible_distribution }} {{ ansible_distribution_version }}
+Current Host: {{ ansible_hostname }}
+Server list:
+{% for host in groups.webservers %} +{{ host }}
+{% endfor %} diff --git a/examples/000_example/roles/apache/tests/inventory b/examples/000_example/roles/apache/tests/inventory new file mode 100755 index 0000000..878877b --- /dev/null +++ b/examples/000_example/roles/apache/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/examples/000_example/roles/apache/tests/test.yml b/examples/000_example/roles/apache/tests/test.yml new file mode 100755 index 0000000..6df1468 --- /dev/null +++ b/examples/000_example/roles/apache/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: webservers + remote_user: root + roles: + - apache \ No newline at end of file diff --git a/examples/000_example/roles/apache/vars/main.yml b/examples/000_example/roles/apache/vars/main.yml new file mode 100755 index 0000000..1173dc9 --- /dev/null +++ b/examples/000_example/roles/apache/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for apache \ No newline at end of file diff --git a/examples/000_example/roles/common/README.md b/examples/000_example/roles/common/README.md new file mode 100755 index 0000000..225dd44 --- /dev/null +++ b/examples/000_example/roles/common/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/000_example/roles/common/defaults/main.yml b/examples/000_example/roles/common/defaults/main.yml new file mode 100755 index 0000000..fa30550 --- /dev/null +++ b/examples/000_example/roles/common/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for common \ No newline at end of file diff --git a/examples/000_example/roles/common/handlers/main.yml b/examples/000_example/roles/common/handlers/main.yml new file mode 100755 index 0000000..4d78ef2 --- /dev/null +++ b/examples/000_example/roles/common/handlers/main.yml @@ -0,0 +1,4 @@ +--- +# handlers file for common +- name: restart ntp + service: name=ntpd state=restarted diff --git a/examples/000_example/roles/common/meta/main.yml b/examples/000_example/roles/common/meta/main.yml new file mode 100755 index 0000000..7223799 --- /dev/null +++ b/examples/000_example/roles/common/meta/main.yml @@ -0,0 +1,57 @@ +galaxy_info: + author: your name + description: your description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + + min_ansible_version: 1.2 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # Optionally specify the branch Galaxy will use when accessing the GitHub + # repo for this role. During role install, if no tags are available, + # Galaxy will use this branch. During import Galaxy will access files on + # this branch. If Travis integration is configured, only notifications for this + # branch will be accepted. Otherwise, in all cases, the repo's default branch + # (usually master) will be used. + #github_branch: + + # + # platforms is a list of platforms, and each platform has a name and a list of versions. + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. \ No newline at end of file diff --git a/examples/000_example/roles/common/tasks/main.yml b/examples/000_example/roles/common/tasks/main.yml new file mode 100755 index 0000000..293c480 --- /dev/null +++ b/examples/000_example/roles/common/tasks/main.yml @@ -0,0 +1,9 @@ +--- +# tasks file for common +- name: install epel repo + apt: + name: epel-release + state: present + +- include: selinux.yml +- include: ntp.yml diff --git a/examples/000_example/roles/common/tasks/ntp.yml b/examples/000_example/roles/common/tasks/ntp.yml new file mode 100755 index 0000000..f9e704e --- /dev/null +++ b/examples/000_example/roles/common/tasks/ntp.yml @@ -0,0 +1,15 @@ +--- +- name: install ntp + apt: + name: ntp + state: present + +- name: configure ntp file + template: + src: ntp.conf.j2 + dest: /etc/ntp.conf + +- name: start ntp + service: + name: ntpd + state: started diff --git a/examples/000_example/roles/common/tasks/selinux.yml b/examples/000_example/roles/common/tasks/selinux.yml new file mode 100755 index 0000000..7ef6a3c --- /dev/null +++ b/examples/000_example/roles/common/tasks/selinux.yml @@ -0,0 +1,13 @@ +--- +- name: install python bindings for SELinux + apt: + name: {{item}} + state: present + with_items: + - libselinux-python + - libsemanage-python + +- name: test to see if SELinux is running + command: getenforce + register: sestatus + changed_when: false diff --git a/examples/000_example/roles/common/templates/ntp.conf.j2 b/examples/000_example/roles/common/templates/ntp.conf.j2 new file mode 100755 index 0000000..e5c5483 --- /dev/null +++ b/examples/000_example/roles/common/templates/ntp.conf.j2 @@ -0,0 +1,7 @@ +driftfile /var/lib/ntp/drift + +restrict 127.0.0.1 +restrict -6 ::1 +server {{ ntpserver }} +includefile /etc/ntp/crypto/pw +keys /etc/ntp/keys diff --git a/examples/000_example/roles/common/tests/inventory b/examples/000_example/roles/common/tests/inventory new file mode 100755 index 0000000..878877b --- /dev/null +++ b/examples/000_example/roles/common/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/examples/000_example/roles/common/tests/test.yml b/examples/000_example/roles/common/tests/test.yml new file mode 100755 index 0000000..8d24282 --- /dev/null +++ b/examples/000_example/roles/common/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - common \ No newline at end of file diff --git a/examples/000_example/roles/common/vars/main.yml b/examples/000_example/roles/common/vars/main.yml new file mode 100755 index 0000000..feaa92f --- /dev/null +++ b/examples/000_example/roles/common/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for common \ No newline at end of file diff --git a/examples/000_example/site.yml b/examples/000_example/site.yml new file mode 100755 index 0000000..d867915 --- /dev/null +++ b/examples/000_example/site.yml @@ -0,0 +1,7 @@ +--- +- name: install and start apache + hosts: webservers + remote_user: root + become: yes + roles: + - apache \ No newline at end of file diff --git a/examples/000_initial_example/001-hostname.yml b/examples/000_initial_example/001-hostname.yml new file mode 100644 index 0000000..130eef3 --- /dev/null +++ b/examples/000_initial_example/001-hostname.yml @@ -0,0 +1,4 @@ +--- + - hosts: all + tasks: + - command: hostname \ No newline at end of file diff --git a/examples/000_initial_example/hosts b/examples/000_initial_example/hosts new file mode 100644 index 0000000..6c37d55 --- /dev/null +++ b/examples/000_initial_example/hosts @@ -0,0 +1,19 @@ +[database] +192.168.0.2 +192.168.0.3 + +[loadbalancer] +192.168.0.3 +192.168.0.4 + +[webserver] +192.168.0.4 + +[alfa] +192.168.0.2 + +[bravo] +192.168.0.3 + +[charlie] +192.168.0.4 diff --git a/examples/000_initial_examples/etc_ansible_hosts b/examples/000_initial_examples/etc_ansible_hosts new file mode 100755 index 0000000..56f0156 --- /dev/null +++ b/examples/000_initial_examples/etc_ansible_hosts @@ -0,0 +1,12 @@ +[loadbalancer] +lb01 ansible_connection=local + +[webserver] +app01 ansible_connection=local +app02 ansible_connection=local + +[database] +db01 ansible_connection=local + +[control] +control ansible_connection=local diff --git a/examples/000_initial_examples/hostname.yml b/examples/000_initial_examples/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/000_initial_examples/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/000_initial_examples/your-first-hosts-file b/examples/000_initial_examples/your-first-hosts-file new file mode 100644 index 0000000..4861c2d --- /dev/null +++ b/examples/000_initial_examples/your-first-hosts-file @@ -0,0 +1,12 @@ +[loadbalancer] +lb01 + +[webserver] +app01 +app02 + +[database] +db01 + +[control] +control ansible_connection=local diff --git a/examples/001_apt/database.yml b/examples/001_apt/database.yml new file mode 100644 index 0000000..063f7d6 --- /dev/null +++ b/examples/001_apt/database.yml @@ -0,0 +1,5 @@ +--- +- hosts: database + tasks: + - name: install mysql-server + apt: name=mysql-server state=present update_cache=yes diff --git a/examples/001_apt/hostname.yml b/examples/001_apt/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/001_apt/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/001_apt/hosts b/examples/001_apt/hosts new file mode 100644 index 0000000..af525aa --- /dev/null +++ b/examples/001_apt/hosts @@ -0,0 +1,5 @@ +[database] +192.168.0.2 + +[loadbalancer] +192.168.0.3 \ No newline at end of file diff --git a/examples/001_apt/loadbalancer.yml b/examples/001_apt/loadbalancer.yml new file mode 100644 index 0000000..1639d97 --- /dev/null +++ b/examples/001_apt/loadbalancer.yml @@ -0,0 +1,5 @@ +--- +- hosts: loadbalancer + tasks: + - name: install nginx + apt: name=nginx state=present update_cache=yes diff --git a/examples/002_become/database.yml b/examples/002_become/database.yml new file mode 100644 index 0000000..82aa0f1 --- /dev/null +++ b/examples/002_become/database.yml @@ -0,0 +1,6 @@ +--- +- hosts: database + become: true + tasks: + - name: install mysql-server + apt: name=mysql-server state=present update_cache=yes diff --git a/examples/002_become/hostname.yml b/examples/002_become/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/002_become/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/002_become/hosts b/examples/002_become/hosts new file mode 100644 index 0000000..c4a9663 --- /dev/null +++ b/examples/002_become/hosts @@ -0,0 +1,8 @@ +[database] +192.168.0.2 + +[loadbalancer] +192.168.0.3 + +[webserver] +192.168.0.4 \ No newline at end of file diff --git a/examples/002_become/loadbalancer.yml b/examples/002_become/loadbalancer.yml new file mode 100644 index 0000000..50881f9 --- /dev/null +++ b/examples/002_become/loadbalancer.yml @@ -0,0 +1,6 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: install nginx + apt: name=nginx state=present update_cache=yes diff --git a/examples/003_with_items/database.yml b/examples/003_with_items/database.yml new file mode 100644 index 0000000..82aa0f1 --- /dev/null +++ b/examples/003_with_items/database.yml @@ -0,0 +1,6 @@ +--- +- hosts: database + become: true + tasks: + - name: install mysql-server + apt: name=mysql-server state=present update_cache=yes diff --git a/examples/003_with_items/hostname.yml b/examples/003_with_items/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/003_with_items/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/003_with_items/loadbalancer.yml b/examples/003_with_items/loadbalancer.yml new file mode 100644 index 0000000..50881f9 --- /dev/null +++ b/examples/003_with_items/loadbalancer.yml @@ -0,0 +1,6 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: install nginx + apt: name=nginx state=present update_cache=yes diff --git a/examples/003_with_items/webserver.yml b/examples/003_with_items/webserver.yml new file mode 100644 index 0000000..c6042e4 --- /dev/null +++ b/examples/003_with_items/webserver.yml @@ -0,0 +1,12 @@ +--- +- hosts: webserver + become: true + tasks: + - name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + - python-pip-whl + - python3-virtualenv + diff --git a/examples/004_services/control.yml b/examples/004_services/control.yml new file mode 100644 index 0000000..999da09 --- /dev/null +++ b/examples/004_services/control.yml @@ -0,0 +1,8 @@ +--- +- hosts: control + become: true + tasks: + - name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - uacme diff --git a/examples/004_services/database.yml b/examples/004_services/database.yml new file mode 100644 index 0000000..06dd2cf --- /dev/null +++ b/examples/004_services/database.yml @@ -0,0 +1,9 @@ +--- +- hosts: database + become: true + tasks: + - name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + + - name: ensure mysql started + service: name=mysql state=started enabled=yes diff --git a/examples/004_services/loadbalancer.yml b/examples/004_services/loadbalancer.yml new file mode 100644 index 0000000..435b161 --- /dev/null +++ b/examples/004_services/loadbalancer.yml @@ -0,0 +1,9 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: install nginx + apt: name=nginx state=present update_cache=yes + + - name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/004_services/playbooks/hostname.yml b/examples/004_services/playbooks/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/004_services/playbooks/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/004_services/playbooks/stack_restart.yml b/examples/004_services/playbooks/stack_restart.yml new file mode 100644 index 0000000..fbfb979 --- /dev/null +++ b/examples/004_services/playbooks/stack_restart.yml @@ -0,0 +1,18 @@ +--- +- hosts: database + become: true + tasks: + - name: reiniciar mysql + service: name=mysql state=restarted + +- hosts: loadbalancer + become: true + tasks: + - name: reiniciar nginx + service: name=nginx state=restarted + +- hosts: webserver + become: true + tasks: + - name: reiniciar apache + service: name=apache2 state=restarted diff --git a/examples/004_services/playbooks/stack_restart.yml.save b/examples/004_services/playbooks/stack_restart.yml.save new file mode 100644 index 0000000..6be67be --- /dev/null +++ b/examples/004_services/playbooks/stack_restart.yml.save @@ -0,0 +1,17 @@ +--- +- hosts: database + become: true + tasks: + - name: reiniciar mysql + service: name=mysql state=restarted + +- hosts: loadbalancer + become: true + tasks: + - name: reiniciar nginx + service: name=nginx state=restarted + +- hosts: webserver + become: true + tasks: + service: name=apache2 state=restarted diff --git a/examples/004_services/playbooks/stack_stopped.yml b/examples/004_services/playbooks/stack_stopped.yml new file mode 100644 index 0000000..88e2354 --- /dev/null +++ b/examples/004_services/playbooks/stack_stopped.yml @@ -0,0 +1,18 @@ +--- +- hosts: database + become: true + tasks: + - name: parar mysql + service: name=mysql state=stopped + +- hosts: loadbalancer + become: true + tasks: + - name: parar nginx + service: name=nginx state=stopped + +- hosts: webserver + become: true + tasks: + - name: parar apache + service: name=apache2 state=stopped diff --git a/examples/004_services/webserver.yml b/examples/004_services/webserver.yml new file mode 100644 index 0000000..b0d8b28 --- /dev/null +++ b/examples/004_services/webserver.yml @@ -0,0 +1,14 @@ +--- +- hosts: webserver + become: true + tasks: + - name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + - python-pip-whl + - python3-virtualenv + + - name: ensure apache2 started + service: name=apache2 state=started enabled=yes diff --git a/examples/005_stack_restart/control.yml b/examples/005_stack_restart/control.yml new file mode 100644 index 0000000..999da09 --- /dev/null +++ b/examples/005_stack_restart/control.yml @@ -0,0 +1,8 @@ +--- +- hosts: control + become: true + tasks: + - name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - uacme diff --git a/examples/005_stack_restart/database.yml b/examples/005_stack_restart/database.yml new file mode 100644 index 0000000..0eac33a --- /dev/null +++ b/examples/005_stack_restart/database.yml @@ -0,0 +1,9 @@ +--- +- hosts: database + become: true + tasks: + - name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + + - name: ensure mysql started + service: name=mysql state=started enabled=yes \ No newline at end of file diff --git a/examples/005_stack_restart/loadbalancer.yml b/examples/005_stack_restart/loadbalancer.yml new file mode 100644 index 0000000..435b161 --- /dev/null +++ b/examples/005_stack_restart/loadbalancer.yml @@ -0,0 +1,9 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: install nginx + apt: name=nginx state=present update_cache=yes + + - name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/005_stack_restart/playbook/hostname.yml b/examples/005_stack_restart/playbook/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/005_stack_restart/playbook/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/005_stack_restart/playbook/stack_restart.yml b/examples/005_stack_restart/playbook/stack_restart.yml new file mode 100644 index 0000000..a78d1b2 --- /dev/null +++ b/examples/005_stack_restart/playbook/stack_restart.yml @@ -0,0 +1,28 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started diff --git a/examples/005_stack_restart/webserver.yml b/examples/005_stack_restart/webserver.yml new file mode 100644 index 0000000..b0d8b28 --- /dev/null +++ b/examples/005_stack_restart/webserver.yml @@ -0,0 +1,14 @@ +--- +- hosts: webserver + become: true + tasks: + - name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + - python-pip-whl + - python3-virtualenv + + - name: ensure apache2 started + service: name=apache2 state=started enabled=yes diff --git a/examples/006_notify_handlers/control.yml b/examples/006_notify_handlers/control.yml new file mode 100644 index 0000000..cab13d4 --- /dev/null +++ b/examples/006_notify_handlers/control.yml @@ -0,0 +1,8 @@ +--- +- hosts: control + become: true + tasks: + - name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl diff --git a/examples/006_notify_handlers/database.yml b/examples/006_notify_handlers/database.yml new file mode 100644 index 0000000..06dd2cf --- /dev/null +++ b/examples/006_notify_handlers/database.yml @@ -0,0 +1,9 @@ +--- +- hosts: database + become: true + tasks: + - name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + + - name: ensure mysql started + service: name=mysql state=started enabled=yes diff --git a/examples/006_notify_handlers/demo/app/demo.py b/examples/006_notify_handlers/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/006_notify_handlers/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/006_notify_handlers/demo/app/demo.wsgi b/examples/006_notify_handlers/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/006_notify_handlers/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/006_notify_handlers/demo/app/requirements.txt b/examples/006_notify_handlers/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/006_notify_handlers/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/006_notify_handlers/demo/demo.conf b/examples/006_notify_handlers/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/006_notify_handlers/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/006_notify_handlers/loadbalancer.yml b/examples/006_notify_handlers/loadbalancer.yml new file mode 100644 index 0000000..435b161 --- /dev/null +++ b/examples/006_notify_handlers/loadbalancer.yml @@ -0,0 +1,9 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: install nginx + apt: name=nginx state=present update_cache=yes + + - name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/006_notify_handlers/playbook/hostname.yml b/examples/006_notify_handlers/playbook/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/006_notify_handlers/playbook/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/006_notify_handlers/playbook/stack_restart.yml b/examples/006_notify_handlers/playbook/stack_restart.yml new file mode 100644 index 0000000..a78d1b2 --- /dev/null +++ b/examples/006_notify_handlers/playbook/stack_restart.yml @@ -0,0 +1,28 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started diff --git a/examples/006_notify_handlers/webserver.yml b/examples/006_notify_handlers/webserver.yml new file mode 100644 index 0000000..6c7f752 --- /dev/null +++ b/examples/006_notify_handlers/webserver.yml @@ -0,0 +1,22 @@ +--- +- hosts: webserver + become: true + tasks: + - name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + - python-pip-whl + - python3-virtualenv + + - 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 + + handlers: + - name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/007_files_copy/control.yml b/examples/007_files_copy/control.yml new file mode 100644 index 0000000..cab13d4 --- /dev/null +++ b/examples/007_files_copy/control.yml @@ -0,0 +1,8 @@ +--- +- hosts: control + become: true + tasks: + - name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl diff --git a/examples/007_files_copy/database.yml b/examples/007_files_copy/database.yml new file mode 100644 index 0000000..06dd2cf --- /dev/null +++ b/examples/007_files_copy/database.yml @@ -0,0 +1,9 @@ +--- +- hosts: database + become: true + tasks: + - name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + + - name: ensure mysql started + service: name=mysql state=started enabled=yes diff --git a/examples/007_files_copy/demo/app/demo.py b/examples/007_files_copy/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/007_files_copy/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/007_files_copy/demo/app/demo.wsgi b/examples/007_files_copy/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/007_files_copy/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/007_files_copy/demo/app/requirements.txt b/examples/007_files_copy/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/007_files_copy/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/007_files_copy/demo/demo.conf b/examples/007_files_copy/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/007_files_copy/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/007_files_copy/loadbalancer.yml b/examples/007_files_copy/loadbalancer.yml new file mode 100644 index 0000000..435b161 --- /dev/null +++ b/examples/007_files_copy/loadbalancer.yml @@ -0,0 +1,9 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: install nginx + apt: name=nginx state=present update_cache=yes + + - name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/007_files_copy/playbook/hostname.yml b/examples/007_files_copy/playbook/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/007_files_copy/playbook/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/007_files_copy/playbook/stack_restart.yml b/examples/007_files_copy/playbook/stack_restart.yml new file mode 100644 index 0000000..a78d1b2 --- /dev/null +++ b/examples/007_files_copy/playbook/stack_restart.yml @@ -0,0 +1,28 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started diff --git a/examples/007_files_copy/webserver.yml b/examples/007_files_copy/webserver.yml new file mode 100644 index 0000000..26ef088 --- /dev/null +++ b/examples/007_files_copy/webserver.yml @@ -0,0 +1,30 @@ +--- +- hosts: webserver + become: true + tasks: + - name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + - python-pip-whl + - python3-virtualenv + + - 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 + + handlers: + - name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/008_pip/control.yml b/examples/008_pip/control.yml new file mode 100644 index 0000000..cab13d4 --- /dev/null +++ b/examples/008_pip/control.yml @@ -0,0 +1,8 @@ +--- +- hosts: control + become: true + tasks: + - name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl diff --git a/examples/008_pip/database.yml b/examples/008_pip/database.yml new file mode 100644 index 0000000..06dd2cf --- /dev/null +++ b/examples/008_pip/database.yml @@ -0,0 +1,9 @@ +--- +- hosts: database + become: true + tasks: + - name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + + - name: ensure mysql started + service: name=mysql state=started enabled=yes diff --git a/examples/008_pip/demo/app/demo.py b/examples/008_pip/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/008_pip/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/008_pip/demo/app/demo.wsgi b/examples/008_pip/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/008_pip/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/008_pip/demo/app/requirements.txt b/examples/008_pip/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/008_pip/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/008_pip/demo/demo.conf b/examples/008_pip/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/008_pip/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/008_pip/loadbalancer.yml b/examples/008_pip/loadbalancer.yml new file mode 100644 index 0000000..435b161 --- /dev/null +++ b/examples/008_pip/loadbalancer.yml @@ -0,0 +1,9 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: install nginx + apt: name=nginx state=present update_cache=yes + + - name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/008_pip/playbook/hostname.yml b/examples/008_pip/playbook/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/008_pip/playbook/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/008_pip/playbook/stack_restart.yml b/examples/008_pip/playbook/stack_restart.yml new file mode 100644 index 0000000..a78d1b2 --- /dev/null +++ b/examples/008_pip/playbook/stack_restart.yml @@ -0,0 +1,28 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started diff --git a/examples/008_pip/webserver.yml b/examples/008_pip/webserver.yml new file mode 100644 index 0000000..9c77cb5 --- /dev/null +++ b/examples/008_pip/webserver.yml @@ -0,0 +1,34 @@ +--- +- hosts: webserver + become: true + tasks: + - name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + - python-pip-whl + - python3-virtualenv + + - 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 + + handlers: + - name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/009_files/control.yml b/examples/009_files/control.yml new file mode 100644 index 0000000..cab13d4 --- /dev/null +++ b/examples/009_files/control.yml @@ -0,0 +1,8 @@ +--- +- hosts: control + become: true + tasks: + - name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl diff --git a/examples/009_files/database.yml b/examples/009_files/database.yml new file mode 100644 index 0000000..06dd2cf --- /dev/null +++ b/examples/009_files/database.yml @@ -0,0 +1,9 @@ +--- +- hosts: database + become: true + tasks: + - name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + + - name: ensure mysql started + service: name=mysql state=started enabled=yes diff --git a/examples/009_files/demo/app/demo.py b/examples/009_files/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/009_files/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/009_files/demo/app/demo.wsgi b/examples/009_files/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/009_files/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/009_files/demo/app/requirements.txt b/examples/009_files/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/009_files/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/009_files/demo/demo.conf b/examples/009_files/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/009_files/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/009_files/loadbalancer.yml b/examples/009_files/loadbalancer.yml new file mode 100644 index 0000000..435b161 --- /dev/null +++ b/examples/009_files/loadbalancer.yml @@ -0,0 +1,9 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: install nginx + apt: name=nginx state=present update_cache=yes + + - name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/009_files/playbook/hostname.yml b/examples/009_files/playbook/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/009_files/playbook/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/009_files/playbook/stack_restart.yml b/examples/009_files/playbook/stack_restart.yml new file mode 100644 index 0000000..a78d1b2 --- /dev/null +++ b/examples/009_files/playbook/stack_restart.yml @@ -0,0 +1,28 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started diff --git a/examples/009_files/webserver.yml b/examples/009_files/webserver.yml new file mode 100644 index 0000000..c73bf4f --- /dev/null +++ b/examples/009_files/webserver.yml @@ -0,0 +1,42 @@ +--- +- hosts: webserver + become: true + tasks: + - name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + - python-pip-whl + - python3-virtualenv + + - 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 diff --git a/examples/010_templates/control.yml b/examples/010_templates/control.yml new file mode 100644 index 0000000..cab13d4 --- /dev/null +++ b/examples/010_templates/control.yml @@ -0,0 +1,8 @@ +--- +- hosts: control + become: true + tasks: + - name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl diff --git a/examples/010_templates/database.yml b/examples/010_templates/database.yml new file mode 100644 index 0000000..06dd2cf --- /dev/null +++ b/examples/010_templates/database.yml @@ -0,0 +1,9 @@ +--- +- hosts: database + become: true + tasks: + - name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + + - name: ensure mysql started + service: name=mysql state=started enabled=yes diff --git a/examples/010_templates/demo/app/demo.py b/examples/010_templates/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/010_templates/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/010_templates/demo/app/demo.wsgi b/examples/010_templates/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/010_templates/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/010_templates/demo/app/requirements.txt b/examples/010_templates/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/010_templates/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/010_templates/demo/demo.conf b/examples/010_templates/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/010_templates/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/010_templates/loadbalancer.yml b/examples/010_templates/loadbalancer.yml new file mode 100644 index 0000000..835a4bc --- /dev/null +++ b/examples/010_templates/loadbalancer.yml @@ -0,0 +1,25 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: install nginx + apt: name=nginx state=present update_cache=yes + + - name: ensure nginx started + service: name=nginx state=started enabled=yes + + - name: configure nginx site + template: src=templates/nginx.conf.j2 dest=/etc/nginx/sites-available/demo mode=0644 + notify: restart nginx + + - name: de-activate default nginx site + file: path=/etc/nginx/sites-enabled/default state=absent + notify: restart nginx + + - name: activate demo nginx site + file: src=/etc/nginx/sites-available/demo dest=/etc/nginx/sites-enabled/demo state=link + notify: restart nginx + + handlers: + - name: restart nginx + service: name=nginx state=restarted diff --git a/examples/010_templates/playbook/hostname.yml b/examples/010_templates/playbook/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/010_templates/playbook/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/010_templates/playbook/loadbalancer-default-nginx.yml b/examples/010_templates/playbook/loadbalancer-default-nginx.yml new file mode 100644 index 0000000..d5d037c --- /dev/null +++ b/examples/010_templates/playbook/loadbalancer-default-nginx.yml @@ -0,0 +1,18 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: ensure nginx started + service: name=nginx state=started enabled=yes + + - name: de-activate demo nginx site + file: path=/etc/nginx/sites-enabled/demo state=absent + notify: restart nginx + + - name: activate default nginx site + file: src=/etc/nginx/sites-available/default dest=/etc/nginx/sites-enabled/default state=link + notify: restart nginx + + handlers: + - name: restart nginx + service: name=nginx state=restarted diff --git a/examples/010_templates/playbook/nginx-default.conf b/examples/010_templates/playbook/nginx-default.conf new file mode 100644 index 0000000..4d4c865 --- /dev/null +++ b/examples/010_templates/playbook/nginx-default.conf @@ -0,0 +1,137 @@ + +#user nobody; +#Defines which Linux system user will own and run the Nginx server + +worker_processes 1; +#Referes to single threaded process. Generally set to be equal to the number of CPUs or cores. + +#error_log logs/error.log; #error_log logs/error.log notice; +#Specifies the file where server logs. + +#pid logs/nginx.pid; +#nginx will write its master process ID(PID). + +events { + worker_connections 1024; + # worker_processes and worker_connections allows you to calculate maxclients value: + # max_clients = worker_processes * worker_connections +} + + +http { + include mime.types; + # anything written in /opt/nginx/conf/mime.types is interpreted as if written inside the http { } block + + default_type application/octet-stream; + # + + #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + # '$status $body_bytes_sent "$http_referer" ' + # '"$http_user_agent" "$http_x_forwarded_for"'; + + #access_log logs/access.log main; + + sendfile on; + # If serving locally stored static files, sendfile is essential to speed up the server, + # But if using as reverse proxy one can deactivate it + + #tcp_nopush on; + # works opposite to tcp_nodelay. Instead of optimizing delays, it optimizes the amount of data sent at once. + + #keepalive_timeout 0; + keepalive_timeout 65; + # timeout during which a keep-alive client connection will stay open. + + #gzip on; + # tells the server to use on-the-fly gzip compression. + + server { + # You would want to make a separate file with its own server block for each virtual domain + # on your server and then include them. + listen 80; + #tells Nginx the hostname and the TCP port where it should listen for HTTP connections. + # listen 80; is equivalent to listen *:80; + + server_name localhost; + # lets you doname-based virtual hosting + + #charset koi8-r; + + #access_log logs/host.access.log main; + + location / { + #The location setting lets you configure how nginx responds to requests for resources within the server. + root html; + index index.html index.htm; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} + } + + + # another virtual host using mix of IP-, name-, and port-based configuration + # + #server { + # listen 8000; + # listen somename:8080; + # server_name somename alias another.alias; + + # location / { + # root html; + # index index.html index.htm; + # } + #} + + + # HTTPS server + # + #server { + # listen 443 ssl; + # server_name localhost; + + # ssl_certificate cert.pem; + # ssl_certificate_key cert.key; + + # ssl_session_cache shared:SSL:1m; + # ssl_session_timeout 5m; + + # ssl_ciphers HIGH:!aNULL:!MD5; + # ssl_prefer_server_ciphers on; + + # location / { + # root html; + # index index.html index.htm; + # } + #} + +} diff --git a/examples/010_templates/playbook/nginx-default.html b/examples/010_templates/playbook/nginx-default.html new file mode 100644 index 0000000..10e3638 --- /dev/null +++ b/examples/010_templates/playbook/nginx-default.html @@ -0,0 +1,36 @@ + + + +Welcome to nginx on Debian! + + + +

Welcome to nginx on Debian!

+

If you see this page, the nginx web server is successfully installed and +working on Debian. Further configuration is required.

+ +

For online documentation and support please refer to +nginx.org

+ +

+ Please use the reportbug tool to report bugs in the + nginx package with Debian. However, check existing + bug reports before reporting a new bug. +

+ +

Thank you for using debian and nginx.

+ +

BackupPi_2

+

monitor

+

say

+

Set DateTime

+ + + diff --git a/examples/010_templates/playbook/stack_restart.yml b/examples/010_templates/playbook/stack_restart.yml new file mode 100644 index 0000000..a78d1b2 --- /dev/null +++ b/examples/010_templates/playbook/stack_restart.yml @@ -0,0 +1,28 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started diff --git a/examples/010_templates/templates/nginx.conf.j2 b/examples/010_templates/templates/nginx.conf.j2 new file mode 100644 index 0000000..4b477b6 --- /dev/null +++ b/examples/010_templates/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream demo { +{% for server in groups.webserver %} + server {{ server }}; +{% endfor %} +} + +server { + listen 80; + + location / { + proxy_pass http://demo; + } +} diff --git a/examples/010_templates/webserver.yml b/examples/010_templates/webserver.yml new file mode 100644 index 0000000..c73bf4f --- /dev/null +++ b/examples/010_templates/webserver.yml @@ -0,0 +1,42 @@ +--- +- hosts: webserver + become: true + tasks: + - name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + - python-pip-whl + - python3-virtualenv + + - 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 diff --git a/examples/011_lineinfile/control.yml b/examples/011_lineinfile/control.yml new file mode 100644 index 0000000..cab13d4 --- /dev/null +++ b/examples/011_lineinfile/control.yml @@ -0,0 +1,8 @@ +--- +- hosts: control + become: true + tasks: + - name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl diff --git a/examples/011_lineinfile/database.yml b/examples/011_lineinfile/database.yml new file mode 100644 index 0000000..4650513 --- /dev/null +++ b/examples/011_lineinfile/database.yml @@ -0,0 +1,15 @@ +--- +- hosts: database + become: true + tasks: + - name: Remove packages for a VM problem using mysql + command: apt-get -y purge mysql-server mysql-client mysql-common + + - name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + + - name: ensure mysql started + service: name=mysql state=started enabled=yes + + - name: ensure mysql listening on all ports + lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address line="bind-address = 0.0.0.0" \ No newline at end of file diff --git a/examples/011_lineinfile/demo/app/demo.py b/examples/011_lineinfile/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/011_lineinfile/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/011_lineinfile/demo/app/demo.wsgi b/examples/011_lineinfile/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/011_lineinfile/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/011_lineinfile/demo/app/requirements.txt b/examples/011_lineinfile/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/011_lineinfile/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/011_lineinfile/demo/demo.conf b/examples/011_lineinfile/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/011_lineinfile/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/011_lineinfile/loadbalancer.yml b/examples/011_lineinfile/loadbalancer.yml new file mode 100644 index 0000000..835a4bc --- /dev/null +++ b/examples/011_lineinfile/loadbalancer.yml @@ -0,0 +1,25 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: install nginx + apt: name=nginx state=present update_cache=yes + + - name: ensure nginx started + service: name=nginx state=started enabled=yes + + - name: configure nginx site + template: src=templates/nginx.conf.j2 dest=/etc/nginx/sites-available/demo mode=0644 + notify: restart nginx + + - name: de-activate default nginx site + file: path=/etc/nginx/sites-enabled/default state=absent + notify: restart nginx + + - name: activate demo nginx site + file: src=/etc/nginx/sites-available/demo dest=/etc/nginx/sites-enabled/demo state=link + notify: restart nginx + + handlers: + - name: restart nginx + service: name=nginx state=restarted diff --git a/examples/011_lineinfile/playbook/hostname.yml b/examples/011_lineinfile/playbook/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/011_lineinfile/playbook/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/011_lineinfile/playbook/stack_restart.yml b/examples/011_lineinfile/playbook/stack_restart.yml new file mode 100644 index 0000000..a78d1b2 --- /dev/null +++ b/examples/011_lineinfile/playbook/stack_restart.yml @@ -0,0 +1,28 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started diff --git a/examples/011_lineinfile/templates/nginx.conf.j2 b/examples/011_lineinfile/templates/nginx.conf.j2 new file mode 100644 index 0000000..4b477b6 --- /dev/null +++ b/examples/011_lineinfile/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream demo { +{% for server in groups.webserver %} + server {{ server }}; +{% endfor %} +} + +server { + listen 80; + + location / { + proxy_pass http://demo; + } +} diff --git a/examples/011_lineinfile/webserver.yml b/examples/011_lineinfile/webserver.yml new file mode 100644 index 0000000..c73bf4f --- /dev/null +++ b/examples/011_lineinfile/webserver.yml @@ -0,0 +1,42 @@ +--- +- hosts: webserver + become: true + tasks: + - name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + - python-pip-whl + - python3-virtualenv + + - 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 diff --git a/examples/012_mysql_management/.clean-database.yml.swp b/examples/012_mysql_management/.clean-database.yml.swp new file mode 100644 index 0000000..af4f0fd Binary files /dev/null and b/examples/012_mysql_management/.clean-database.yml.swp differ diff --git a/examples/012_mysql_management/control.yml b/examples/012_mysql_management/control.yml new file mode 100644 index 0000000..cab13d4 --- /dev/null +++ b/examples/012_mysql_management/control.yml @@ -0,0 +1,8 @@ +--- +- hosts: control + become: true + tasks: + - name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl diff --git a/examples/012_mysql_management/database.yml b/examples/012_mysql_management/database.yml new file mode 100644 index 0000000..87ef6cf --- /dev/null +++ b/examples/012_mysql_management/database.yml @@ -0,0 +1,21 @@ +--- +- hosts: database + become: true + tasks: + - name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python3-mysqldb + - mysql-server + + - name: ensure mysql started + service: name=mysql state=started enabled=yes + + - name: ensure mysql listening on all ports + lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address line="bind-address = 0.0.0.0" + + - name: create demo database + mysql_db: name=demo state=present + + - name: create demo user + mysql_user: name=demo password=demo priv=demo.*:ALL host='%' state=present diff --git a/examples/012_mysql_management/demo/app/demo.py b/examples/012_mysql_management/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/012_mysql_management/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/012_mysql_management/demo/app/demo.wsgi b/examples/012_mysql_management/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/012_mysql_management/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/012_mysql_management/demo/app/requirements.txt b/examples/012_mysql_management/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/012_mysql_management/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/012_mysql_management/demo/demo.conf b/examples/012_mysql_management/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/012_mysql_management/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/012_mysql_management/loadbalancer.yml b/examples/012_mysql_management/loadbalancer.yml new file mode 100644 index 0000000..835a4bc --- /dev/null +++ b/examples/012_mysql_management/loadbalancer.yml @@ -0,0 +1,25 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: install nginx + apt: name=nginx state=present update_cache=yes + + - name: ensure nginx started + service: name=nginx state=started enabled=yes + + - name: configure nginx site + template: src=templates/nginx.conf.j2 dest=/etc/nginx/sites-available/demo mode=0644 + notify: restart nginx + + - name: de-activate default nginx site + file: path=/etc/nginx/sites-enabled/default state=absent + notify: restart nginx + + - name: activate demo nginx site + file: src=/etc/nginx/sites-available/demo dest=/etc/nginx/sites-enabled/demo state=link + notify: restart nginx + + handlers: + - name: restart nginx + service: name=nginx state=restarted diff --git a/examples/012_mysql_management/playbook/clean-database.yml b/examples/012_mysql_management/playbook/clean-database.yml new file mode 100644 index 0000000..189e817 --- /dev/null +++ b/examples/012_mysql_management/playbook/clean-database.yml @@ -0,0 +1,9 @@ +--- +- hosts: database + become: true + tasks: + - name: create demo database + mysql_db: name=demo state=absent + + - name: create demo user + mysql_user: name=demo password=demo priv=demo.*:ALL host='%' state=absent diff --git a/examples/012_mysql_management/playbook/hostname.yml b/examples/012_mysql_management/playbook/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/012_mysql_management/playbook/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/012_mysql_management/playbook/stack_restart.yml b/examples/012_mysql_management/playbook/stack_restart.yml new file mode 100644 index 0000000..f7ddec8 --- /dev/null +++ b/examples/012_mysql_management/playbook/stack_restart.yml @@ -0,0 +1,28 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + +# Restart mysql - commented problem with the VMs +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started diff --git a/examples/012_mysql_management/templates/nginx.conf.j2 b/examples/012_mysql_management/templates/nginx.conf.j2 new file mode 100644 index 0000000..4b477b6 --- /dev/null +++ b/examples/012_mysql_management/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream demo { +{% for server in groups.webserver %} + server {{ server }}; +{% endfor %} +} + +server { + listen 80; + + location / { + proxy_pass http://demo; + } +} diff --git a/examples/012_mysql_management/webserver.yml b/examples/012_mysql_management/webserver.yml new file mode 100644 index 0000000..c73bf4f --- /dev/null +++ b/examples/012_mysql_management/webserver.yml @@ -0,0 +1,42 @@ +--- +- hosts: webserver + become: true + tasks: + - name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + - python-pip-whl + - python3-virtualenv + + - 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 diff --git a/examples/013_wait_for/control.yml b/examples/013_wait_for/control.yml new file mode 100644 index 0000000..cab13d4 --- /dev/null +++ b/examples/013_wait_for/control.yml @@ -0,0 +1,8 @@ +--- +- hosts: control + become: true + tasks: + - name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl diff --git a/examples/013_wait_for/database.yml b/examples/013_wait_for/database.yml new file mode 100644 index 0000000..bf89f49 --- /dev/null +++ b/examples/013_wait_for/database.yml @@ -0,0 +1,28 @@ +--- +- hosts: database + become: true + tasks: + - name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python3-mysqldb + + - name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + + - name: ensure mysql started + service: name=mysql state=started enabled=yes + + - name: ensure mysql listening on all ports + lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address line="bind-address = 0.0.0.0" + notify: restart mysql + + - name: create demo database + mysql_db: name=demo state=present + + - name: create demo user + mysql_user: name=demo password=demo priv=demo.*:ALL host='%' state=present + + handlers: + - name: restart mysql + service: name=mysql state=restarted diff --git a/examples/013_wait_for/demo/app/demo.py b/examples/013_wait_for/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/013_wait_for/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/013_wait_for/demo/app/demo.wsgi b/examples/013_wait_for/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/013_wait_for/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/013_wait_for/demo/app/requirements.txt b/examples/013_wait_for/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/013_wait_for/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/013_wait_for/demo/demo.conf b/examples/013_wait_for/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/013_wait_for/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/013_wait_for/loadbalancer.yml b/examples/013_wait_for/loadbalancer.yml new file mode 100644 index 0000000..835a4bc --- /dev/null +++ b/examples/013_wait_for/loadbalancer.yml @@ -0,0 +1,25 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: install nginx + apt: name=nginx state=present update_cache=yes + + - name: ensure nginx started + service: name=nginx state=started enabled=yes + + - name: configure nginx site + template: src=templates/nginx.conf.j2 dest=/etc/nginx/sites-available/demo mode=0644 + notify: restart nginx + + - name: de-activate default nginx site + file: path=/etc/nginx/sites-enabled/default state=absent + notify: restart nginx + + - name: activate demo nginx site + file: src=/etc/nginx/sites-available/demo dest=/etc/nginx/sites-enabled/demo state=link + notify: restart nginx + + handlers: + - name: restart nginx + service: name=nginx state=restarted diff --git a/examples/013_wait_for/playbook/hostname.yml b/examples/013_wait_for/playbook/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/013_wait_for/playbook/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/013_wait_for/playbook/stack_restart.yml b/examples/013_wait_for/playbook/stack_restart.yml new file mode 100644 index 0000000..b55de3d --- /dev/null +++ b/examples/013_wait_for/playbook/stack_restart.yml @@ -0,0 +1,33 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + - wait_for: port=80 state=drained + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + - wait_for: port=80 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + - wait_for: port=3306 state=started + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + - wait_for: port=80 + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started + - wait_for: port=80 diff --git a/examples/013_wait_for/playbook/stack_status.yml b/examples/013_wait_for/playbook/stack_status.yml new file mode 100644 index 0000000..01df995 --- /dev/null +++ b/examples/013_wait_for/playbook/stack_status.yml @@ -0,0 +1,27 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: verify nginx service + command: service nginx status + + - name: verify nginx is listening on 80 + wait_for: port=80 timeout=3 + +- hosts: webserver + become: true + tasks: + - name: verify apache2 service + command: service apache2 status + + - name: verify apache2 is listening on 80 + wait_for: port=80 timeout=3 + +- hosts: database + become: true + tasks: + - name: verify mysql service + command: service mysql status + + - name: verify mysql is listening on 3306 + wait_for: port=3306 timeout=3 diff --git a/examples/013_wait_for/templates/nginx.conf.j2 b/examples/013_wait_for/templates/nginx.conf.j2 new file mode 100644 index 0000000..4b477b6 --- /dev/null +++ b/examples/013_wait_for/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream demo { +{% for server in groups.webserver %} + server {{ server }}; +{% endfor %} +} + +server { + listen 80; + + location / { + proxy_pass http://demo; + } +} diff --git a/examples/013_wait_for/webserver.yml b/examples/013_wait_for/webserver.yml new file mode 100644 index 0000000..ac133bf --- /dev/null +++ b/examples/013_wait_for/webserver.yml @@ -0,0 +1,43 @@ +--- +- hosts: webserver + become: true + tasks: + - name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + - python-pip-whl + - 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 + + handlers: + - name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/014_stack_status/control.yml b/examples/014_stack_status/control.yml new file mode 100644 index 0000000..8330bc1 --- /dev/null +++ b/examples/014_stack_status/control.yml @@ -0,0 +1,9 @@ +--- +- hosts: control + become: true + tasks: + - name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl + - python-httplib2 diff --git a/examples/014_stack_status/database.yml b/examples/014_stack_status/database.yml new file mode 100644 index 0000000..bf89f49 --- /dev/null +++ b/examples/014_stack_status/database.yml @@ -0,0 +1,28 @@ +--- +- hosts: database + become: true + tasks: + - name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python3-mysqldb + + - name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + + - name: ensure mysql started + service: name=mysql state=started enabled=yes + + - name: ensure mysql listening on all ports + lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address line="bind-address = 0.0.0.0" + notify: restart mysql + + - name: create demo database + mysql_db: name=demo state=present + + - name: create demo user + mysql_user: name=demo password=demo priv=demo.*:ALL host='%' state=present + + handlers: + - name: restart mysql + service: name=mysql state=restarted diff --git a/examples/014_stack_status/demo/app/demo.py b/examples/014_stack_status/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/014_stack_status/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/014_stack_status/demo/app/demo.wsgi b/examples/014_stack_status/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/014_stack_status/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/014_stack_status/demo/app/requirements.txt b/examples/014_stack_status/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/014_stack_status/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/014_stack_status/demo/demo.conf b/examples/014_stack_status/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/014_stack_status/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/014_stack_status/loadbalancer.yml b/examples/014_stack_status/loadbalancer.yml new file mode 100644 index 0000000..8063643 --- /dev/null +++ b/examples/014_stack_status/loadbalancer.yml @@ -0,0 +1,30 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python-httplib2 + + - name: install nginx + apt: name=nginx state=present update_cache=yes + + - name: ensure nginx started + service: name=nginx state=started enabled=yes + + - name: configure nginx site + template: src=templates/nginx.conf.j2 dest=/etc/nginx/sites-available/demo mode=0644 + notify: restart nginx + + - name: de-activate default nginx site + file: path=/etc/nginx/sites-enabled/default state=absent + notify: restart nginx + + - name: activate demo nginx site + file: src=/etc/nginx/sites-available/demo dest=/etc/nginx/sites-enabled/demo state=link + notify: restart nginx + + handlers: + - name: restart nginx + service: name=nginx state=restarted diff --git a/examples/014_stack_status/playbooks/hostname.yml b/examples/014_stack_status/playbooks/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/014_stack_status/playbooks/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/014_stack_status/playbooks/stack_restart.yml b/examples/014_stack_status/playbooks/stack_restart.yml new file mode 100644 index 0000000..b55de3d --- /dev/null +++ b/examples/014_stack_status/playbooks/stack_restart.yml @@ -0,0 +1,33 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + - wait_for: port=80 state=drained + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + - wait_for: port=80 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + - wait_for: port=3306 state=started + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + - wait_for: port=80 + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started + - wait_for: port=80 diff --git a/examples/014_stack_status/playbooks/stack_status.yml b/examples/014_stack_status/playbooks/stack_status.yml new file mode 100644 index 0000000..451221d --- /dev/null +++ b/examples/014_stack_status/playbooks/stack_status.yml @@ -0,0 +1,67 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: verify nginx service + command: service nginx status + + - name: verify nginx is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: webserver + become: true + tasks: + - name: verify apache2 service + command: service apache2 status + + - name: verify apache2 is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: database + become: true + tasks: + - name: verify mysql service + command: service mysql status + + - name: verify mysql is listening on 3306 + wait_for: port=3306 timeout=1 + +- hosts: control + tasks: + - name: verify end-to-end index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ 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}}" + + - name: verify end-to-end db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ 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}}" + +- hosts: loadbalancer + tasks: + - name: verify backend index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ groups.webserver }}" + register: app_index + + - fail: msg="index failed to return content" + when: "'Hello, from sunny' not in item.content" + with_items: "{{app_index.results}}" + + - name: verify backend db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ groups.webserver }}" + register: app_db + + - fail: msg="db failed to return content" + when: "'Database Connected from' not in item.content" + with_items: "{{app_db.results}}" diff --git a/examples/014_stack_status/templates/nginx.conf.j2 b/examples/014_stack_status/templates/nginx.conf.j2 new file mode 100644 index 0000000..4b477b6 --- /dev/null +++ b/examples/014_stack_status/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream demo { +{% for server in groups.webserver %} + server {{ server }}; +{% endfor %} +} + +server { + listen 80; + + location / { + proxy_pass http://demo; + } +} diff --git a/examples/014_stack_status/webserver.yml b/examples/014_stack_status/webserver.yml new file mode 100644 index 0000000..ac133bf --- /dev/null +++ b/examples/014_stack_status/webserver.yml @@ -0,0 +1,43 @@ +--- +- hosts: webserver + become: true + tasks: + - name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + - python-pip-whl + - 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 + + handlers: + - name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/015_roles/playbooks/hostname.yml b/examples/015_roles/playbooks/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/015_roles/playbooks/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/015_roles/playbooks/stack_restart.yml b/examples/015_roles/playbooks/stack_restart.yml new file mode 100644 index 0000000..b55de3d --- /dev/null +++ b/examples/015_roles/playbooks/stack_restart.yml @@ -0,0 +1,33 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + - wait_for: port=80 state=drained + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + - wait_for: port=80 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + - wait_for: port=3306 state=started + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + - wait_for: port=80 + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started + - wait_for: port=80 diff --git a/examples/015_roles/roles/apache2/.travis.yml b/examples/015_roles/roles/apache2/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/examples/015_roles/roles/apache2/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file diff --git a/examples/015_roles/roles/apache2/README.md b/examples/015_roles/roles/apache2/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/015_roles/roles/apache2/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/015_roles/roles/apache2/defaults/main.yml b/examples/015_roles/roles/apache2/defaults/main.yml new file mode 100644 index 0000000..0381169 --- /dev/null +++ b/examples/015_roles/roles/apache2/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for apache2 diff --git a/examples/015_roles/roles/apache2/handlers/main.yml b/examples/015_roles/roles/apache2/handlers/main.yml new file mode 100644 index 0000000..faa75e1 --- /dev/null +++ b/examples/015_roles/roles/apache2/handlers/main.yml @@ -0,0 +1,4 @@ +# handlers file for apache2 +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/015_roles/roles/apache2/meta/main.yml b/examples/015_roles/roles/apache2/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/examples/015_roles/roles/apache2/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/examples/015_roles/roles/apache2/tasks/main.yml b/examples/015_roles/roles/apache2/tasks/main.yml new file mode 100644 index 0000000..f06f2c1 --- /dev/null +++ b/examples/015_roles/roles/apache2/tasks/main.yml @@ -0,0 +1,21 @@ +# tasks file for apache2 +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + - python-pip-whl + - python3-virtualenv + - python3-mysqldb + +- name: ensure mod_wsgi enabled + apache2_module: state=present name=wsgi + notify: restart apache2 + +- name: de-activate default apache site + file: path=/etc/apache2/sites-enabled/000-default.conf state=absent + notify: restart apache2 + +- name: ensure apache2 started + service: name=apache2 state=started enabled=yes diff --git a/examples/015_roles/roles/apache2/tests/inventory b/examples/015_roles/roles/apache2/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/examples/015_roles/roles/apache2/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/examples/015_roles/roles/apache2/tests/test.yml b/examples/015_roles/roles/apache2/tests/test.yml new file mode 100644 index 0000000..7d2d6da --- /dev/null +++ b/examples/015_roles/roles/apache2/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - apache2 diff --git a/examples/015_roles/roles/apache2/vars/main.yml b/examples/015_roles/roles/apache2/vars/main.yml new file mode 100644 index 0000000..5d23ceb --- /dev/null +++ b/examples/015_roles/roles/apache2/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for apache2 diff --git a/examples/015_roles/roles/control/.travis.yml b/examples/015_roles/roles/control/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/examples/015_roles/roles/control/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file diff --git a/examples/015_roles/roles/control/README.md b/examples/015_roles/roles/control/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/015_roles/roles/control/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/015_roles/roles/control/defaults/main.yml b/examples/015_roles/roles/control/defaults/main.yml new file mode 100644 index 0000000..9fe52bd --- /dev/null +++ b/examples/015_roles/roles/control/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for control diff --git a/examples/015_roles/roles/control/handlers/main.yml b/examples/015_roles/roles/control/handlers/main.yml new file mode 100644 index 0000000..4136893 --- /dev/null +++ b/examples/015_roles/roles/control/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for control diff --git a/examples/015_roles/roles/control/meta/main.yml b/examples/015_roles/roles/control/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/examples/015_roles/roles/control/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/examples/015_roles/roles/control/tasks/main.yml b/examples/015_roles/roles/control/tasks/main.yml new file mode 100644 index 0000000..93318e3 --- /dev/null +++ b/examples/015_roles/roles/control/tasks/main.yml @@ -0,0 +1,7 @@ +# tasks file for control +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl + - python-httplib2 diff --git a/examples/015_roles/roles/control/tests/inventory b/examples/015_roles/roles/control/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/examples/015_roles/roles/control/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/examples/015_roles/roles/control/tests/test.yml b/examples/015_roles/roles/control/tests/test.yml new file mode 100644 index 0000000..1a668ab --- /dev/null +++ b/examples/015_roles/roles/control/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - control diff --git a/examples/015_roles/roles/control/vars/main.yml b/examples/015_roles/roles/control/vars/main.yml new file mode 100644 index 0000000..eadc8b6 --- /dev/null +++ b/examples/015_roles/roles/control/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for control diff --git a/examples/015_roles/roles/demo_app/.travis.yml b/examples/015_roles/roles/demo_app/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/examples/015_roles/roles/demo_app/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file diff --git a/examples/015_roles/roles/demo_app/README.md b/examples/015_roles/roles/demo_app/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/015_roles/roles/demo_app/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/015_roles/roles/demo_app/defaults/main.yml b/examples/015_roles/roles/demo_app/defaults/main.yml new file mode 100644 index 0000000..914e957 --- /dev/null +++ b/examples/015_roles/roles/demo_app/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for demo_app diff --git a/examples/015_roles/roles/demo_app/files/demo/app/demo.py b/examples/015_roles/roles/demo_app/files/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/015_roles/roles/demo_app/files/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/015_roles/roles/demo_app/files/demo/app/demo.wsgi b/examples/015_roles/roles/demo_app/files/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/015_roles/roles/demo_app/files/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/015_roles/roles/demo_app/files/demo/app/requirements.txt b/examples/015_roles/roles/demo_app/files/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/015_roles/roles/demo_app/files/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/015_roles/roles/demo_app/files/demo/demo.conf b/examples/015_roles/roles/demo_app/files/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/015_roles/roles/demo_app/files/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/015_roles/roles/demo_app/handlers/main.yml b/examples/015_roles/roles/demo_app/handlers/main.yml new file mode 100644 index 0000000..0ff1f25 --- /dev/null +++ b/examples/015_roles/roles/demo_app/handlers/main.yml @@ -0,0 +1,4 @@ +# handlers file for demo_app +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/015_roles/roles/demo_app/meta/main.yml b/examples/015_roles/roles/demo_app/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/examples/015_roles/roles/demo_app/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/examples/015_roles/roles/demo_app/tasks/main.yml b/examples/015_roles/roles/demo_app/tasks/main.yml new file mode 100644 index 0000000..e1dcc64 --- /dev/null +++ b/examples/015_roles/roles/demo_app/tasks/main.yml @@ -0,0 +1,24 @@ +# tasks file for demo_app +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - python-pip-whl + - python3-virtualenv + - python3-mysqldb + +- name: copy demo app source + copy: src=files/demo/app/ dest=/var/www/demo mode=0755 + notify: restart apache2 + +- name: copy apache virtual host config + copy: src=files/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: activate demo apache site + file: src=/etc/apache2/sites-available/demo.conf dest=/etc/apache2/sites-enabled/demo.conf state=link + notify: restart apache2 diff --git a/examples/015_roles/roles/demo_app/tests/inventory b/examples/015_roles/roles/demo_app/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/examples/015_roles/roles/demo_app/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/examples/015_roles/roles/demo_app/tests/test.yml b/examples/015_roles/roles/demo_app/tests/test.yml new file mode 100644 index 0000000..2b0cbd9 --- /dev/null +++ b/examples/015_roles/roles/demo_app/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - demo_app diff --git a/examples/015_roles/roles/demo_app/vars/main.yml b/examples/015_roles/roles/demo_app/vars/main.yml new file mode 100644 index 0000000..52fb613 --- /dev/null +++ b/examples/015_roles/roles/demo_app/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for demo_app diff --git a/examples/015_roles/roles/mysql/.travis.yml b/examples/015_roles/roles/mysql/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/examples/015_roles/roles/mysql/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file diff --git a/examples/015_roles/roles/mysql/README.md b/examples/015_roles/roles/mysql/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/015_roles/roles/mysql/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/015_roles/roles/mysql/defaults/main.yml b/examples/015_roles/roles/mysql/defaults/main.yml new file mode 100644 index 0000000..e9ebcba --- /dev/null +++ b/examples/015_roles/roles/mysql/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for mysql diff --git a/examples/015_roles/roles/mysql/handlers/main.yml b/examples/015_roles/roles/mysql/handlers/main.yml new file mode 100644 index 0000000..68cccce --- /dev/null +++ b/examples/015_roles/roles/mysql/handlers/main.yml @@ -0,0 +1,4 @@ +# handlers file for mysql +--- +- name: restart mysql + service: name=mysql state=restarted diff --git a/examples/015_roles/roles/mysql/meta/main.yml b/examples/015_roles/roles/mysql/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/examples/015_roles/roles/mysql/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/examples/015_roles/roles/mysql/tasks/main.yml b/examples/015_roles/roles/mysql/tasks/main.yml new file mode 100644 index 0000000..c6e1e59 --- /dev/null +++ b/examples/015_roles/roles/mysql/tasks/main.yml @@ -0,0 +1,25 @@ +# tasks file for mysql +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python3-mysqldb + +- name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + +- name: chmod cnf + command: chmod 777 /etc/mysql/my.cnf + +- name: ensure mysql listening on all ports + lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address line="bind-address = 0.0.0.0" + notify: restart mysql + +- name: ensure mysql started + service: name=mysql state=started enabled=yes + +- name: create demo database + mysql_db: name=demo state=present + +- name: create demo user + mysql_user: name=demo password=demo priv=demo.*:ALL host='%' state=present diff --git a/examples/015_roles/roles/mysql/tests/inventory b/examples/015_roles/roles/mysql/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/examples/015_roles/roles/mysql/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/examples/015_roles/roles/mysql/tests/test.yml b/examples/015_roles/roles/mysql/tests/test.yml new file mode 100644 index 0000000..15feaa1 --- /dev/null +++ b/examples/015_roles/roles/mysql/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - mysql diff --git a/examples/015_roles/roles/mysql/vars/main.yml b/examples/015_roles/roles/mysql/vars/main.yml new file mode 100644 index 0000000..a79bfed --- /dev/null +++ b/examples/015_roles/roles/mysql/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for mysql diff --git a/examples/015_roles/roles/nginx/.travis.yml b/examples/015_roles/roles/nginx/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/examples/015_roles/roles/nginx/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file diff --git a/examples/015_roles/roles/nginx/README.md b/examples/015_roles/roles/nginx/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/015_roles/roles/nginx/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/015_roles/roles/nginx/defaults/main.yml b/examples/015_roles/roles/nginx/defaults/main.yml new file mode 100644 index 0000000..78c8c76 --- /dev/null +++ b/examples/015_roles/roles/nginx/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for nginx diff --git a/examples/015_roles/roles/nginx/handlers/main.yml b/examples/015_roles/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..09669a2 --- /dev/null +++ b/examples/015_roles/roles/nginx/handlers/main.yml @@ -0,0 +1,4 @@ +# handlers file for nginx +--- +- name: restart nginx + service: name=nginx state=restarted diff --git a/examples/015_roles/roles/nginx/meta/main.yml b/examples/015_roles/roles/nginx/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/examples/015_roles/roles/nginx/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/examples/015_roles/roles/nginx/tasks/main.yml b/examples/015_roles/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..620a0dc --- /dev/null +++ b/examples/015_roles/roles/nginx/tasks/main.yml @@ -0,0 +1,24 @@ +# tasks file for nginx +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python-httplib2 + +- name: install nginx + apt: name=nginx state=present update_cache=yes + +- name: configure nginx site + template: src=nginx.conf.j2 dest=/etc/nginx/sites-available/demo mode=0644 + notify: restart nginx + +- name: de-activate default nginx site + file: path=/etc/nginx/sites-enabled/default state=absent + notify: restart nginx + +- name: activate demo nginx site + file: src=/etc/nginx/sites-available/demo dest=/etc/nginx/sites-enabled/demo state=link + notify: restart nginx + +- name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/015_roles/roles/nginx/templates/nginx.conf.j2 b/examples/015_roles/roles/nginx/templates/nginx.conf.j2 new file mode 100644 index 0000000..4b477b6 --- /dev/null +++ b/examples/015_roles/roles/nginx/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream demo { +{% for server in groups.webserver %} + server {{ server }}; +{% endfor %} +} + +server { + listen 80; + + location / { + proxy_pass http://demo; + } +} diff --git a/examples/015_roles/roles/nginx/tests/inventory b/examples/015_roles/roles/nginx/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/examples/015_roles/roles/nginx/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/examples/015_roles/roles/nginx/tests/test.yml b/examples/015_roles/roles/nginx/tests/test.yml new file mode 100644 index 0000000..261c779 --- /dev/null +++ b/examples/015_roles/roles/nginx/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - nginx diff --git a/examples/015_roles/roles/nginx/vars/main.yml b/examples/015_roles/roles/nginx/vars/main.yml new file mode 100644 index 0000000..d45faf6 --- /dev/null +++ b/examples/015_roles/roles/nginx/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for nginx diff --git a/examples/015_roles/roles/status/.travis.yml b/examples/015_roles/roles/status/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/examples/015_roles/roles/status/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file diff --git a/examples/015_roles/roles/status/README.md b/examples/015_roles/roles/status/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/015_roles/roles/status/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/015_roles/roles/status/defaults/main.yml b/examples/015_roles/roles/status/defaults/main.yml new file mode 100644 index 0000000..af48236 --- /dev/null +++ b/examples/015_roles/roles/status/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for status diff --git a/examples/015_roles/roles/status/handlers/main.yml b/examples/015_roles/roles/status/handlers/main.yml new file mode 100644 index 0000000..ca3a957 --- /dev/null +++ b/examples/015_roles/roles/status/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for status diff --git a/examples/015_roles/roles/status/meta/main.yml b/examples/015_roles/roles/status/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/examples/015_roles/roles/status/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/examples/015_roles/roles/status/tests/inventory b/examples/015_roles/roles/status/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/examples/015_roles/roles/status/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/examples/015_roles/roles/status/tests/test.yml b/examples/015_roles/roles/status/tests/test.yml new file mode 100644 index 0000000..e6b10b3 --- /dev/null +++ b/examples/015_roles/roles/status/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - status diff --git a/examples/015_roles/roles/status/vars/main.yml b/examples/015_roles/roles/status/vars/main.yml new file mode 100644 index 0000000..7751cdd --- /dev/null +++ b/examples/015_roles/roles/status/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for status diff --git a/examples/015_roles/site.yml b/examples/015_roles/site.yml new file mode 100644 index 0000000..f596f9f --- /dev/null +++ b/examples/015_roles/site.yml @@ -0,0 +1,88 @@ +--- +- hosts: control + become: true + roles: + - control + +- hosts: database + become: true + roles: + - mysql + +- hosts: loadbalancer + become: true + roles: + - nginx + +- hosts: webserver + become: true + roles: + - apache2 + - demo_app + +- hosts: loadbalancer + become: true + tasks: + - name: verify nginx service + command: service nginx status + + - name: verify nginx is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: webserver + become: true + tasks: + - name: verify apache2 service + command: service apache2 status + + - name: verify apache2 is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: database + become: true + tasks: + - name: verify mysql service + command: service mysql status + + - name: verify mysql is listening on 3306 + wait_for: port=3306 timeout=1 + +- hosts: control + tasks: + - name: verify end-to-end index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ 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}}" + + - name: verify end-to-end db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ 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}}" + +- hosts: loadbalancer + tasks: + - name: verify backend index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ groups.webserver }}" + register: app_index + + - fail: msg="index failed to return content" + when: "'Hello, from sunny' not in item.content" + with_items: "{{app_index.results}}" + + - name: verify backend db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ groups.webserver }}" + register: app_db + + - fail: msg="db failed to return content" + when: "'Database Connected from' not in item.content" + with_items: "{{app_db.results}}" diff --git a/examples/015_roles/stack_status.yml b/examples/015_roles/stack_status.yml new file mode 100644 index 0000000..451221d --- /dev/null +++ b/examples/015_roles/stack_status.yml @@ -0,0 +1,67 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: verify nginx service + command: service nginx status + + - name: verify nginx is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: webserver + become: true + tasks: + - name: verify apache2 service + command: service apache2 status + + - name: verify apache2 is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: database + become: true + tasks: + - name: verify mysql service + command: service mysql status + + - name: verify mysql is listening on 3306 + wait_for: port=3306 timeout=1 + +- hosts: control + tasks: + - name: verify end-to-end index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ 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}}" + + - name: verify end-to-end db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ 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}}" + +- hosts: loadbalancer + tasks: + - name: verify backend index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ groups.webserver }}" + register: app_index + + - fail: msg="index failed to return content" + when: "'Hello, from sunny' not in item.content" + with_items: "{{app_index.results}}" + + - name: verify backend db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ groups.webserver }}" + register: app_db + + - fail: msg="db failed to return content" + when: "'Database Connected from' not in item.content" + with_items: "{{app_db.results}}" diff --git a/examples/015_roles/templates/nginx.conf.j2 b/examples/015_roles/templates/nginx.conf.j2 new file mode 100644 index 0000000..4b477b6 --- /dev/null +++ b/examples/015_roles/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream demo { +{% for server in groups.webserver %} + server {{ server }}; +{% endfor %} +} + +server { + listen 80; + + location / { + proxy_pass http://demo; + } +} diff --git a/examples/016_tasks_handlers/control.yml b/examples/016_tasks_handlers/control.yml new file mode 100644 index 0000000..c6a8d81 --- /dev/null +++ b/examples/016_tasks_handlers/control.yml @@ -0,0 +1,5 @@ +--- +- hosts: control + become: true + roles: + - control diff --git a/examples/016_tasks_handlers/database.yml b/examples/016_tasks_handlers/database.yml new file mode 100644 index 0000000..e22020d --- /dev/null +++ b/examples/016_tasks_handlers/database.yml @@ -0,0 +1,5 @@ +--- +- hosts: database + become: true + roles: + - mysql diff --git a/examples/016_tasks_handlers/demo/app/demo.py b/examples/016_tasks_handlers/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/016_tasks_handlers/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/016_tasks_handlers/demo/app/demo.wsgi b/examples/016_tasks_handlers/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/016_tasks_handlers/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/016_tasks_handlers/demo/app/requirements.txt b/examples/016_tasks_handlers/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/016_tasks_handlers/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/016_tasks_handlers/demo/demo.conf b/examples/016_tasks_handlers/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/016_tasks_handlers/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/016_tasks_handlers/loadbalancer.yml b/examples/016_tasks_handlers/loadbalancer.yml new file mode 100644 index 0000000..8063643 --- /dev/null +++ b/examples/016_tasks_handlers/loadbalancer.yml @@ -0,0 +1,30 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python-httplib2 + + - name: install nginx + apt: name=nginx state=present update_cache=yes + + - name: ensure nginx started + service: name=nginx state=started enabled=yes + + - name: configure nginx site + template: src=templates/nginx.conf.j2 dest=/etc/nginx/sites-available/demo mode=0644 + notify: restart nginx + + - name: de-activate default nginx site + file: path=/etc/nginx/sites-enabled/default state=absent + notify: restart nginx + + - name: activate demo nginx site + file: src=/etc/nginx/sites-available/demo dest=/etc/nginx/sites-enabled/demo state=link + notify: restart nginx + + handlers: + - name: restart nginx + service: name=nginx state=restarted diff --git a/examples/016_tasks_handlers/playbooks/hostname.yml b/examples/016_tasks_handlers/playbooks/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/016_tasks_handlers/playbooks/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/016_tasks_handlers/playbooks/stack_restart.yml b/examples/016_tasks_handlers/playbooks/stack_restart.yml new file mode 100644 index 0000000..b55de3d --- /dev/null +++ b/examples/016_tasks_handlers/playbooks/stack_restart.yml @@ -0,0 +1,33 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + - wait_for: port=80 state=drained + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + - wait_for: port=80 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + - wait_for: port=3306 state=started + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + - wait_for: port=80 + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started + - wait_for: port=80 diff --git a/examples/016_tasks_handlers/playbooks/stack_status.yml b/examples/016_tasks_handlers/playbooks/stack_status.yml new file mode 100644 index 0000000..0676295 --- /dev/null +++ b/examples/016_tasks_handlers/playbooks/stack_status.yml @@ -0,0 +1,67 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: verify nginx service + command: service nginx status + + - name: verify nginx is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: webserver + become: true + tasks: + - name: verify apache2 service + command: service apache2 status + + - name: verify apache2 is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: database + become: true + tasks: + - name: verify mysql service + command: service mysql status + + - name: verify mysql is listening on 3306 + wait_for: port=3306 timeout=1 + +- hosts: control + tasks: + - name: verify end-to-end index response + uri: url=http://{{item}} return_content=yes + with_items: 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}}" + + - name: verify end-to-end db response + uri: url=http://{{item}}/db return_content=yes + with_items: 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}}" + +- hosts: loadbalancer + tasks: + - name: verify backend index response + uri: url=http://{{item}} return_content=yes + with_items: 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}}" + + - name: verify backend db response + uri: url=http://{{item}}/db return_content=yes + with_items: 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}}" diff --git a/examples/016_tasks_handlers/roles/apache2/README.md b/examples/016_tasks_handlers/roles/apache2/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/016_tasks_handlers/roles/apache2/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/016_tasks_handlers/roles/apache2/defaults/main.yml b/examples/016_tasks_handlers/roles/apache2/defaults/main.yml new file mode 100644 index 0000000..0381169 --- /dev/null +++ b/examples/016_tasks_handlers/roles/apache2/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for apache2 diff --git a/examples/016_tasks_handlers/roles/apache2/handlers/main.yml b/examples/016_tasks_handlers/roles/apache2/handlers/main.yml new file mode 100644 index 0000000..76add52 --- /dev/null +++ b/examples/016_tasks_handlers/roles/apache2/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for apache2 diff --git a/examples/016_tasks_handlers/roles/apache2/meta/main.yml b/examples/016_tasks_handlers/roles/apache2/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/016_tasks_handlers/roles/apache2/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/016_tasks_handlers/roles/apache2/tasks/main.yml b/examples/016_tasks_handlers/roles/apache2/tasks/main.yml new file mode 100644 index 0000000..2e2af7a --- /dev/null +++ b/examples/016_tasks_handlers/roles/apache2/tasks/main.yml @@ -0,0 +1,2 @@ +--- +# tasks file for apache2 diff --git a/examples/016_tasks_handlers/roles/apache2/vars/main.yml b/examples/016_tasks_handlers/roles/apache2/vars/main.yml new file mode 100644 index 0000000..5d23ceb --- /dev/null +++ b/examples/016_tasks_handlers/roles/apache2/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for apache2 diff --git a/examples/016_tasks_handlers/roles/control/README.md b/examples/016_tasks_handlers/roles/control/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/016_tasks_handlers/roles/control/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/016_tasks_handlers/roles/control/defaults/main.yml b/examples/016_tasks_handlers/roles/control/defaults/main.yml new file mode 100644 index 0000000..9fe52bd --- /dev/null +++ b/examples/016_tasks_handlers/roles/control/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for control diff --git a/examples/016_tasks_handlers/roles/control/handlers/main.yml b/examples/016_tasks_handlers/roles/control/handlers/main.yml new file mode 100644 index 0000000..4136893 --- /dev/null +++ b/examples/016_tasks_handlers/roles/control/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for control diff --git a/examples/016_tasks_handlers/roles/control/meta/main.yml b/examples/016_tasks_handlers/roles/control/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/016_tasks_handlers/roles/control/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/016_tasks_handlers/roles/control/tasks/main.yml b/examples/016_tasks_handlers/roles/control/tasks/main.yml new file mode 100644 index 0000000..330e91c --- /dev/null +++ b/examples/016_tasks_handlers/roles/control/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl + - python-httplib2 diff --git a/examples/016_tasks_handlers/roles/control/vars/main.yml b/examples/016_tasks_handlers/roles/control/vars/main.yml new file mode 100644 index 0000000..eadc8b6 --- /dev/null +++ b/examples/016_tasks_handlers/roles/control/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for control diff --git a/examples/016_tasks_handlers/roles/demo_app/README.md b/examples/016_tasks_handlers/roles/demo_app/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/016_tasks_handlers/roles/demo_app/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/016_tasks_handlers/roles/demo_app/defaults/main.yml b/examples/016_tasks_handlers/roles/demo_app/defaults/main.yml new file mode 100644 index 0000000..914e957 --- /dev/null +++ b/examples/016_tasks_handlers/roles/demo_app/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for demo_app diff --git a/examples/016_tasks_handlers/roles/demo_app/handlers/main.yml b/examples/016_tasks_handlers/roles/demo_app/handlers/main.yml new file mode 100644 index 0000000..c7a9311 --- /dev/null +++ b/examples/016_tasks_handlers/roles/demo_app/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for demo_app diff --git a/examples/016_tasks_handlers/roles/demo_app/meta/main.yml b/examples/016_tasks_handlers/roles/demo_app/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/016_tasks_handlers/roles/demo_app/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/016_tasks_handlers/roles/demo_app/tasks/main.yml b/examples/016_tasks_handlers/roles/demo_app/tasks/main.yml new file mode 100644 index 0000000..ede66b7 --- /dev/null +++ b/examples/016_tasks_handlers/roles/demo_app/tasks/main.yml @@ -0,0 +1,2 @@ +--- +# tasks file for demo_app diff --git a/examples/016_tasks_handlers/roles/demo_app/vars/main.yml b/examples/016_tasks_handlers/roles/demo_app/vars/main.yml new file mode 100644 index 0000000..52fb613 --- /dev/null +++ b/examples/016_tasks_handlers/roles/demo_app/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for demo_app diff --git a/examples/016_tasks_handlers/roles/mysql/README.md b/examples/016_tasks_handlers/roles/mysql/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/016_tasks_handlers/roles/mysql/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/016_tasks_handlers/roles/mysql/defaults/main.yml b/examples/016_tasks_handlers/roles/mysql/defaults/main.yml new file mode 100644 index 0000000..e9ebcba --- /dev/null +++ b/examples/016_tasks_handlers/roles/mysql/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for mysql diff --git a/examples/016_tasks_handlers/roles/mysql/handlers/main.yml b/examples/016_tasks_handlers/roles/mysql/handlers/main.yml new file mode 100644 index 0000000..3755d8c --- /dev/null +++ b/examples/016_tasks_handlers/roles/mysql/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart mysql + service: name=mysql state=restarted diff --git a/examples/016_tasks_handlers/roles/mysql/meta/main.yml b/examples/016_tasks_handlers/roles/mysql/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/016_tasks_handlers/roles/mysql/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/016_tasks_handlers/roles/mysql/tasks/main.yml b/examples/016_tasks_handlers/roles/mysql/tasks/main.yml new file mode 100644 index 0000000..db06b1c --- /dev/null +++ b/examples/016_tasks_handlers/roles/mysql/tasks/main.yml @@ -0,0 +1,21 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python3-mysqldb + +- name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + +- name: ensure mysql started + service: name=mysql state=started enabled=yes + +- name: ensure mysql listening on all ports + lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address line="bind-address = 0.0.0.0" + notify: restart mysql + +- name: create demo database + mysql_db: name=demo state=present + +- name: create demo user + mysql_user: name=demo password=demo priv=demo.*:ALL host='%' state=present diff --git a/examples/016_tasks_handlers/roles/mysql/vars/main.yml b/examples/016_tasks_handlers/roles/mysql/vars/main.yml new file mode 100644 index 0000000..a79bfed --- /dev/null +++ b/examples/016_tasks_handlers/roles/mysql/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for mysql diff --git a/examples/016_tasks_handlers/roles/nginx/README.md b/examples/016_tasks_handlers/roles/nginx/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/016_tasks_handlers/roles/nginx/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/016_tasks_handlers/roles/nginx/defaults/main.yml b/examples/016_tasks_handlers/roles/nginx/defaults/main.yml new file mode 100644 index 0000000..78c8c76 --- /dev/null +++ b/examples/016_tasks_handlers/roles/nginx/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for nginx diff --git a/examples/016_tasks_handlers/roles/nginx/handlers/main.yml b/examples/016_tasks_handlers/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..ad79151 --- /dev/null +++ b/examples/016_tasks_handlers/roles/nginx/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for nginx diff --git a/examples/016_tasks_handlers/roles/nginx/meta/main.yml b/examples/016_tasks_handlers/roles/nginx/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/016_tasks_handlers/roles/nginx/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/016_tasks_handlers/roles/nginx/tasks/main.yml b/examples/016_tasks_handlers/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..7034178 --- /dev/null +++ b/examples/016_tasks_handlers/roles/nginx/tasks/main.yml @@ -0,0 +1,2 @@ +--- +# tasks file for nginx diff --git a/examples/016_tasks_handlers/roles/nginx/vars/main.yml b/examples/016_tasks_handlers/roles/nginx/vars/main.yml new file mode 100644 index 0000000..d45faf6 --- /dev/null +++ b/examples/016_tasks_handlers/roles/nginx/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for nginx diff --git a/examples/016_tasks_handlers/templates/nginx.conf.j2 b/examples/016_tasks_handlers/templates/nginx.conf.j2 new file mode 100644 index 0000000..4b477b6 --- /dev/null +++ b/examples/016_tasks_handlers/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream demo { +{% for server in groups.webserver %} + server {{ server }}; +{% endfor %} +} + +server { + listen 80; + + location / { + proxy_pass http://demo; + } +} diff --git a/examples/016_tasks_handlers/webserver.yml b/examples/016_tasks_handlers/webserver.yml new file mode 100644 index 0000000..1417614 --- /dev/null +++ b/examples/016_tasks_handlers/webserver.yml @@ -0,0 +1,43 @@ +--- +- 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 + + - 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 diff --git a/examples/017_files_templates/control.yml b/examples/017_files_templates/control.yml new file mode 100644 index 0000000..c6a8d81 --- /dev/null +++ b/examples/017_files_templates/control.yml @@ -0,0 +1,5 @@ +--- +- hosts: control + become: true + roles: + - control diff --git a/examples/017_files_templates/database.yml b/examples/017_files_templates/database.yml new file mode 100644 index 0000000..e22020d --- /dev/null +++ b/examples/017_files_templates/database.yml @@ -0,0 +1,5 @@ +--- +- hosts: database + become: true + roles: + - mysql diff --git a/examples/017_files_templates/demo/app/demo.py b/examples/017_files_templates/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/017_files_templates/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/017_files_templates/demo/app/demo.wsgi b/examples/017_files_templates/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/017_files_templates/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/017_files_templates/demo/app/requirements.txt b/examples/017_files_templates/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/017_files_templates/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/017_files_templates/demo/demo.conf b/examples/017_files_templates/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/017_files_templates/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/017_files_templates/loadbalancer.yml b/examples/017_files_templates/loadbalancer.yml new file mode 100644 index 0000000..651bc7d --- /dev/null +++ b/examples/017_files_templates/loadbalancer.yml @@ -0,0 +1,5 @@ +--- +- hosts: loadbalancer + become: true + roles: + - nginx diff --git a/examples/017_files_templates/playbooks/hostname.yml b/examples/017_files_templates/playbooks/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/017_files_templates/playbooks/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/017_files_templates/playbooks/stack_restart.yml b/examples/017_files_templates/playbooks/stack_restart.yml new file mode 100644 index 0000000..b55de3d --- /dev/null +++ b/examples/017_files_templates/playbooks/stack_restart.yml @@ -0,0 +1,33 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + - wait_for: port=80 state=drained + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + - wait_for: port=80 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + - wait_for: port=3306 state=started + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + - wait_for: port=80 + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started + - wait_for: port=80 diff --git a/examples/017_files_templates/playbooks/stack_status.yml b/examples/017_files_templates/playbooks/stack_status.yml new file mode 100644 index 0000000..0676295 --- /dev/null +++ b/examples/017_files_templates/playbooks/stack_status.yml @@ -0,0 +1,67 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: verify nginx service + command: service nginx status + + - name: verify nginx is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: webserver + become: true + tasks: + - name: verify apache2 service + command: service apache2 status + + - name: verify apache2 is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: database + become: true + tasks: + - name: verify mysql service + command: service mysql status + + - name: verify mysql is listening on 3306 + wait_for: port=3306 timeout=1 + +- hosts: control + tasks: + - name: verify end-to-end index response + uri: url=http://{{item}} return_content=yes + with_items: 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}}" + + - name: verify end-to-end db response + uri: url=http://{{item}}/db return_content=yes + with_items: 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}}" + +- hosts: loadbalancer + tasks: + - name: verify backend index response + uri: url=http://{{item}} return_content=yes + with_items: 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}}" + + - name: verify backend db response + uri: url=http://{{item}}/db return_content=yes + with_items: 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}}" diff --git a/examples/017_files_templates/roles/apache2/README.md b/examples/017_files_templates/roles/apache2/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/017_files_templates/roles/apache2/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/017_files_templates/roles/apache2/defaults/main.yml b/examples/017_files_templates/roles/apache2/defaults/main.yml new file mode 100644 index 0000000..0381169 --- /dev/null +++ b/examples/017_files_templates/roles/apache2/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for apache2 diff --git a/examples/017_files_templates/roles/apache2/handlers/main.yml b/examples/017_files_templates/roles/apache2/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/017_files_templates/roles/apache2/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/017_files_templates/roles/apache2/meta/main.yml b/examples/017_files_templates/roles/apache2/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/017_files_templates/roles/apache2/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/017_files_templates/roles/apache2/tasks/main.yml b/examples/017_files_templates/roles/apache2/tasks/main.yml new file mode 100644 index 0000000..2d0632f --- /dev/null +++ b/examples/017_files_templates/roles/apache2/tasks/main.yml @@ -0,0 +1,17 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi + +- name: ensure mod_wsgi enabled + apache2_module: state=present name=wsgi + notify: restart apache2 + +- name: de-activate default apache site + file: path=/etc/apache2/sites-enabled/000-default.conf state=absent + notify: restart apache2 + +- name: ensure apache2 started + service: name=apache2 state=started enabled=yes diff --git a/examples/017_files_templates/roles/apache2/vars/main.yml b/examples/017_files_templates/roles/apache2/vars/main.yml new file mode 100644 index 0000000..5d23ceb --- /dev/null +++ b/examples/017_files_templates/roles/apache2/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for apache2 diff --git a/examples/017_files_templates/roles/control/README.md b/examples/017_files_templates/roles/control/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/017_files_templates/roles/control/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/017_files_templates/roles/control/defaults/main.yml b/examples/017_files_templates/roles/control/defaults/main.yml new file mode 100644 index 0000000..9fe52bd --- /dev/null +++ b/examples/017_files_templates/roles/control/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for control diff --git a/examples/017_files_templates/roles/control/handlers/main.yml b/examples/017_files_templates/roles/control/handlers/main.yml new file mode 100644 index 0000000..4136893 --- /dev/null +++ b/examples/017_files_templates/roles/control/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for control diff --git a/examples/017_files_templates/roles/control/meta/main.yml b/examples/017_files_templates/roles/control/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/017_files_templates/roles/control/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/017_files_templates/roles/control/tasks/main.yml b/examples/017_files_templates/roles/control/tasks/main.yml new file mode 100644 index 0000000..330e91c --- /dev/null +++ b/examples/017_files_templates/roles/control/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl + - python-httplib2 diff --git a/examples/017_files_templates/roles/control/vars/main.yml b/examples/017_files_templates/roles/control/vars/main.yml new file mode 100644 index 0000000..eadc8b6 --- /dev/null +++ b/examples/017_files_templates/roles/control/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for control diff --git a/examples/017_files_templates/roles/demo_app/README.md b/examples/017_files_templates/roles/demo_app/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/017_files_templates/roles/demo_app/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/017_files_templates/roles/demo_app/defaults/main.yml b/examples/017_files_templates/roles/demo_app/defaults/main.yml new file mode 100644 index 0000000..914e957 --- /dev/null +++ b/examples/017_files_templates/roles/demo_app/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for demo_app diff --git a/examples/017_files_templates/roles/demo_app/files/demo/app/demo.py b/examples/017_files_templates/roles/demo_app/files/demo/app/demo.py new file mode 100644 index 0000000..f7897f0 --- /dev/null +++ b/examples/017_files_templates/roles/demo_app/files/demo/app/demo.py @@ -0,0 +1,23 @@ +from flask import Flask +from flask.ext.sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + try: + db.create_all() + except Exception as e: + return e.message + '\n' + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() diff --git a/examples/017_files_templates/roles/demo_app/files/demo/app/demo.wsgi b/examples/017_files_templates/roles/demo_app/files/demo/app/demo.wsgi new file mode 100644 index 0000000..f6453b3 --- /dev/null +++ b/examples/017_files_templates/roles/demo_app/files/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +execfile(activate_this, dict(__file__=activate_this)) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application diff --git a/examples/017_files_templates/roles/demo_app/files/demo/app/requirements.txt b/examples/017_files_templates/roles/demo_app/files/demo/app/requirements.txt new file mode 100644 index 0000000..451ff90 --- /dev/null +++ b/examples/017_files_templates/roles/demo_app/files/demo/app/requirements.txt @@ -0,0 +1,2 @@ +Flask==0.10.1 +Flask-SQLAlchemy==2.0 diff --git a/examples/017_files_templates/roles/demo_app/files/demo/demo.conf b/examples/017_files_templates/roles/demo_app/files/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/017_files_templates/roles/demo_app/files/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/017_files_templates/roles/demo_app/handlers/main.yml b/examples/017_files_templates/roles/demo_app/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/017_files_templates/roles/demo_app/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/017_files_templates/roles/demo_app/meta/main.yml b/examples/017_files_templates/roles/demo_app/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/017_files_templates/roles/demo_app/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/017_files_templates/roles/demo_app/tasks/main.yml b/examples/017_files_templates/roles/demo_app/tasks/main.yml new file mode 100644 index 0000000..05ff043 --- /dev/null +++ b/examples/017_files_templates/roles/demo_app/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - python-pip + - python-virtualenv + - python-mysqldb + +- 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: activate demo apache site + file: src=/etc/apache2/sites-available/demo.conf dest=/etc/apache2/sites-enabled/demo.conf state=link + notify: restart apache2 diff --git a/examples/017_files_templates/roles/demo_app/vars/main.yml b/examples/017_files_templates/roles/demo_app/vars/main.yml new file mode 100644 index 0000000..52fb613 --- /dev/null +++ b/examples/017_files_templates/roles/demo_app/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for demo_app diff --git a/examples/017_files_templates/roles/mysql/README.md b/examples/017_files_templates/roles/mysql/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/017_files_templates/roles/mysql/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/017_files_templates/roles/mysql/defaults/main.yml b/examples/017_files_templates/roles/mysql/defaults/main.yml new file mode 100644 index 0000000..e9ebcba --- /dev/null +++ b/examples/017_files_templates/roles/mysql/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for mysql diff --git a/examples/017_files_templates/roles/mysql/handlers/main.yml b/examples/017_files_templates/roles/mysql/handlers/main.yml new file mode 100644 index 0000000..3755d8c --- /dev/null +++ b/examples/017_files_templates/roles/mysql/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart mysql + service: name=mysql state=restarted diff --git a/examples/017_files_templates/roles/mysql/meta/main.yml b/examples/017_files_templates/roles/mysql/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/017_files_templates/roles/mysql/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/017_files_templates/roles/mysql/tasks/main.yml b/examples/017_files_templates/roles/mysql/tasks/main.yml new file mode 100644 index 0000000..af8cdcd --- /dev/null +++ b/examples/017_files_templates/roles/mysql/tasks/main.yml @@ -0,0 +1,21 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python-mysqldb + +- name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + +- name: ensure mysql listening on all ports + lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address line="bind-address = 0.0.0.0" + notify: restart mysql + +- name: ensure mysql started + service: name=mysql state=started enabled=yes + +- name: create demo database + mysql_db: name=demo state=present + +- name: create demo user + mysql_user: name=demo password=demo priv=demo.*:ALL host='%' state=present diff --git a/examples/017_files_templates/roles/mysql/vars/main.yml b/examples/017_files_templates/roles/mysql/vars/main.yml new file mode 100644 index 0000000..a79bfed --- /dev/null +++ b/examples/017_files_templates/roles/mysql/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for mysql diff --git a/examples/017_files_templates/roles/nginx/README.md b/examples/017_files_templates/roles/nginx/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/017_files_templates/roles/nginx/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/017_files_templates/roles/nginx/defaults/main.yml b/examples/017_files_templates/roles/nginx/defaults/main.yml new file mode 100644 index 0000000..78c8c76 --- /dev/null +++ b/examples/017_files_templates/roles/nginx/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for nginx diff --git a/examples/017_files_templates/roles/nginx/handlers/main.yml b/examples/017_files_templates/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..92971d2 --- /dev/null +++ b/examples/017_files_templates/roles/nginx/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart nginx + service: name=nginx state=restarted diff --git a/examples/017_files_templates/roles/nginx/meta/main.yml b/examples/017_files_templates/roles/nginx/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/017_files_templates/roles/nginx/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/017_files_templates/roles/nginx/tasks/main.yml b/examples/017_files_templates/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..69c6461 --- /dev/null +++ b/examples/017_files_templates/roles/nginx/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python-httplib2 + +- name: install nginx + apt: name=nginx state=present update_cache=yes + +- name: configure nginx site + template: src=nginx.conf.j2 dest=/etc/nginx/sites-available/demo mode=0644 + notify: restart nginx + +- name: de-activate default nginx site + file: path=/etc/nginx/sites-enabled/default state=absent + notify: restart nginx + +- name: activate demo nginx site + file: src=/etc/nginx/sites-available/demo dest=/etc/nginx/sites-enabled/demo state=link + notify: restart nginx + +- name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/017_files_templates/roles/nginx/templates/nginx.conf.j2 b/examples/017_files_templates/roles/nginx/templates/nginx.conf.j2 new file mode 100644 index 0000000..4b477b6 --- /dev/null +++ b/examples/017_files_templates/roles/nginx/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream demo { +{% for server in groups.webserver %} + server {{ server }}; +{% endfor %} +} + +server { + listen 80; + + location / { + proxy_pass http://demo; + } +} diff --git a/examples/017_files_templates/roles/nginx/vars/main.yml b/examples/017_files_templates/roles/nginx/vars/main.yml new file mode 100644 index 0000000..d45faf6 --- /dev/null +++ b/examples/017_files_templates/roles/nginx/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for nginx diff --git a/examples/017_files_templates/webserver.yml b/examples/017_files_templates/webserver.yml new file mode 100644 index 0000000..195ec7f --- /dev/null +++ b/examples/017_files_templates/webserver.yml @@ -0,0 +1,6 @@ +--- +- hosts: webserver + become: true + roles: + - apache2 + - demo_app diff --git a/examples/018_site_yml/control.yml b/examples/018_site_yml/control.yml new file mode 100644 index 0000000..c6a8d81 --- /dev/null +++ b/examples/018_site_yml/control.yml @@ -0,0 +1,5 @@ +--- +- hosts: control + become: true + roles: + - control diff --git a/examples/018_site_yml/database.yml b/examples/018_site_yml/database.yml new file mode 100644 index 0000000..e22020d --- /dev/null +++ b/examples/018_site_yml/database.yml @@ -0,0 +1,5 @@ +--- +- hosts: database + become: true + roles: + - mysql diff --git a/examples/018_site_yml/demo/app/demo.py b/examples/018_site_yml/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/018_site_yml/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/018_site_yml/demo/app/demo.wsgi b/examples/018_site_yml/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/018_site_yml/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/018_site_yml/demo/app/requirements.txt b/examples/018_site_yml/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/018_site_yml/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/018_site_yml/demo/demo.conf b/examples/018_site_yml/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/018_site_yml/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/018_site_yml/loadbalancer.yml b/examples/018_site_yml/loadbalancer.yml new file mode 100644 index 0000000..63f0c1a --- /dev/null +++ b/examples/018_site_yml/loadbalancer.yml @@ -0,0 +1,28 @@ +--- +- hosts: loadbalancer + become: true + roles: + - nginx + - haproxy + - keepalived + vars: + nginx_http_port: 80 + nginx_https_port: 443 + nginx_http2: true + nginx_ssl_certificate: "/etc/ssl/certs/ssl-cert-snakeoil.pem" + nginx_ssl_certificate_key: "/etc/ssl/private/ssl-cert-snakeoil.key" + haproxy_frontend_port: 80 + haproxy_backend_servers: + - { name: "web1", address: "0.0.0.0", port: 80 } + keepalived_vrrp_id: 51 + keepalived_vrrp_priority: 100 + keepalived_vrrp_auth_pass: "password" + keepalived_vrrp_virtual_ip: "" # Set this to the virtual IP you want to use + keepalived_vrrp_state: "MASTER" # Set to "BACKUP" for the secondary load balancer + keepalived_vrrp_interface: "eth0" # Change to your network interface + keepalived_vrrp_virtual_router_id: 51 # Must match the ID used by the other load balancer + keepalived_vrrp_unicast_peer: [] # Add IPs of other load balancers if needed + keepalived_vrrp_unicast_src_ip: "" # Set to the source IP for unicast communication + keepalived_vrrp_track_script: "check_haproxy" + keepalived_vrrp_script_name: "check_haproxy" + diff --git a/examples/018_site_yml/playbooks/hostname.yml b/examples/018_site_yml/playbooks/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/018_site_yml/playbooks/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/018_site_yml/playbooks/stack_restart.yml b/examples/018_site_yml/playbooks/stack_restart.yml new file mode 100644 index 0000000..b55de3d --- /dev/null +++ b/examples/018_site_yml/playbooks/stack_restart.yml @@ -0,0 +1,33 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + - wait_for: port=80 state=drained + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + - wait_for: port=80 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + - wait_for: port=3306 state=started + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + - wait_for: port=80 + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started + - wait_for: port=80 diff --git a/examples/018_site_yml/playbooks/stack_status.yml b/examples/018_site_yml/playbooks/stack_status.yml new file mode 100644 index 0000000..0676295 --- /dev/null +++ b/examples/018_site_yml/playbooks/stack_status.yml @@ -0,0 +1,67 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: verify nginx service + command: service nginx status + + - name: verify nginx is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: webserver + become: true + tasks: + - name: verify apache2 service + command: service apache2 status + + - name: verify apache2 is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: database + become: true + tasks: + - name: verify mysql service + command: service mysql status + + - name: verify mysql is listening on 3306 + wait_for: port=3306 timeout=1 + +- hosts: control + tasks: + - name: verify end-to-end index response + uri: url=http://{{item}} return_content=yes + with_items: 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}}" + + - name: verify end-to-end db response + uri: url=http://{{item}}/db return_content=yes + with_items: 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}}" + +- hosts: loadbalancer + tasks: + - name: verify backend index response + uri: url=http://{{item}} return_content=yes + with_items: 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}}" + + - name: verify backend db response + uri: url=http://{{item}}/db return_content=yes + with_items: 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}}" diff --git a/examples/018_site_yml/roles/apache2/README.md b/examples/018_site_yml/roles/apache2/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/018_site_yml/roles/apache2/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/018_site_yml/roles/apache2/defaults/main.yml b/examples/018_site_yml/roles/apache2/defaults/main.yml new file mode 100644 index 0000000..0381169 --- /dev/null +++ b/examples/018_site_yml/roles/apache2/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for apache2 diff --git a/examples/018_site_yml/roles/apache2/handlers/main.yml b/examples/018_site_yml/roles/apache2/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/018_site_yml/roles/apache2/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/018_site_yml/roles/apache2/meta/main.yml b/examples/018_site_yml/roles/apache2/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/018_site_yml/roles/apache2/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/018_site_yml/roles/apache2/tasks/main.yml b/examples/018_site_yml/roles/apache2/tasks/main.yml new file mode 100644 index 0000000..2d0632f --- /dev/null +++ b/examples/018_site_yml/roles/apache2/tasks/main.yml @@ -0,0 +1,17 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi + +- name: ensure mod_wsgi enabled + apache2_module: state=present name=wsgi + notify: restart apache2 + +- name: de-activate default apache site + file: path=/etc/apache2/sites-enabled/000-default.conf state=absent + notify: restart apache2 + +- name: ensure apache2 started + service: name=apache2 state=started enabled=yes diff --git a/examples/018_site_yml/roles/apache2/vars/main.yml b/examples/018_site_yml/roles/apache2/vars/main.yml new file mode 100644 index 0000000..5d23ceb --- /dev/null +++ b/examples/018_site_yml/roles/apache2/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for apache2 diff --git a/examples/018_site_yml/roles/control/README.md b/examples/018_site_yml/roles/control/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/018_site_yml/roles/control/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/018_site_yml/roles/control/defaults/main.yml b/examples/018_site_yml/roles/control/defaults/main.yml new file mode 100644 index 0000000..9fe52bd --- /dev/null +++ b/examples/018_site_yml/roles/control/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for control diff --git a/examples/018_site_yml/roles/control/handlers/main.yml b/examples/018_site_yml/roles/control/handlers/main.yml new file mode 100644 index 0000000..4136893 --- /dev/null +++ b/examples/018_site_yml/roles/control/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for control diff --git a/examples/018_site_yml/roles/control/meta/main.yml b/examples/018_site_yml/roles/control/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/018_site_yml/roles/control/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/018_site_yml/roles/control/tasks/main.yml b/examples/018_site_yml/roles/control/tasks/main.yml new file mode 100644 index 0000000..330e91c --- /dev/null +++ b/examples/018_site_yml/roles/control/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl + - python-httplib2 diff --git a/examples/018_site_yml/roles/control/vars/main.yml b/examples/018_site_yml/roles/control/vars/main.yml new file mode 100644 index 0000000..eadc8b6 --- /dev/null +++ b/examples/018_site_yml/roles/control/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for control diff --git a/examples/018_site_yml/roles/demo_app/README.md b/examples/018_site_yml/roles/demo_app/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/018_site_yml/roles/demo_app/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/018_site_yml/roles/demo_app/defaults/main.yml b/examples/018_site_yml/roles/demo_app/defaults/main.yml new file mode 100644 index 0000000..914e957 --- /dev/null +++ b/examples/018_site_yml/roles/demo_app/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for demo_app diff --git a/examples/018_site_yml/roles/demo_app/files/demo/app/demo.py b/examples/018_site_yml/roles/demo_app/files/demo/app/demo.py new file mode 100644 index 0000000..f7897f0 --- /dev/null +++ b/examples/018_site_yml/roles/demo_app/files/demo/app/demo.py @@ -0,0 +1,23 @@ +from flask import Flask +from flask.ext.sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + try: + db.create_all() + except Exception as e: + return e.message + '\n' + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() diff --git a/examples/018_site_yml/roles/demo_app/files/demo/app/demo.wsgi b/examples/018_site_yml/roles/demo_app/files/demo/app/demo.wsgi new file mode 100644 index 0000000..f6453b3 --- /dev/null +++ b/examples/018_site_yml/roles/demo_app/files/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +execfile(activate_this, dict(__file__=activate_this)) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application diff --git a/examples/018_site_yml/roles/demo_app/files/demo/app/requirements.txt b/examples/018_site_yml/roles/demo_app/files/demo/app/requirements.txt new file mode 100644 index 0000000..451ff90 --- /dev/null +++ b/examples/018_site_yml/roles/demo_app/files/demo/app/requirements.txt @@ -0,0 +1,2 @@ +Flask==0.10.1 +Flask-SQLAlchemy==2.0 diff --git a/examples/018_site_yml/roles/demo_app/files/demo/demo.conf b/examples/018_site_yml/roles/demo_app/files/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/018_site_yml/roles/demo_app/files/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/018_site_yml/roles/demo_app/handlers/main.yml b/examples/018_site_yml/roles/demo_app/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/018_site_yml/roles/demo_app/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/018_site_yml/roles/demo_app/meta/main.yml b/examples/018_site_yml/roles/demo_app/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/018_site_yml/roles/demo_app/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/018_site_yml/roles/demo_app/tasks/main.yml b/examples/018_site_yml/roles/demo_app/tasks/main.yml new file mode 100644 index 0000000..c5e1f3a --- /dev/null +++ b/examples/018_site_yml/roles/demo_app/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - python-pip-whl + - python3-virtualenv + - python3-mysqldb + +- 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: activate demo apache site + file: src=/etc/apache2/sites-available/demo.conf dest=/etc/apache2/sites-enabled/demo.conf state=link + notify: restart apache2 diff --git a/examples/018_site_yml/roles/demo_app/vars/main.yml b/examples/018_site_yml/roles/demo_app/vars/main.yml new file mode 100644 index 0000000..52fb613 --- /dev/null +++ b/examples/018_site_yml/roles/demo_app/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for demo_app diff --git a/examples/018_site_yml/roles/mysql/README.md b/examples/018_site_yml/roles/mysql/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/018_site_yml/roles/mysql/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/018_site_yml/roles/mysql/defaults/main.yml b/examples/018_site_yml/roles/mysql/defaults/main.yml new file mode 100644 index 0000000..e9ebcba --- /dev/null +++ b/examples/018_site_yml/roles/mysql/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for mysql diff --git a/examples/018_site_yml/roles/mysql/handlers/main.yml b/examples/018_site_yml/roles/mysql/handlers/main.yml new file mode 100644 index 0000000..3755d8c --- /dev/null +++ b/examples/018_site_yml/roles/mysql/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart mysql + service: name=mysql state=restarted diff --git a/examples/018_site_yml/roles/mysql/meta/main.yml b/examples/018_site_yml/roles/mysql/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/018_site_yml/roles/mysql/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/018_site_yml/roles/mysql/tasks/main.yml b/examples/018_site_yml/roles/mysql/tasks/main.yml new file mode 100644 index 0000000..b5990b7 --- /dev/null +++ b/examples/018_site_yml/roles/mysql/tasks/main.yml @@ -0,0 +1,21 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python3-mysqldb + +- name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + +- name: ensure mysql listening on all ports + lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address line="bind-address = 0.0.0.0" + notify: restart mysql + +- name: ensure mysql started + service: name=mysql state=started enabled=yes + +- name: create demo database + mysql_db: name=demo state=present + +- name: create demo user + mysql_user: name=demo password=demo priv=demo.*:ALL host='%' state=present diff --git a/examples/018_site_yml/roles/mysql/vars/main.yml b/examples/018_site_yml/roles/mysql/vars/main.yml new file mode 100644 index 0000000..a79bfed --- /dev/null +++ b/examples/018_site_yml/roles/mysql/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for mysql diff --git a/examples/018_site_yml/roles/nginx/README.md b/examples/018_site_yml/roles/nginx/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/018_site_yml/roles/nginx/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/018_site_yml/roles/nginx/defaults/main.yml b/examples/018_site_yml/roles/nginx/defaults/main.yml new file mode 100644 index 0000000..78c8c76 --- /dev/null +++ b/examples/018_site_yml/roles/nginx/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for nginx diff --git a/examples/018_site_yml/roles/nginx/handlers/main.yml b/examples/018_site_yml/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..92971d2 --- /dev/null +++ b/examples/018_site_yml/roles/nginx/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart nginx + service: name=nginx state=restarted diff --git a/examples/018_site_yml/roles/nginx/meta/main.yml b/examples/018_site_yml/roles/nginx/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/018_site_yml/roles/nginx/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/018_site_yml/roles/nginx/tasks/main.yml b/examples/018_site_yml/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..69c6461 --- /dev/null +++ b/examples/018_site_yml/roles/nginx/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python-httplib2 + +- name: install nginx + apt: name=nginx state=present update_cache=yes + +- name: configure nginx site + template: src=nginx.conf.j2 dest=/etc/nginx/sites-available/demo mode=0644 + notify: restart nginx + +- name: de-activate default nginx site + file: path=/etc/nginx/sites-enabled/default state=absent + notify: restart nginx + +- name: activate demo nginx site + file: src=/etc/nginx/sites-available/demo dest=/etc/nginx/sites-enabled/demo state=link + notify: restart nginx + +- name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/018_site_yml/roles/nginx/templates/nginx.conf.j2 b/examples/018_site_yml/roles/nginx/templates/nginx.conf.j2 new file mode 100644 index 0000000..4b477b6 --- /dev/null +++ b/examples/018_site_yml/roles/nginx/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream demo { +{% for server in groups.webserver %} + server {{ server }}; +{% endfor %} +} + +server { + listen 80; + + location / { + proxy_pass http://demo; + } +} diff --git a/examples/018_site_yml/roles/nginx/vars/main.yml b/examples/018_site_yml/roles/nginx/vars/main.yml new file mode 100644 index 0000000..d45faf6 --- /dev/null +++ b/examples/018_site_yml/roles/nginx/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for nginx diff --git a/examples/018_site_yml/site.yml b/examples/018_site_yml/site.yml new file mode 100644 index 0000000..0cb3dd0 --- /dev/null +++ b/examples/018_site_yml/site.yml @@ -0,0 +1,5 @@ +--- +- include: control.yml +- include: database.yml +- include: webserver.yml +- include: loadbalancer.yml diff --git a/examples/018_site_yml/webserver.yml b/examples/018_site_yml/webserver.yml new file mode 100644 index 0000000..195ec7f --- /dev/null +++ b/examples/018_site_yml/webserver.yml @@ -0,0 +1,6 @@ +--- +- hosts: webserver + become: true + roles: + - apache2 + - demo_app diff --git a/examples/019_facts/control.yml b/examples/019_facts/control.yml new file mode 100644 index 0000000..c6a8d81 --- /dev/null +++ b/examples/019_facts/control.yml @@ -0,0 +1,5 @@ +--- +- hosts: control + become: true + roles: + - control diff --git a/examples/019_facts/database.yml b/examples/019_facts/database.yml new file mode 100644 index 0000000..e22020d --- /dev/null +++ b/examples/019_facts/database.yml @@ -0,0 +1,5 @@ +--- +- hosts: database + become: true + roles: + - mysql diff --git a/examples/019_facts/demo/app/demo.py b/examples/019_facts/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/019_facts/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/019_facts/demo/app/demo.wsgi b/examples/019_facts/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/019_facts/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/019_facts/demo/app/requirements.txt b/examples/019_facts/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/019_facts/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/019_facts/demo/demo.conf b/examples/019_facts/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/019_facts/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/019_facts/loadbalancer.yml b/examples/019_facts/loadbalancer.yml new file mode 100644 index 0000000..651bc7d --- /dev/null +++ b/examples/019_facts/loadbalancer.yml @@ -0,0 +1,5 @@ +--- +- hosts: loadbalancer + become: true + roles: + - nginx diff --git a/examples/019_facts/playbooks/hostname.yml b/examples/019_facts/playbooks/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/019_facts/playbooks/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/019_facts/playbooks/stack_restart.yml b/examples/019_facts/playbooks/stack_restart.yml new file mode 100644 index 0000000..d89c326 --- /dev/null +++ b/examples/019_facts/playbooks/stack_restart.yml @@ -0,0 +1,33 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + - wait_for: port=80 state=drained + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + - wait_for: port=80 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + - wait_for: host={{ ansible_eth0.ipv4.address }} port=3306 state=started + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + - wait_for: port=80 + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started + - wait_for: port=80 diff --git a/examples/019_facts/playbooks/stack_status.yml b/examples/019_facts/playbooks/stack_status.yml new file mode 100644 index 0000000..9c8be07 --- /dev/null +++ b/examples/019_facts/playbooks/stack_status.yml @@ -0,0 +1,67 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: verify nginx service + command: service nginx status + + - name: verify nginx is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: webserver + become: true + tasks: + - name: verify apache2 service + command: service apache2 status + + - name: verify apache2 is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: database + become: true + tasks: + - name: verify mysql service + command: service mysql status + + - name: verify mysql is listening on 3306 + wait_for: host={{ ansible_eth0.ipv4.address }} port=3306 timeout=1 + +- hosts: control + tasks: + - name: verify end-to-end index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ 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}}" + + - name: verify end-to-end db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ 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}}" + +- hosts: loadbalancer + tasks: + - name: verify backend index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ groups.webserver }}" + register: app_index + + - fail: msg="index failed to return content" + when: "'Hello, from sunny' not in item.content" + with_items: "{{app_index.results}}" + + - name: verify backend db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ groups.webserver }}" + register: app_db + + - fail: msg="db failed to return content" + when: "'Database Connected' not in item.content" + with_items: "{{app_db.results}}" diff --git a/examples/019_facts/roles/apache2/README.md b/examples/019_facts/roles/apache2/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/019_facts/roles/apache2/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/019_facts/roles/apache2/defaults/main.yml b/examples/019_facts/roles/apache2/defaults/main.yml new file mode 100644 index 0000000..0381169 --- /dev/null +++ b/examples/019_facts/roles/apache2/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for apache2 diff --git a/examples/019_facts/roles/apache2/handlers/main.yml b/examples/019_facts/roles/apache2/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/019_facts/roles/apache2/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/019_facts/roles/apache2/meta/main.yml b/examples/019_facts/roles/apache2/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/019_facts/roles/apache2/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/019_facts/roles/apache2/tasks/main.yml b/examples/019_facts/roles/apache2/tasks/main.yml new file mode 100644 index 0000000..2d0632f --- /dev/null +++ b/examples/019_facts/roles/apache2/tasks/main.yml @@ -0,0 +1,17 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi + +- name: ensure mod_wsgi enabled + apache2_module: state=present name=wsgi + notify: restart apache2 + +- name: de-activate default apache site + file: path=/etc/apache2/sites-enabled/000-default.conf state=absent + notify: restart apache2 + +- name: ensure apache2 started + service: name=apache2 state=started enabled=yes diff --git a/examples/019_facts/roles/apache2/vars/main.yml b/examples/019_facts/roles/apache2/vars/main.yml new file mode 100644 index 0000000..5d23ceb --- /dev/null +++ b/examples/019_facts/roles/apache2/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for apache2 diff --git a/examples/019_facts/roles/control/README.md b/examples/019_facts/roles/control/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/019_facts/roles/control/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/019_facts/roles/control/defaults/main.yml b/examples/019_facts/roles/control/defaults/main.yml new file mode 100644 index 0000000..9fe52bd --- /dev/null +++ b/examples/019_facts/roles/control/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for control diff --git a/examples/019_facts/roles/control/handlers/main.yml b/examples/019_facts/roles/control/handlers/main.yml new file mode 100644 index 0000000..4136893 --- /dev/null +++ b/examples/019_facts/roles/control/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for control diff --git a/examples/019_facts/roles/control/meta/main.yml b/examples/019_facts/roles/control/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/019_facts/roles/control/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/019_facts/roles/control/tasks/main.yml b/examples/019_facts/roles/control/tasks/main.yml new file mode 100644 index 0000000..330e91c --- /dev/null +++ b/examples/019_facts/roles/control/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl + - python-httplib2 diff --git a/examples/019_facts/roles/control/vars/main.yml b/examples/019_facts/roles/control/vars/main.yml new file mode 100644 index 0000000..eadc8b6 --- /dev/null +++ b/examples/019_facts/roles/control/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for control diff --git a/examples/019_facts/roles/demo_app/README.md b/examples/019_facts/roles/demo_app/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/019_facts/roles/demo_app/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/019_facts/roles/demo_app/defaults/main.yml b/examples/019_facts/roles/demo_app/defaults/main.yml new file mode 100644 index 0000000..914e957 --- /dev/null +++ b/examples/019_facts/roles/demo_app/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for demo_app diff --git a/examples/019_facts/roles/demo_app/files/demo/app/demo.py b/examples/019_facts/roles/demo_app/files/demo/app/demo.py new file mode 100644 index 0000000..f7897f0 --- /dev/null +++ b/examples/019_facts/roles/demo_app/files/demo/app/demo.py @@ -0,0 +1,23 @@ +from flask import Flask +from flask.ext.sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + try: + db.create_all() + except Exception as e: + return e.message + '\n' + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() diff --git a/examples/019_facts/roles/demo_app/files/demo/app/demo.wsgi b/examples/019_facts/roles/demo_app/files/demo/app/demo.wsgi new file mode 100644 index 0000000..f6453b3 --- /dev/null +++ b/examples/019_facts/roles/demo_app/files/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +execfile(activate_this, dict(__file__=activate_this)) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application diff --git a/examples/019_facts/roles/demo_app/files/demo/app/requirements.txt b/examples/019_facts/roles/demo_app/files/demo/app/requirements.txt new file mode 100644 index 0000000..451ff90 --- /dev/null +++ b/examples/019_facts/roles/demo_app/files/demo/app/requirements.txt @@ -0,0 +1,2 @@ +Flask==0.10.1 +Flask-SQLAlchemy==2.0 diff --git a/examples/019_facts/roles/demo_app/files/demo/demo.conf b/examples/019_facts/roles/demo_app/files/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/019_facts/roles/demo_app/files/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/019_facts/roles/demo_app/handlers/main.yml b/examples/019_facts/roles/demo_app/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/019_facts/roles/demo_app/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/019_facts/roles/demo_app/meta/main.yml b/examples/019_facts/roles/demo_app/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/019_facts/roles/demo_app/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/019_facts/roles/demo_app/tasks/main.yml b/examples/019_facts/roles/demo_app/tasks/main.yml new file mode 100644 index 0000000..c5e1f3a --- /dev/null +++ b/examples/019_facts/roles/demo_app/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - python-pip-whl + - python3-virtualenv + - python3-mysqldb + +- 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: activate demo apache site + file: src=/etc/apache2/sites-available/demo.conf dest=/etc/apache2/sites-enabled/demo.conf state=link + notify: restart apache2 diff --git a/examples/019_facts/roles/demo_app/vars/main.yml b/examples/019_facts/roles/demo_app/vars/main.yml new file mode 100644 index 0000000..52fb613 --- /dev/null +++ b/examples/019_facts/roles/demo_app/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for demo_app diff --git a/examples/019_facts/roles/mysql/README.md b/examples/019_facts/roles/mysql/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/019_facts/roles/mysql/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/019_facts/roles/mysql/defaults/main.yml b/examples/019_facts/roles/mysql/defaults/main.yml new file mode 100644 index 0000000..e9ebcba --- /dev/null +++ b/examples/019_facts/roles/mysql/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for mysql diff --git a/examples/019_facts/roles/mysql/handlers/main.yml b/examples/019_facts/roles/mysql/handlers/main.yml new file mode 100644 index 0000000..3755d8c --- /dev/null +++ b/examples/019_facts/roles/mysql/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart mysql + service: name=mysql state=restarted diff --git a/examples/019_facts/roles/mysql/meta/main.yml b/examples/019_facts/roles/mysql/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/019_facts/roles/mysql/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/019_facts/roles/mysql/tasks/main.yml b/examples/019_facts/roles/mysql/tasks/main.yml new file mode 100644 index 0000000..163a18f --- /dev/null +++ b/examples/019_facts/roles/mysql/tasks/main.yml @@ -0,0 +1,26 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python3-mysqldb + - mysql-server + +- name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + +- name: copy original config file + copy: src=files/my.cnf dest=/etc/mysql/my.cnf owner=mysql group=mysql mode=0700 + +- name: ensure mysql listening on all ports + lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address + line="bind-address = {{ ansible_eth0.ipv4.address }}" + notify: restart mysql + +- name: ensure mysql started + service: name=mysql state=started enabled=yes + +- name: create demo database + mysql_db: name=demo state=present + +- name: create demo user + mysql_user: name=demo password=demo priv=demo.*:ALL host='%' state=present diff --git a/examples/019_facts/roles/mysql/vars/main.yml b/examples/019_facts/roles/mysql/vars/main.yml new file mode 100644 index 0000000..a79bfed --- /dev/null +++ b/examples/019_facts/roles/mysql/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for mysql diff --git a/examples/019_facts/roles/nginx/README.md b/examples/019_facts/roles/nginx/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/019_facts/roles/nginx/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/019_facts/roles/nginx/defaults/main.yml b/examples/019_facts/roles/nginx/defaults/main.yml new file mode 100644 index 0000000..78c8c76 --- /dev/null +++ b/examples/019_facts/roles/nginx/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for nginx diff --git a/examples/019_facts/roles/nginx/handlers/main.yml b/examples/019_facts/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..92971d2 --- /dev/null +++ b/examples/019_facts/roles/nginx/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart nginx + service: name=nginx state=restarted diff --git a/examples/019_facts/roles/nginx/meta/main.yml b/examples/019_facts/roles/nginx/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/019_facts/roles/nginx/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/019_facts/roles/nginx/tasks/main.yml b/examples/019_facts/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..69c6461 --- /dev/null +++ b/examples/019_facts/roles/nginx/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python-httplib2 + +- name: install nginx + apt: name=nginx state=present update_cache=yes + +- name: configure nginx site + template: src=nginx.conf.j2 dest=/etc/nginx/sites-available/demo mode=0644 + notify: restart nginx + +- name: de-activate default nginx site + file: path=/etc/nginx/sites-enabled/default state=absent + notify: restart nginx + +- name: activate demo nginx site + file: src=/etc/nginx/sites-available/demo dest=/etc/nginx/sites-enabled/demo state=link + notify: restart nginx + +- name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/019_facts/roles/nginx/templates/nginx.conf.j2 b/examples/019_facts/roles/nginx/templates/nginx.conf.j2 new file mode 100644 index 0000000..4b477b6 --- /dev/null +++ b/examples/019_facts/roles/nginx/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream demo { +{% for server in groups.webserver %} + server {{ server }}; +{% endfor %} +} + +server { + listen 80; + + location / { + proxy_pass http://demo; + } +} diff --git a/examples/019_facts/roles/nginx/vars/main.yml b/examples/019_facts/roles/nginx/vars/main.yml new file mode 100644 index 0000000..d45faf6 --- /dev/null +++ b/examples/019_facts/roles/nginx/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for nginx diff --git a/examples/019_facts/site.yml b/examples/019_facts/site.yml new file mode 100644 index 0000000..7299e9e --- /dev/null +++ b/examples/019_facts/site.yml @@ -0,0 +1,6 @@ +--- +- include: control.yml +- include: database.yml +- include: webserver.yml +- include: loadbalancer.yml +- include: playbooks/stack_status.yml diff --git a/examples/019_facts/webserver.yml b/examples/019_facts/webserver.yml new file mode 100644 index 0000000..195ec7f --- /dev/null +++ b/examples/019_facts/webserver.yml @@ -0,0 +1,6 @@ +--- +- hosts: webserver + become: true + roles: + - apache2 + - demo_app diff --git a/examples/020_defaults/control.yml b/examples/020_defaults/control.yml new file mode 100644 index 0000000..c6a8d81 --- /dev/null +++ b/examples/020_defaults/control.yml @@ -0,0 +1,5 @@ +--- +- hosts: control + become: true + roles: + - control diff --git a/examples/020_defaults/database.yml b/examples/020_defaults/database.yml new file mode 100644 index 0000000..e22020d --- /dev/null +++ b/examples/020_defaults/database.yml @@ -0,0 +1,5 @@ +--- +- hosts: database + become: true + roles: + - mysql diff --git a/examples/020_defaults/demo/app/demo.py b/examples/020_defaults/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/020_defaults/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/020_defaults/demo/app/demo.wsgi b/examples/020_defaults/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/020_defaults/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/020_defaults/demo/app/requirements.txt b/examples/020_defaults/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/020_defaults/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/020_defaults/demo/demo.conf b/examples/020_defaults/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/020_defaults/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/020_defaults/loadbalancer.yml b/examples/020_defaults/loadbalancer.yml new file mode 100644 index 0000000..651bc7d --- /dev/null +++ b/examples/020_defaults/loadbalancer.yml @@ -0,0 +1,5 @@ +--- +- hosts: loadbalancer + become: true + roles: + - nginx diff --git a/examples/020_defaults/playbooks/hostname.yml b/examples/020_defaults/playbooks/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/020_defaults/playbooks/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/020_defaults/playbooks/stack_restart.yml b/examples/020_defaults/playbooks/stack_restart.yml new file mode 100644 index 0000000..d89c326 --- /dev/null +++ b/examples/020_defaults/playbooks/stack_restart.yml @@ -0,0 +1,33 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + - wait_for: port=80 state=drained + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + - wait_for: port=80 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + - wait_for: host={{ ansible_eth0.ipv4.address }} port=3306 state=started + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + - wait_for: port=80 + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started + - wait_for: port=80 diff --git a/examples/020_defaults/playbooks/stack_status.yml b/examples/020_defaults/playbooks/stack_status.yml new file mode 100644 index 0000000..32fcb9a --- /dev/null +++ b/examples/020_defaults/playbooks/stack_status.yml @@ -0,0 +1,67 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: verify nginx service + command: service nginx status + + - name: verify nginx is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: webserver + become: true + tasks: + - name: verify apache2 service + command: service apache2 status + + - name: verify apache2 is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: database + become: true + tasks: + - name: verify mysql service + command: service mysql status + + - name: verify mysql is listening on 3306 + wait_for: port=3306 timeout=1 + +- hosts: control + tasks: + - name: verify end-to-end index response + uri: url=http://{{item}} return_content=yes + with_items: 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}}" + + - name: verify end-to-end db response + uri: url=http://{{item}}/db return_content=yes + with_items: 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}}" + +- hosts: loadbalancer + tasks: + - name: verify backend index response + uri: url=http://{{item}} return_content=yes + with_items: groups.webserver + register: app_index + + - fail: msg="index failed to return content" + when: "'Hello, from sunny' not in item.content" + with_items: "{{app_index.results}}" + + - name: verify backend db response + uri: url=http://{{item}}/db return_content=yes + with_items: groups.webserver + register: app_db + + - fail: msg="db failed to return content" + when: "'Database Connected from' not in item.content" + with_items: "{{app_db.results}}" diff --git a/examples/020_defaults/roles/apache2/README.md b/examples/020_defaults/roles/apache2/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/020_defaults/roles/apache2/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/020_defaults/roles/apache2/defaults/main.yml b/examples/020_defaults/roles/apache2/defaults/main.yml new file mode 100644 index 0000000..0381169 --- /dev/null +++ b/examples/020_defaults/roles/apache2/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for apache2 diff --git a/examples/020_defaults/roles/apache2/handlers/main.yml b/examples/020_defaults/roles/apache2/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/020_defaults/roles/apache2/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/020_defaults/roles/apache2/meta/main.yml b/examples/020_defaults/roles/apache2/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/020_defaults/roles/apache2/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/020_defaults/roles/apache2/tasks/main.yml b/examples/020_defaults/roles/apache2/tasks/main.yml new file mode 100644 index 0000000..2d0632f --- /dev/null +++ b/examples/020_defaults/roles/apache2/tasks/main.yml @@ -0,0 +1,17 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi + +- name: ensure mod_wsgi enabled + apache2_module: state=present name=wsgi + notify: restart apache2 + +- name: de-activate default apache site + file: path=/etc/apache2/sites-enabled/000-default.conf state=absent + notify: restart apache2 + +- name: ensure apache2 started + service: name=apache2 state=started enabled=yes diff --git a/examples/020_defaults/roles/apache2/vars/main.yml b/examples/020_defaults/roles/apache2/vars/main.yml new file mode 100644 index 0000000..5d23ceb --- /dev/null +++ b/examples/020_defaults/roles/apache2/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for apache2 diff --git a/examples/020_defaults/roles/control/README.md b/examples/020_defaults/roles/control/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/020_defaults/roles/control/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/020_defaults/roles/control/defaults/main.yml b/examples/020_defaults/roles/control/defaults/main.yml new file mode 100644 index 0000000..9fe52bd --- /dev/null +++ b/examples/020_defaults/roles/control/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for control diff --git a/examples/020_defaults/roles/control/handlers/main.yml b/examples/020_defaults/roles/control/handlers/main.yml new file mode 100644 index 0000000..4136893 --- /dev/null +++ b/examples/020_defaults/roles/control/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for control diff --git a/examples/020_defaults/roles/control/meta/main.yml b/examples/020_defaults/roles/control/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/020_defaults/roles/control/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/020_defaults/roles/control/tasks/main.yml b/examples/020_defaults/roles/control/tasks/main.yml new file mode 100644 index 0000000..330e91c --- /dev/null +++ b/examples/020_defaults/roles/control/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl + - python-httplib2 diff --git a/examples/020_defaults/roles/control/vars/main.yml b/examples/020_defaults/roles/control/vars/main.yml new file mode 100644 index 0000000..eadc8b6 --- /dev/null +++ b/examples/020_defaults/roles/control/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for control diff --git a/examples/020_defaults/roles/demo_app/README.md b/examples/020_defaults/roles/demo_app/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/020_defaults/roles/demo_app/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/020_defaults/roles/demo_app/defaults/main.yml b/examples/020_defaults/roles/demo_app/defaults/main.yml new file mode 100644 index 0000000..914e957 --- /dev/null +++ b/examples/020_defaults/roles/demo_app/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for demo_app diff --git a/examples/020_defaults/roles/demo_app/files/demo/app/demo.py b/examples/020_defaults/roles/demo_app/files/demo/app/demo.py new file mode 100644 index 0000000..f7897f0 --- /dev/null +++ b/examples/020_defaults/roles/demo_app/files/demo/app/demo.py @@ -0,0 +1,23 @@ +from flask import Flask +from flask.ext.sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + try: + db.create_all() + except Exception as e: + return e.message + '\n' + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() diff --git a/examples/020_defaults/roles/demo_app/files/demo/app/demo.wsgi b/examples/020_defaults/roles/demo_app/files/demo/app/demo.wsgi new file mode 100644 index 0000000..6df3d61 --- /dev/null +++ b/examples/020_defaults/roles/demo_app/files/demo/app/demo.wsgi @@ -0,0 +1,12 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +#execfile(activate_this, dict(__file__=activate_this)) +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +#os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' +os.environ['DATABASE_URI'] = 'mysql://ansibleuser:ansiblepass@db01/ansibleapp' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application diff --git a/examples/020_defaults/roles/demo_app/files/demo/app/requirements.txt b/examples/020_defaults/roles/demo_app/files/demo/app/requirements.txt new file mode 100644 index 0000000..451ff90 --- /dev/null +++ b/examples/020_defaults/roles/demo_app/files/demo/app/requirements.txt @@ -0,0 +1,2 @@ +Flask==0.10.1 +Flask-SQLAlchemy==2.0 diff --git a/examples/020_defaults/roles/demo_app/files/demo/demo.conf b/examples/020_defaults/roles/demo_app/files/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/020_defaults/roles/demo_app/files/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/020_defaults/roles/demo_app/handlers/main.yml b/examples/020_defaults/roles/demo_app/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/020_defaults/roles/demo_app/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/020_defaults/roles/demo_app/meta/main.yml b/examples/020_defaults/roles/demo_app/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/020_defaults/roles/demo_app/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/020_defaults/roles/demo_app/tasks/main.yml b/examples/020_defaults/roles/demo_app/tasks/main.yml new file mode 100644 index 0000000..c5e1f3a --- /dev/null +++ b/examples/020_defaults/roles/demo_app/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - python-pip-whl + - python3-virtualenv + - python3-mysqldb + +- 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: activate demo apache site + file: src=/etc/apache2/sites-available/demo.conf dest=/etc/apache2/sites-enabled/demo.conf state=link + notify: restart apache2 diff --git a/examples/020_defaults/roles/demo_app/vars/main.yml b/examples/020_defaults/roles/demo_app/vars/main.yml new file mode 100644 index 0000000..52fb613 --- /dev/null +++ b/examples/020_defaults/roles/demo_app/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for demo_app diff --git a/examples/020_defaults/roles/mysql/README.md b/examples/020_defaults/roles/mysql/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/020_defaults/roles/mysql/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/020_defaults/roles/mysql/defaults/main.yml b/examples/020_defaults/roles/mysql/defaults/main.yml new file mode 100644 index 0000000..886d59c --- /dev/null +++ b/examples/020_defaults/roles/mysql/defaults/main.yml @@ -0,0 +1,6 @@ +--- +db_name: ansibleapp +db_user_name: ansibleuser +db_user_pass: ansiblepass +db_user_host: localhost +db_server: 3.144.5.82 diff --git a/examples/020_defaults/roles/mysql/handlers/main.yml b/examples/020_defaults/roles/mysql/handlers/main.yml new file mode 100644 index 0000000..3755d8c --- /dev/null +++ b/examples/020_defaults/roles/mysql/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart mysql + service: name=mysql state=restarted diff --git a/examples/020_defaults/roles/mysql/meta/main.yml b/examples/020_defaults/roles/mysql/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/020_defaults/roles/mysql/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/020_defaults/roles/mysql/tasks/main.yml b/examples/020_defaults/roles/mysql/tasks/main.yml new file mode 100644 index 0000000..d4489fa --- /dev/null +++ b/examples/020_defaults/roles/mysql/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python3-mysqldb + +- name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + +- name: ensure mysql listening on all ports + #lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address line="bind-address = {{ ansible_eth0.ipv6[0].address }}" + lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address line="bind-address = {{ db_server }}" + notify: restart mysql + +- name: ensure mysql started + service: name=mysql state=started enabled=yes + +- name: create database + mysql_db: name={{ db_name }} state=present + +- name: create user + mysql_user: name={{ db_user_name }} password={{ db_user_pass }} priv={{ db_name }}.*:ALL + host='{{ db_user_host }}' state=present diff --git a/examples/020_defaults/roles/mysql/vars/main.yml b/examples/020_defaults/roles/mysql/vars/main.yml new file mode 100644 index 0000000..a79bfed --- /dev/null +++ b/examples/020_defaults/roles/mysql/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for mysql diff --git a/examples/020_defaults/roles/nginx/README.md b/examples/020_defaults/roles/nginx/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/020_defaults/roles/nginx/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/020_defaults/roles/nginx/defaults/main.yml b/examples/020_defaults/roles/nginx/defaults/main.yml new file mode 100644 index 0000000..78c8c76 --- /dev/null +++ b/examples/020_defaults/roles/nginx/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for nginx diff --git a/examples/020_defaults/roles/nginx/handlers/main.yml b/examples/020_defaults/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..92971d2 --- /dev/null +++ b/examples/020_defaults/roles/nginx/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart nginx + service: name=nginx state=restarted diff --git a/examples/020_defaults/roles/nginx/meta/main.yml b/examples/020_defaults/roles/nginx/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/020_defaults/roles/nginx/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/020_defaults/roles/nginx/tasks/main.yml b/examples/020_defaults/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..69c6461 --- /dev/null +++ b/examples/020_defaults/roles/nginx/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python-httplib2 + +- name: install nginx + apt: name=nginx state=present update_cache=yes + +- name: configure nginx site + template: src=nginx.conf.j2 dest=/etc/nginx/sites-available/demo mode=0644 + notify: restart nginx + +- name: de-activate default nginx site + file: path=/etc/nginx/sites-enabled/default state=absent + notify: restart nginx + +- name: activate demo nginx site + file: src=/etc/nginx/sites-available/demo dest=/etc/nginx/sites-enabled/demo state=link + notify: restart nginx + +- name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/020_defaults/roles/nginx/templates/nginx.conf.j2 b/examples/020_defaults/roles/nginx/templates/nginx.conf.j2 new file mode 100644 index 0000000..4b477b6 --- /dev/null +++ b/examples/020_defaults/roles/nginx/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream demo { +{% for server in groups.webserver %} + server {{ server }}; +{% endfor %} +} + +server { + listen 80; + + location / { + proxy_pass http://demo; + } +} diff --git a/examples/020_defaults/roles/nginx/vars/main.yml b/examples/020_defaults/roles/nginx/vars/main.yml new file mode 100644 index 0000000..d45faf6 --- /dev/null +++ b/examples/020_defaults/roles/nginx/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for nginx diff --git a/examples/020_defaults/site.yml b/examples/020_defaults/site.yml new file mode 100644 index 0000000..7299e9e --- /dev/null +++ b/examples/020_defaults/site.yml @@ -0,0 +1,6 @@ +--- +- include: control.yml +- include: database.yml +- include: webserver.yml +- include: loadbalancer.yml +- include: playbooks/stack_status.yml diff --git a/examples/020_defaults/webserver.yml b/examples/020_defaults/webserver.yml new file mode 100644 index 0000000..195ec7f --- /dev/null +++ b/examples/020_defaults/webserver.yml @@ -0,0 +1,6 @@ +--- +- hosts: webserver + become: true + roles: + - apache2 + - demo_app diff --git a/examples/021_vars/control.yml b/examples/021_vars/control.yml new file mode 100644 index 0000000..c6a8d81 --- /dev/null +++ b/examples/021_vars/control.yml @@ -0,0 +1,5 @@ +--- +- hosts: control + become: true + roles: + - control diff --git a/examples/021_vars/database.yml b/examples/021_vars/database.yml new file mode 100644 index 0000000..6b6387d --- /dev/null +++ b/examples/021_vars/database.yml @@ -0,0 +1,6 @@ +--- +- hosts: database + become: true + roles: +# - { role: mysql, db_name: demo, db_user_name: demo, db_user_pass: demo, db_user_host: '%' } + - { role: mysql } diff --git a/examples/021_vars/demo/app/demo.py b/examples/021_vars/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/021_vars/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/021_vars/demo/app/demo.wsgi b/examples/021_vars/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/021_vars/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/021_vars/demo/app/requirements.txt b/examples/021_vars/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/021_vars/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/021_vars/demo/demo.conf b/examples/021_vars/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/021_vars/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/021_vars/loadbalancer.yml b/examples/021_vars/loadbalancer.yml new file mode 100644 index 0000000..651bc7d --- /dev/null +++ b/examples/021_vars/loadbalancer.yml @@ -0,0 +1,5 @@ +--- +- hosts: loadbalancer + become: true + roles: + - nginx diff --git a/examples/021_vars/playbooks/hostname.yml b/examples/021_vars/playbooks/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/021_vars/playbooks/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/021_vars/playbooks/stack_restart.yml b/examples/021_vars/playbooks/stack_restart.yml new file mode 100644 index 0000000..d89c326 --- /dev/null +++ b/examples/021_vars/playbooks/stack_restart.yml @@ -0,0 +1,33 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + - wait_for: port=80 state=drained + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + - wait_for: port=80 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + - wait_for: host={{ ansible_eth0.ipv4.address }} port=3306 state=started + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + - wait_for: port=80 + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started + - wait_for: port=80 diff --git a/examples/021_vars/playbooks/stack_status.yml b/examples/021_vars/playbooks/stack_status.yml new file mode 100644 index 0000000..aae9058 --- /dev/null +++ b/examples/021_vars/playbooks/stack_status.yml @@ -0,0 +1,67 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: verify nginx service + command: service nginx status + + - name: verify nginx is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: webserver + become: true + tasks: + - name: verify apache2 service + command: service apache2 status + + - name: verify apache2 is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: database + become: true + tasks: + - name: verify mysql service + command: service mysql status + + - name: verify mysql is listening on 3306 + wait_for: port=3306 timeout=1 + +- hosts: control + tasks: + - name: verify end-to-end index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ 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}}" + + - name: verify end-to-end db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ 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}}" + +- hosts: loadbalancer + tasks: + - name: verify backend index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ groups.webserver }}" + register: app_index + + - fail: msg="index failed to return content" + when: "'Hello, from sunny' not in item.content" + with_items: "{{app_index.results}}" + + - name: verify backend db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ groups.webserver }}" + register: app_db + + - fail: msg="db failed to return content" + when: "'Database Connected from' not in item.content" + with_items: "{{app_db.results}}" diff --git a/examples/021_vars/roles/apache2/README.md b/examples/021_vars/roles/apache2/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/021_vars/roles/apache2/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/021_vars/roles/apache2/defaults/main.yml b/examples/021_vars/roles/apache2/defaults/main.yml new file mode 100644 index 0000000..0381169 --- /dev/null +++ b/examples/021_vars/roles/apache2/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for apache2 diff --git a/examples/021_vars/roles/apache2/handlers/main.yml b/examples/021_vars/roles/apache2/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/021_vars/roles/apache2/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/021_vars/roles/apache2/meta/main.yml b/examples/021_vars/roles/apache2/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/021_vars/roles/apache2/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/021_vars/roles/apache2/tasks/main.yml b/examples/021_vars/roles/apache2/tasks/main.yml new file mode 100644 index 0000000..e1fd9a3 --- /dev/null +++ b/examples/021_vars/roles/apache2/tasks/main.yml @@ -0,0 +1,17 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + +- name: ensure mod_wsgi enabled + apache2_module: state=present name=wsgi + notify: restart apache2 + +- name: de-activate default apache site + file: path=/etc/apache2/sites-enabled/000-default.conf state=absent + notify: restart apache2 + +- name: ensure apache2 started + service: name=apache2 state=started enabled=yes diff --git a/examples/021_vars/roles/apache2/vars/main.yml b/examples/021_vars/roles/apache2/vars/main.yml new file mode 100644 index 0000000..5d23ceb --- /dev/null +++ b/examples/021_vars/roles/apache2/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for apache2 diff --git a/examples/021_vars/roles/control/README.md b/examples/021_vars/roles/control/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/021_vars/roles/control/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/021_vars/roles/control/defaults/main.yml b/examples/021_vars/roles/control/defaults/main.yml new file mode 100644 index 0000000..9fe52bd --- /dev/null +++ b/examples/021_vars/roles/control/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for control diff --git a/examples/021_vars/roles/control/handlers/main.yml b/examples/021_vars/roles/control/handlers/main.yml new file mode 100644 index 0000000..4136893 --- /dev/null +++ b/examples/021_vars/roles/control/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for control diff --git a/examples/021_vars/roles/control/meta/main.yml b/examples/021_vars/roles/control/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/021_vars/roles/control/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/021_vars/roles/control/tasks/main.yml b/examples/021_vars/roles/control/tasks/main.yml new file mode 100644 index 0000000..330e91c --- /dev/null +++ b/examples/021_vars/roles/control/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl + - python-httplib2 diff --git a/examples/021_vars/roles/control/vars/main.yml b/examples/021_vars/roles/control/vars/main.yml new file mode 100644 index 0000000..eadc8b6 --- /dev/null +++ b/examples/021_vars/roles/control/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for control diff --git a/examples/021_vars/roles/demo_app/README.md b/examples/021_vars/roles/demo_app/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/021_vars/roles/demo_app/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/021_vars/roles/demo_app/defaults/main.yml b/examples/021_vars/roles/demo_app/defaults/main.yml new file mode 100644 index 0000000..914e957 --- /dev/null +++ b/examples/021_vars/roles/demo_app/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for demo_app diff --git a/examples/021_vars/roles/demo_app/files/demo/app/demo.py b/examples/021_vars/roles/demo_app/files/demo/app/demo.py new file mode 100644 index 0000000..05874b6 --- /dev/null +++ b/examples/021_vars/roles/demo_app/files/demo/app/demo.py @@ -0,0 +1,23 @@ +from flask import Flask +from flask.ext.sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + #try: + # db.create_all() + #except Exception as e: + # return e.message + '\n' + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() diff --git a/examples/021_vars/roles/demo_app/files/demo/app/demo.wsgi b/examples/021_vars/roles/demo_app/files/demo/app/demo.wsgi new file mode 100644 index 0000000..d3e3543 --- /dev/null +++ b/examples/021_vars/roles/demo_app/files/demo/app/demo.wsgi @@ -0,0 +1,11 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +#execfile(activate_this, dict(__file__=activate_this)) +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application diff --git a/examples/021_vars/roles/demo_app/files/demo/app/requirements.txt b/examples/021_vars/roles/demo_app/files/demo/app/requirements.txt new file mode 100644 index 0000000..451ff90 --- /dev/null +++ b/examples/021_vars/roles/demo_app/files/demo/app/requirements.txt @@ -0,0 +1,2 @@ +Flask==0.10.1 +Flask-SQLAlchemy==2.0 diff --git a/examples/021_vars/roles/demo_app/files/demo/demo.conf b/examples/021_vars/roles/demo_app/files/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/021_vars/roles/demo_app/files/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/021_vars/roles/demo_app/handlers/main.yml b/examples/021_vars/roles/demo_app/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/021_vars/roles/demo_app/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/021_vars/roles/demo_app/meta/main.yml b/examples/021_vars/roles/demo_app/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/021_vars/roles/demo_app/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/021_vars/roles/demo_app/tasks/main.yml b/examples/021_vars/roles/demo_app/tasks/main.yml new file mode 100644 index 0000000..c5e1f3a --- /dev/null +++ b/examples/021_vars/roles/demo_app/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - python-pip-whl + - python3-virtualenv + - python3-mysqldb + +- 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: activate demo apache site + file: src=/etc/apache2/sites-available/demo.conf dest=/etc/apache2/sites-enabled/demo.conf state=link + notify: restart apache2 diff --git a/examples/021_vars/roles/demo_app/vars/main.yml b/examples/021_vars/roles/demo_app/vars/main.yml new file mode 100644 index 0000000..52fb613 --- /dev/null +++ b/examples/021_vars/roles/demo_app/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for demo_app diff --git a/examples/021_vars/roles/mysql/README.md b/examples/021_vars/roles/mysql/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/021_vars/roles/mysql/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/021_vars/roles/mysql/defaults/main.yml b/examples/021_vars/roles/mysql/defaults/main.yml new file mode 100644 index 0000000..f76aeda --- /dev/null +++ b/examples/021_vars/roles/mysql/defaults/main.yml @@ -0,0 +1,6 @@ +--- +db_name: myapp +db_user_name: dbuser +db_user_pass: dbpass +db_user_host: localhost +db_host_ipv4: 3.144.5.82 diff --git a/examples/021_vars/roles/mysql/handlers/main.yml b/examples/021_vars/roles/mysql/handlers/main.yml new file mode 100644 index 0000000..3755d8c --- /dev/null +++ b/examples/021_vars/roles/mysql/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart mysql + service: name=mysql state=restarted diff --git a/examples/021_vars/roles/mysql/meta/main.yml b/examples/021_vars/roles/mysql/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/021_vars/roles/mysql/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/021_vars/roles/mysql/tasks/main.yml b/examples/021_vars/roles/mysql/tasks/main.yml new file mode 100644 index 0000000..0a36c93 --- /dev/null +++ b/examples/021_vars/roles/mysql/tasks/main.yml @@ -0,0 +1,27 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python3-mysqldb + - mysql-server + +- name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + +- name: chmod cnf + copy: src=files/my.cnf dest=/etc/mysql/my.cnf owner=mysql group=mysql mode=0700 + +- name: ensure mysql listening on all ports + lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address + line="bind-address = {{ db_host_ipv4 }}" + notify: restart mysql + +- name: ensure mysql started + service: name=mysql state=started enabled=yes + +- name: create database + mysql_db: name={{ db_name }} state=present + +- name: create user + mysql_user: name={{ db_user_name }} password={{ db_user_pass }} priv={{ db_name }}.*:ALL + host='{{ db_user_host }}' state=present diff --git a/examples/021_vars/roles/mysql/vars/main.yml b/examples/021_vars/roles/mysql/vars/main.yml new file mode 100644 index 0000000..a79bfed --- /dev/null +++ b/examples/021_vars/roles/mysql/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for mysql diff --git a/examples/021_vars/roles/nginx/README.md b/examples/021_vars/roles/nginx/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/021_vars/roles/nginx/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/021_vars/roles/nginx/defaults/main.yml b/examples/021_vars/roles/nginx/defaults/main.yml new file mode 100644 index 0000000..16c56ce --- /dev/null +++ b/examples/021_vars/roles/nginx/defaults/main.yml @@ -0,0 +1,6 @@ +# defaults file for nginx +--- +sites: + myappguillem: + frontend: 80 + backend: 80 diff --git a/examples/021_vars/roles/nginx/handlers/main.yml b/examples/021_vars/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..92971d2 --- /dev/null +++ b/examples/021_vars/roles/nginx/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart nginx + service: name=nginx state=restarted diff --git a/examples/021_vars/roles/nginx/meta/main.yml b/examples/021_vars/roles/nginx/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/021_vars/roles/nginx/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/021_vars/roles/nginx/tasks/main.yml b/examples/021_vars/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..20396e9 --- /dev/null +++ b/examples/021_vars/roles/nginx/tasks/main.yml @@ -0,0 +1,30 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python-httplib2 + +- name: install nginx + apt: name=nginx state=present update_cache=yes + +- name: de-active former served sites + file: name=/etc/nginx/sites-enabled/{{ item.key }} state=absent + with_dict: "{{ sites }}" + notify: restart nginx + +- name: configure sites nginx + template: src=nginx.conf.j2 dest=/etc/nginx/sites-available/{{ item.key }} mode=0644 + with_dict: "{{ sites }}" + notify: restart nginx + +- name: de-activate default nginx site + file: path=/etc/nginx/sites-enabled/default state=absent + notify: restart nginx + +- name: activate sites nginx + file: src=/etc/nginx/sites-available/{{ item.key }} dest=/etc/nginx/sites-enabled/{{ item.key }} state=link + with_dict: "{{ sites }}" + notify: restart nginx + +- name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/021_vars/roles/nginx/templates/nginx.conf.j2 b/examples/021_vars/roles/nginx/templates/nginx.conf.j2 new file mode 100644 index 0000000..6e716d1 --- /dev/null +++ b/examples/021_vars/roles/nginx/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream {{ item.key }} { +{% for server in groups.webserver %} + server {{ server }}:{{ item.value.backend }}; +{% endfor %} +} + +server { + listen {{ item.value.frontend }}; + + location / { + proxy_pass http://{{ item.key }}; + } +} diff --git a/examples/021_vars/roles/nginx/vars/main.yml b/examples/021_vars/roles/nginx/vars/main.yml new file mode 100644 index 0000000..d45faf6 --- /dev/null +++ b/examples/021_vars/roles/nginx/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for nginx diff --git a/examples/021_vars/site.yml b/examples/021_vars/site.yml new file mode 100644 index 0000000..7299e9e --- /dev/null +++ b/examples/021_vars/site.yml @@ -0,0 +1,6 @@ +--- +- include: control.yml +- include: database.yml +- include: webserver.yml +- include: loadbalancer.yml +- include: playbooks/stack_status.yml diff --git a/examples/021_vars/webserver.yml b/examples/021_vars/webserver.yml new file mode 100644 index 0000000..195ec7f --- /dev/null +++ b/examples/021_vars/webserver.yml @@ -0,0 +1,6 @@ +--- +- hosts: webserver + become: true + roles: + - apache2 + - demo_app diff --git a/examples/022_with_dict/control.yml b/examples/022_with_dict/control.yml new file mode 100644 index 0000000..c6a8d81 --- /dev/null +++ b/examples/022_with_dict/control.yml @@ -0,0 +1,5 @@ +--- +- hosts: control + become: true + roles: + - control diff --git a/examples/022_with_dict/database.yml b/examples/022_with_dict/database.yml new file mode 100644 index 0000000..fee12fa --- /dev/null +++ b/examples/022_with_dict/database.yml @@ -0,0 +1,5 @@ +--- +- hosts: database + become: true + roles: + - { role: mysql, db_name: demo, db_user_name: demo, db_user_pass: demo, db_user_host: '%' } diff --git a/examples/022_with_dict/demo/app/demo.py b/examples/022_with_dict/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/022_with_dict/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/022_with_dict/demo/app/demo.wsgi b/examples/022_with_dict/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/022_with_dict/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/022_with_dict/demo/app/requirements.txt b/examples/022_with_dict/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/022_with_dict/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/022_with_dict/demo/demo.conf b/examples/022_with_dict/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/022_with_dict/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/022_with_dict/loadbalancer.yml b/examples/022_with_dict/loadbalancer.yml new file mode 100644 index 0000000..651bc7d --- /dev/null +++ b/examples/022_with_dict/loadbalancer.yml @@ -0,0 +1,5 @@ +--- +- hosts: loadbalancer + become: true + roles: + - nginx diff --git a/examples/022_with_dict/playbooks/hostname.yml b/examples/022_with_dict/playbooks/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/022_with_dict/playbooks/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/022_with_dict/playbooks/stack_restart.yml b/examples/022_with_dict/playbooks/stack_restart.yml new file mode 100644 index 0000000..d89c326 --- /dev/null +++ b/examples/022_with_dict/playbooks/stack_restart.yml @@ -0,0 +1,33 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + - wait_for: port=80 state=drained + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + - wait_for: port=80 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + - wait_for: host={{ ansible_eth0.ipv4.address }} port=3306 state=started + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + - wait_for: port=80 + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started + - wait_for: port=80 diff --git a/examples/022_with_dict/playbooks/stack_status.yml b/examples/022_with_dict/playbooks/stack_status.yml new file mode 100644 index 0000000..3c1331b --- /dev/null +++ b/examples/022_with_dict/playbooks/stack_status.yml @@ -0,0 +1,67 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: verify nginx service + command: service nginx status + + - name: verify nginx is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: webserver + become: true + tasks: + - name: verify apache2 service + command: service apache2 status + + - name: verify apache2 is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: database + become: true + tasks: + - name: verify mysql service + command: service mysql status + + - name: verify mysql is listening on 3306 + wait_for: host={{ ansible_eth0.ipv4.address }} port=3306 timeout=1 + +- hosts: control + tasks: + - name: verify end-to-end index response + uri: url=http://{{item}} return_content=yes + with_items: 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}}" + + - name: verify end-to-end db response + uri: url=http://{{item}}/db return_content=yes + with_items: 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}}" + +- hosts: loadbalancer + tasks: + - name: verify backend index response + uri: url=http://{{item}} return_content=yes + with_items: 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}}" + + - name: verify backend db response + uri: url=http://{{item}}/db return_content=yes + with_items: 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}}" diff --git a/examples/022_with_dict/roles/apache2/README.md b/examples/022_with_dict/roles/apache2/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/022_with_dict/roles/apache2/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/022_with_dict/roles/apache2/defaults/main.yml b/examples/022_with_dict/roles/apache2/defaults/main.yml new file mode 100644 index 0000000..0381169 --- /dev/null +++ b/examples/022_with_dict/roles/apache2/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for apache2 diff --git a/examples/022_with_dict/roles/apache2/handlers/main.yml b/examples/022_with_dict/roles/apache2/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/022_with_dict/roles/apache2/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/022_with_dict/roles/apache2/meta/main.yml b/examples/022_with_dict/roles/apache2/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/022_with_dict/roles/apache2/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/022_with_dict/roles/apache2/tasks/main.yml b/examples/022_with_dict/roles/apache2/tasks/main.yml new file mode 100644 index 0000000..2d0632f --- /dev/null +++ b/examples/022_with_dict/roles/apache2/tasks/main.yml @@ -0,0 +1,17 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi + +- name: ensure mod_wsgi enabled + apache2_module: state=present name=wsgi + notify: restart apache2 + +- name: de-activate default apache site + file: path=/etc/apache2/sites-enabled/000-default.conf state=absent + notify: restart apache2 + +- name: ensure apache2 started + service: name=apache2 state=started enabled=yes diff --git a/examples/022_with_dict/roles/apache2/vars/main.yml b/examples/022_with_dict/roles/apache2/vars/main.yml new file mode 100644 index 0000000..5d23ceb --- /dev/null +++ b/examples/022_with_dict/roles/apache2/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for apache2 diff --git a/examples/022_with_dict/roles/control/README.md b/examples/022_with_dict/roles/control/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/022_with_dict/roles/control/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/022_with_dict/roles/control/defaults/main.yml b/examples/022_with_dict/roles/control/defaults/main.yml new file mode 100644 index 0000000..9fe52bd --- /dev/null +++ b/examples/022_with_dict/roles/control/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for control diff --git a/examples/022_with_dict/roles/control/handlers/main.yml b/examples/022_with_dict/roles/control/handlers/main.yml new file mode 100644 index 0000000..4136893 --- /dev/null +++ b/examples/022_with_dict/roles/control/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for control diff --git a/examples/022_with_dict/roles/control/meta/main.yml b/examples/022_with_dict/roles/control/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/022_with_dict/roles/control/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/022_with_dict/roles/control/tasks/main.yml b/examples/022_with_dict/roles/control/tasks/main.yml new file mode 100644 index 0000000..330e91c --- /dev/null +++ b/examples/022_with_dict/roles/control/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl + - python-httplib2 diff --git a/examples/022_with_dict/roles/control/vars/main.yml b/examples/022_with_dict/roles/control/vars/main.yml new file mode 100644 index 0000000..eadc8b6 --- /dev/null +++ b/examples/022_with_dict/roles/control/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for control diff --git a/examples/022_with_dict/roles/demo_app/README.md b/examples/022_with_dict/roles/demo_app/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/022_with_dict/roles/demo_app/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/022_with_dict/roles/demo_app/defaults/main.yml b/examples/022_with_dict/roles/demo_app/defaults/main.yml new file mode 100644 index 0000000..914e957 --- /dev/null +++ b/examples/022_with_dict/roles/demo_app/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for demo_app diff --git a/examples/022_with_dict/roles/demo_app/files/demo/app/demo.py b/examples/022_with_dict/roles/demo_app/files/demo/app/demo.py new file mode 100644 index 0000000..f7897f0 --- /dev/null +++ b/examples/022_with_dict/roles/demo_app/files/demo/app/demo.py @@ -0,0 +1,23 @@ +from flask import Flask +from flask.ext.sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + try: + db.create_all() + except Exception as e: + return e.message + '\n' + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() diff --git a/examples/022_with_dict/roles/demo_app/files/demo/app/demo.wsgi b/examples/022_with_dict/roles/demo_app/files/demo/app/demo.wsgi new file mode 100644 index 0000000..f6453b3 --- /dev/null +++ b/examples/022_with_dict/roles/demo_app/files/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +execfile(activate_this, dict(__file__=activate_this)) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application diff --git a/examples/022_with_dict/roles/demo_app/files/demo/app/requirements.txt b/examples/022_with_dict/roles/demo_app/files/demo/app/requirements.txt new file mode 100644 index 0000000..451ff90 --- /dev/null +++ b/examples/022_with_dict/roles/demo_app/files/demo/app/requirements.txt @@ -0,0 +1,2 @@ +Flask==0.10.1 +Flask-SQLAlchemy==2.0 diff --git a/examples/022_with_dict/roles/demo_app/files/demo/demo.conf b/examples/022_with_dict/roles/demo_app/files/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/022_with_dict/roles/demo_app/files/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/022_with_dict/roles/demo_app/handlers/main.yml b/examples/022_with_dict/roles/demo_app/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/022_with_dict/roles/demo_app/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/022_with_dict/roles/demo_app/meta/main.yml b/examples/022_with_dict/roles/demo_app/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/022_with_dict/roles/demo_app/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/022_with_dict/roles/demo_app/tasks/main.yml b/examples/022_with_dict/roles/demo_app/tasks/main.yml new file mode 100644 index 0000000..05ff043 --- /dev/null +++ b/examples/022_with_dict/roles/demo_app/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - python-pip + - python-virtualenv + - python-mysqldb + +- 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: activate demo apache site + file: src=/etc/apache2/sites-available/demo.conf dest=/etc/apache2/sites-enabled/demo.conf state=link + notify: restart apache2 diff --git a/examples/022_with_dict/roles/demo_app/vars/main.yml b/examples/022_with_dict/roles/demo_app/vars/main.yml new file mode 100644 index 0000000..52fb613 --- /dev/null +++ b/examples/022_with_dict/roles/demo_app/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for demo_app diff --git a/examples/022_with_dict/roles/mysql/README.md b/examples/022_with_dict/roles/mysql/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/022_with_dict/roles/mysql/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/022_with_dict/roles/mysql/defaults/main.yml b/examples/022_with_dict/roles/mysql/defaults/main.yml new file mode 100644 index 0000000..2ea6760 --- /dev/null +++ b/examples/022_with_dict/roles/mysql/defaults/main.yml @@ -0,0 +1,5 @@ +--- +db_name: myapp +db_user_name: dbuser +db_user_pass: dbpass +db_user_host: localhost diff --git a/examples/022_with_dict/roles/mysql/handlers/main.yml b/examples/022_with_dict/roles/mysql/handlers/main.yml new file mode 100644 index 0000000..3755d8c --- /dev/null +++ b/examples/022_with_dict/roles/mysql/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart mysql + service: name=mysql state=restarted diff --git a/examples/022_with_dict/roles/mysql/meta/main.yml b/examples/022_with_dict/roles/mysql/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/022_with_dict/roles/mysql/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/022_with_dict/roles/mysql/tasks/main.yml b/examples/022_with_dict/roles/mysql/tasks/main.yml new file mode 100644 index 0000000..438fd7a --- /dev/null +++ b/examples/022_with_dict/roles/mysql/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python-mysqldb + +- name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + +- name: ensure mysql listening on all ports + lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address + line="bind-address = {{ ansible_eth0.ipv4.address }}" + notify: restart mysql + +- name: ensure mysql started + service: name=mysql state=started enabled=yes + +- name: create database + mysql_db: name={{ db_name }} state=present + +- name: create user + mysql_user: name={{ db_user_name }} password={{ db_user_pass }} priv={{ db_name }}.*:ALL + host='{{ db_user_host }}' state=present diff --git a/examples/022_with_dict/roles/mysql/vars/main.yml b/examples/022_with_dict/roles/mysql/vars/main.yml new file mode 100644 index 0000000..a79bfed --- /dev/null +++ b/examples/022_with_dict/roles/mysql/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for mysql diff --git a/examples/022_with_dict/roles/nginx/README.md b/examples/022_with_dict/roles/nginx/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/022_with_dict/roles/nginx/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/022_with_dict/roles/nginx/defaults/main.yml b/examples/022_with_dict/roles/nginx/defaults/main.yml new file mode 100644 index 0000000..0661d5d --- /dev/null +++ b/examples/022_with_dict/roles/nginx/defaults/main.yml @@ -0,0 +1,5 @@ +--- +sites: + myapp: + frontend: 80 + backend: 80 diff --git a/examples/022_with_dict/roles/nginx/handlers/main.yml b/examples/022_with_dict/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..92971d2 --- /dev/null +++ b/examples/022_with_dict/roles/nginx/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart nginx + service: name=nginx state=restarted diff --git a/examples/022_with_dict/roles/nginx/meta/main.yml b/examples/022_with_dict/roles/nginx/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/022_with_dict/roles/nginx/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/022_with_dict/roles/nginx/tasks/main.yml b/examples/022_with_dict/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..47e4eb2 --- /dev/null +++ b/examples/022_with_dict/roles/nginx/tasks/main.yml @@ -0,0 +1,25 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python-httplib2 + +- name: install nginx + apt: name=nginx state=present update_cache=yes + +- name: configure nginx sites + template: src=nginx.conf.j2 dest=/etc/nginx/sites-available/{{ item.key }} mode=0644 + with_dict: sites + notify: restart nginx + +- name: de-activate default nginx site + file: path=/etc/nginx/sites-enabled/default state=absent + notify: restart nginx + +- name: activate nginx sites + file: src=/etc/nginx/sites-available/{{ item.key }} dest=/etc/nginx/sites-enabled/{{ item.key }} state=link + with_dict: sites + notify: restart nginx + +- name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/022_with_dict/roles/nginx/templates/nginx.conf.j2 b/examples/022_with_dict/roles/nginx/templates/nginx.conf.j2 new file mode 100644 index 0000000..092c8be --- /dev/null +++ b/examples/022_with_dict/roles/nginx/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream {{ item.key }} { +{% for server in groups.webserver %} + server {{ server }}:{{ item.value.backend }}; +{% endfor %} +} + +server { + listen {{ item.value.frontend }}; + + location / { + proxy_pass http://{{ item.key }}; + } +} diff --git a/examples/022_with_dict/roles/nginx/vars/main.yml b/examples/022_with_dict/roles/nginx/vars/main.yml new file mode 100644 index 0000000..d45faf6 --- /dev/null +++ b/examples/022_with_dict/roles/nginx/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for nginx diff --git a/examples/022_with_dict/site.yml b/examples/022_with_dict/site.yml new file mode 100644 index 0000000..0cb3dd0 --- /dev/null +++ b/examples/022_with_dict/site.yml @@ -0,0 +1,5 @@ +--- +- include: control.yml +- include: database.yml +- include: webserver.yml +- include: loadbalancer.yml diff --git a/examples/022_with_dict/webserver.yml b/examples/022_with_dict/webserver.yml new file mode 100644 index 0000000..195ec7f --- /dev/null +++ b/examples/022_with_dict/webserver.yml @@ -0,0 +1,6 @@ +--- +- hosts: webserver + become: true + roles: + - apache2 + - demo_app diff --git a/examples/023_selective_removal/control.yml b/examples/023_selective_removal/control.yml new file mode 100644 index 0000000..c6a8d81 --- /dev/null +++ b/examples/023_selective_removal/control.yml @@ -0,0 +1,5 @@ +--- +- hosts: control + become: true + roles: + - control diff --git a/examples/023_selective_removal/database.yml b/examples/023_selective_removal/database.yml new file mode 100644 index 0000000..690fff4 --- /dev/null +++ b/examples/023_selective_removal/database.yml @@ -0,0 +1,5 @@ +--- +- hosts: database + become: true + roles: + - { role: mysql, db_name: eureka, db_user_name: eurekademo, db_user_pass: eurekademo, db_user_host: '%' } diff --git a/examples/023_selective_removal/demo/app/demo.py b/examples/023_selective_removal/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/023_selective_removal/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/023_selective_removal/demo/app/demo.wsgi b/examples/023_selective_removal/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/023_selective_removal/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/023_selective_removal/demo/app/requirements.txt b/examples/023_selective_removal/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/023_selective_removal/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/023_selective_removal/demo/demo.conf b/examples/023_selective_removal/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/023_selective_removal/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/023_selective_removal/loadbalancer.yml b/examples/023_selective_removal/loadbalancer.yml new file mode 100644 index 0000000..651bc7d --- /dev/null +++ b/examples/023_selective_removal/loadbalancer.yml @@ -0,0 +1,5 @@ +--- +- hosts: loadbalancer + become: true + roles: + - nginx diff --git a/examples/023_selective_removal/playbooks/hostname.yml b/examples/023_selective_removal/playbooks/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/023_selective_removal/playbooks/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/023_selective_removal/playbooks/stack_restart.yml b/examples/023_selective_removal/playbooks/stack_restart.yml new file mode 100644 index 0000000..d89c326 --- /dev/null +++ b/examples/023_selective_removal/playbooks/stack_restart.yml @@ -0,0 +1,33 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + - wait_for: port=80 state=drained + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + - wait_for: port=80 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + - wait_for: host={{ ansible_eth0.ipv4.address }} port=3306 state=started + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + - wait_for: port=80 + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started + - wait_for: port=80 diff --git a/examples/023_selective_removal/playbooks/stack_status.yml b/examples/023_selective_removal/playbooks/stack_status.yml new file mode 100644 index 0000000..2abc0ea --- /dev/null +++ b/examples/023_selective_removal/playbooks/stack_status.yml @@ -0,0 +1,67 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: verify nginx service + command: service nginx status + + - name: verify nginx is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: webserver + become: true + tasks: + - name: verify apache2 service + command: service apache2 status + + - name: verify apache2 is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: database + become: true + tasks: + - name: verify mysql service + command: service mysql status + + - name: verify mysql is listening on 3306 + wait_for: port=3306 timeout=1 + +- hosts: control + tasks: + - name: verify end-to-end index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ 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}}" + + - name: verify end-to-end db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ 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}}" + +- hosts: loadbalancer + tasks: + - name: verify backend index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ groups.webserver }}" + register: app_index + +# - fail: msg="index failed to return content" +# when: "'Hello, from sunny {{ item.content }}!' not in item.content" +# with_items: "{{app_index.results}}" + + - name: verify backend db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ 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}}" diff --git a/examples/023_selective_removal/roles/apache2/README.md b/examples/023_selective_removal/roles/apache2/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/023_selective_removal/roles/apache2/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/023_selective_removal/roles/apache2/defaults/main.yml b/examples/023_selective_removal/roles/apache2/defaults/main.yml new file mode 100644 index 0000000..0381169 --- /dev/null +++ b/examples/023_selective_removal/roles/apache2/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for apache2 diff --git a/examples/023_selective_removal/roles/apache2/handlers/main.yml b/examples/023_selective_removal/roles/apache2/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/023_selective_removal/roles/apache2/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/023_selective_removal/roles/apache2/meta/main.yml b/examples/023_selective_removal/roles/apache2/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/023_selective_removal/roles/apache2/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/023_selective_removal/roles/apache2/tasks/main.yml b/examples/023_selective_removal/roles/apache2/tasks/main.yml new file mode 100644 index 0000000..e1fd9a3 --- /dev/null +++ b/examples/023_selective_removal/roles/apache2/tasks/main.yml @@ -0,0 +1,17 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + +- name: ensure mod_wsgi enabled + apache2_module: state=present name=wsgi + notify: restart apache2 + +- name: de-activate default apache site + file: path=/etc/apache2/sites-enabled/000-default.conf state=absent + notify: restart apache2 + +- name: ensure apache2 started + service: name=apache2 state=started enabled=yes diff --git a/examples/023_selective_removal/roles/apache2/vars/main.yml b/examples/023_selective_removal/roles/apache2/vars/main.yml new file mode 100644 index 0000000..5d23ceb --- /dev/null +++ b/examples/023_selective_removal/roles/apache2/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for apache2 diff --git a/examples/023_selective_removal/roles/control/README.md b/examples/023_selective_removal/roles/control/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/023_selective_removal/roles/control/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/023_selective_removal/roles/control/defaults/main.yml b/examples/023_selective_removal/roles/control/defaults/main.yml new file mode 100644 index 0000000..9fe52bd --- /dev/null +++ b/examples/023_selective_removal/roles/control/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for control diff --git a/examples/023_selective_removal/roles/control/handlers/main.yml b/examples/023_selective_removal/roles/control/handlers/main.yml new file mode 100644 index 0000000..4136893 --- /dev/null +++ b/examples/023_selective_removal/roles/control/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for control diff --git a/examples/023_selective_removal/roles/control/meta/main.yml b/examples/023_selective_removal/roles/control/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/023_selective_removal/roles/control/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/023_selective_removal/roles/control/tasks/main.yml b/examples/023_selective_removal/roles/control/tasks/main.yml new file mode 100644 index 0000000..330e91c --- /dev/null +++ b/examples/023_selective_removal/roles/control/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl + - python-httplib2 diff --git a/examples/023_selective_removal/roles/control/vars/main.yml b/examples/023_selective_removal/roles/control/vars/main.yml new file mode 100644 index 0000000..eadc8b6 --- /dev/null +++ b/examples/023_selective_removal/roles/control/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for control diff --git a/examples/023_selective_removal/roles/demo_app/README.md b/examples/023_selective_removal/roles/demo_app/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/023_selective_removal/roles/demo_app/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/023_selective_removal/roles/demo_app/defaults/main.yml b/examples/023_selective_removal/roles/demo_app/defaults/main.yml new file mode 100644 index 0000000..914e957 --- /dev/null +++ b/examples/023_selective_removal/roles/demo_app/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for demo_app diff --git a/examples/023_selective_removal/roles/demo_app/files/demo/app/demo.py b/examples/023_selective_removal/roles/demo_app/files/demo/app/demo.py new file mode 100644 index 0000000..05874b6 --- /dev/null +++ b/examples/023_selective_removal/roles/demo_app/files/demo/app/demo.py @@ -0,0 +1,23 @@ +from flask import Flask +from flask.ext.sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + #try: + # db.create_all() + #except Exception as e: + # return e.message + '\n' + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() diff --git a/examples/023_selective_removal/roles/demo_app/files/demo/app/demo.wsgi b/examples/023_selective_removal/roles/demo_app/files/demo/app/demo.wsgi new file mode 100644 index 0000000..d3e3543 --- /dev/null +++ b/examples/023_selective_removal/roles/demo_app/files/demo/app/demo.wsgi @@ -0,0 +1,11 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +#execfile(activate_this, dict(__file__=activate_this)) +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application diff --git a/examples/023_selective_removal/roles/demo_app/files/demo/app/requirements.txt b/examples/023_selective_removal/roles/demo_app/files/demo/app/requirements.txt new file mode 100644 index 0000000..451ff90 --- /dev/null +++ b/examples/023_selective_removal/roles/demo_app/files/demo/app/requirements.txt @@ -0,0 +1,2 @@ +Flask==0.10.1 +Flask-SQLAlchemy==2.0 diff --git a/examples/023_selective_removal/roles/demo_app/files/demo/demo.conf b/examples/023_selective_removal/roles/demo_app/files/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/023_selective_removal/roles/demo_app/files/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/023_selective_removal/roles/demo_app/handlers/main.yml b/examples/023_selective_removal/roles/demo_app/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/023_selective_removal/roles/demo_app/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/023_selective_removal/roles/demo_app/meta/main.yml b/examples/023_selective_removal/roles/demo_app/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/023_selective_removal/roles/demo_app/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/023_selective_removal/roles/demo_app/tasks/main.yml b/examples/023_selective_removal/roles/demo_app/tasks/main.yml new file mode 100644 index 0000000..c5e1f3a --- /dev/null +++ b/examples/023_selective_removal/roles/demo_app/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - python-pip-whl + - python3-virtualenv + - python3-mysqldb + +- 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: activate demo apache site + file: src=/etc/apache2/sites-available/demo.conf dest=/etc/apache2/sites-enabled/demo.conf state=link + notify: restart apache2 diff --git a/examples/023_selective_removal/roles/demo_app/vars/main.yml b/examples/023_selective_removal/roles/demo_app/vars/main.yml new file mode 100644 index 0000000..52fb613 --- /dev/null +++ b/examples/023_selective_removal/roles/demo_app/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for demo_app diff --git a/examples/023_selective_removal/roles/mysql/README.md b/examples/023_selective_removal/roles/mysql/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/023_selective_removal/roles/mysql/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/023_selective_removal/roles/mysql/defaults/main.yml b/examples/023_selective_removal/roles/mysql/defaults/main.yml new file mode 100644 index 0000000..2ea6760 --- /dev/null +++ b/examples/023_selective_removal/roles/mysql/defaults/main.yml @@ -0,0 +1,5 @@ +--- +db_name: myapp +db_user_name: dbuser +db_user_pass: dbpass +db_user_host: localhost diff --git a/examples/023_selective_removal/roles/mysql/handlers/main.yml b/examples/023_selective_removal/roles/mysql/handlers/main.yml new file mode 100644 index 0000000..3755d8c --- /dev/null +++ b/examples/023_selective_removal/roles/mysql/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart mysql + service: name=mysql state=restarted diff --git a/examples/023_selective_removal/roles/mysql/meta/main.yml b/examples/023_selective_removal/roles/mysql/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/023_selective_removal/roles/mysql/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/023_selective_removal/roles/mysql/tasks/main.yml b/examples/023_selective_removal/roles/mysql/tasks/main.yml new file mode 100644 index 0000000..35b2fd3 --- /dev/null +++ b/examples/023_selective_removal/roles/mysql/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python3-mysqldb + +- name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + +- name: ensure mysql listening on all ports + lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address + line="bind-address = {{ ansible_eth0.ipv4.address }}" + notify: restart mysql + +- name: ensure mysql started + service: name=mysql state=started enabled=yes + +- name: create database + mysql_db: name={{ db_name }} state=present + +- name: create user + mysql_user: name={{ db_user_name }} password={{ db_user_pass }} priv={{ db_name }}.*:ALL + host='{{ db_user_host }}' state=present diff --git a/examples/023_selective_removal/roles/mysql/vars/main.yml b/examples/023_selective_removal/roles/mysql/vars/main.yml new file mode 100644 index 0000000..a79bfed --- /dev/null +++ b/examples/023_selective_removal/roles/mysql/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for mysql diff --git a/examples/023_selective_removal/roles/nginx/README.md b/examples/023_selective_removal/roles/nginx/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/023_selective_removal/roles/nginx/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/023_selective_removal/roles/nginx/defaults/main.yml b/examples/023_selective_removal/roles/nginx/defaults/main.yml new file mode 100644 index 0000000..45a7ecc --- /dev/null +++ b/examples/023_selective_removal/roles/nginx/defaults/main.yml @@ -0,0 +1,5 @@ +--- +sites: + myapp20211216: + frontend: 80 + backend: 80 diff --git a/examples/023_selective_removal/roles/nginx/handlers/main.yml b/examples/023_selective_removal/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..92971d2 --- /dev/null +++ b/examples/023_selective_removal/roles/nginx/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart nginx + service: name=nginx state=restarted diff --git a/examples/023_selective_removal/roles/nginx/meta/main.yml b/examples/023_selective_removal/roles/nginx/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/023_selective_removal/roles/nginx/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/023_selective_removal/roles/nginx/tasks/main.yml b/examples/023_selective_removal/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..f69ee18 --- /dev/null +++ b/examples/023_selective_removal/roles/nginx/tasks/main.yml @@ -0,0 +1,31 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python-httplib2 + +- name: install nginx + apt: name=nginx state=present update_cache=yes + +- name: configure nginx sites + template: src=nginx.conf.j2 dest=/etc/nginx/sites-available/{{ item.key }} mode=0644 + with_dict: "{{ sites }}" + notify: restart nginx + +- name: get active sites + shell: ls /etc/nginx/sites-enabled + register: result + +- name: de-activate sites + file: path=/etc/nginx/sites-enabled/{{ item }} state=absent + with_items: "{{ result.stdout_lines }}" + when: item not in sites + notify: restart nginx + +- name: activate nginx sites + file: src=/etc/nginx/sites-available/{{ item.key }} dest=/etc/nginx/sites-enabled/{{ item.key }} state=link + with_dict: "{{ sites }}" + notify: restart nginx + +- name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/023_selective_removal/roles/nginx/templates/nginx.conf.j2 b/examples/023_selective_removal/roles/nginx/templates/nginx.conf.j2 new file mode 100644 index 0000000..092c8be --- /dev/null +++ b/examples/023_selective_removal/roles/nginx/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream {{ item.key }} { +{% for server in groups.webserver %} + server {{ server }}:{{ item.value.backend }}; +{% endfor %} +} + +server { + listen {{ item.value.frontend }}; + + location / { + proxy_pass http://{{ item.key }}; + } +} diff --git a/examples/023_selective_removal/roles/nginx/vars/main.yml b/examples/023_selective_removal/roles/nginx/vars/main.yml new file mode 100644 index 0000000..d45faf6 --- /dev/null +++ b/examples/023_selective_removal/roles/nginx/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for nginx diff --git a/examples/023_selective_removal/site.yml b/examples/023_selective_removal/site.yml new file mode 100644 index 0000000..7299e9e --- /dev/null +++ b/examples/023_selective_removal/site.yml @@ -0,0 +1,6 @@ +--- +- include: control.yml +- include: database.yml +- include: webserver.yml +- include: loadbalancer.yml +- include: playbooks/stack_status.yml diff --git a/examples/023_selective_removal/webserver.yml b/examples/023_selective_removal/webserver.yml new file mode 100644 index 0000000..195ec7f --- /dev/null +++ b/examples/023_selective_removal/webserver.yml @@ -0,0 +1,6 @@ +--- +- hosts: webserver + become: true + roles: + - apache2 + - demo_app diff --git a/examples/024_continued/control.yml b/examples/024_continued/control.yml new file mode 100644 index 0000000..c6a8d81 --- /dev/null +++ b/examples/024_continued/control.yml @@ -0,0 +1,5 @@ +--- +- hosts: control + become: true + roles: + - control diff --git a/examples/024_continued/database.yml b/examples/024_continued/database.yml new file mode 100644 index 0000000..fee12fa --- /dev/null +++ b/examples/024_continued/database.yml @@ -0,0 +1,5 @@ +--- +- hosts: database + become: true + roles: + - { role: mysql, db_name: demo, db_user_name: demo, db_user_pass: demo, db_user_host: '%' } diff --git a/examples/024_continued/demo/app/demo.py b/examples/024_continued/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/024_continued/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/024_continued/demo/app/demo.wsgi b/examples/024_continued/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/024_continued/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/024_continued/demo/app/requirements.txt b/examples/024_continued/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/024_continued/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/024_continued/demo/demo.conf b/examples/024_continued/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/024_continued/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/024_continued/loadbalancer.yml b/examples/024_continued/loadbalancer.yml new file mode 100644 index 0000000..651bc7d --- /dev/null +++ b/examples/024_continued/loadbalancer.yml @@ -0,0 +1,5 @@ +--- +- hosts: loadbalancer + become: true + roles: + - nginx diff --git a/examples/024_continued/playbooks/hostname.yml b/examples/024_continued/playbooks/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/024_continued/playbooks/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/024_continued/playbooks/stack_restart.yml b/examples/024_continued/playbooks/stack_restart.yml new file mode 100644 index 0000000..d89c326 --- /dev/null +++ b/examples/024_continued/playbooks/stack_restart.yml @@ -0,0 +1,33 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + - wait_for: port=80 state=drained + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + - wait_for: port=80 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + - wait_for: host={{ ansible_eth0.ipv4.address }} port=3306 state=started + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + - wait_for: port=80 + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started + - wait_for: port=80 diff --git a/examples/024_continued/playbooks/stack_status.yml b/examples/024_continued/playbooks/stack_status.yml new file mode 100644 index 0000000..0676295 --- /dev/null +++ b/examples/024_continued/playbooks/stack_status.yml @@ -0,0 +1,67 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: verify nginx service + command: service nginx status + + - name: verify nginx is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: webserver + become: true + tasks: + - name: verify apache2 service + command: service apache2 status + + - name: verify apache2 is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: database + become: true + tasks: + - name: verify mysql service + command: service mysql status + + - name: verify mysql is listening on 3306 + wait_for: port=3306 timeout=1 + +- hosts: control + tasks: + - name: verify end-to-end index response + uri: url=http://{{item}} return_content=yes + with_items: 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}}" + + - name: verify end-to-end db response + uri: url=http://{{item}}/db return_content=yes + with_items: 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}}" + +- hosts: loadbalancer + tasks: + - name: verify backend index response + uri: url=http://{{item}} return_content=yes + with_items: 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}}" + + - name: verify backend db response + uri: url=http://{{item}}/db return_content=yes + with_items: 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}}" diff --git a/examples/024_continued/roles/apache2/README.md b/examples/024_continued/roles/apache2/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/024_continued/roles/apache2/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/024_continued/roles/apache2/defaults/main.yml b/examples/024_continued/roles/apache2/defaults/main.yml new file mode 100644 index 0000000..0381169 --- /dev/null +++ b/examples/024_continued/roles/apache2/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for apache2 diff --git a/examples/024_continued/roles/apache2/handlers/main.yml b/examples/024_continued/roles/apache2/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/024_continued/roles/apache2/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/024_continued/roles/apache2/meta/main.yml b/examples/024_continued/roles/apache2/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/024_continued/roles/apache2/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/024_continued/roles/apache2/tasks/main.yml b/examples/024_continued/roles/apache2/tasks/main.yml new file mode 100644 index 0000000..2d0632f --- /dev/null +++ b/examples/024_continued/roles/apache2/tasks/main.yml @@ -0,0 +1,17 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi + +- name: ensure mod_wsgi enabled + apache2_module: state=present name=wsgi + notify: restart apache2 + +- name: de-activate default apache site + file: path=/etc/apache2/sites-enabled/000-default.conf state=absent + notify: restart apache2 + +- name: ensure apache2 started + service: name=apache2 state=started enabled=yes diff --git a/examples/024_continued/roles/apache2/vars/main.yml b/examples/024_continued/roles/apache2/vars/main.yml new file mode 100644 index 0000000..5d23ceb --- /dev/null +++ b/examples/024_continued/roles/apache2/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for apache2 diff --git a/examples/024_continued/roles/control/README.md b/examples/024_continued/roles/control/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/024_continued/roles/control/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/024_continued/roles/control/defaults/main.yml b/examples/024_continued/roles/control/defaults/main.yml new file mode 100644 index 0000000..9fe52bd --- /dev/null +++ b/examples/024_continued/roles/control/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for control diff --git a/examples/024_continued/roles/control/handlers/main.yml b/examples/024_continued/roles/control/handlers/main.yml new file mode 100644 index 0000000..4136893 --- /dev/null +++ b/examples/024_continued/roles/control/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for control diff --git a/examples/024_continued/roles/control/meta/main.yml b/examples/024_continued/roles/control/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/024_continued/roles/control/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/024_continued/roles/control/tasks/main.yml b/examples/024_continued/roles/control/tasks/main.yml new file mode 100644 index 0000000..330e91c --- /dev/null +++ b/examples/024_continued/roles/control/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl + - python-httplib2 diff --git a/examples/024_continued/roles/control/vars/main.yml b/examples/024_continued/roles/control/vars/main.yml new file mode 100644 index 0000000..eadc8b6 --- /dev/null +++ b/examples/024_continued/roles/control/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for control diff --git a/examples/024_continued/roles/demo_app/README.md b/examples/024_continued/roles/demo_app/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/024_continued/roles/demo_app/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/024_continued/roles/demo_app/defaults/main.yml b/examples/024_continued/roles/demo_app/defaults/main.yml new file mode 100644 index 0000000..914e957 --- /dev/null +++ b/examples/024_continued/roles/demo_app/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for demo_app diff --git a/examples/024_continued/roles/demo_app/files/demo/app/demo.py b/examples/024_continued/roles/demo_app/files/demo/app/demo.py new file mode 100644 index 0000000..f7897f0 --- /dev/null +++ b/examples/024_continued/roles/demo_app/files/demo/app/demo.py @@ -0,0 +1,23 @@ +from flask import Flask +from flask.ext.sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + try: + db.create_all() + except Exception as e: + return e.message + '\n' + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() diff --git a/examples/024_continued/roles/demo_app/files/demo/app/requirements.txt b/examples/024_continued/roles/demo_app/files/demo/app/requirements.txt new file mode 100644 index 0000000..451ff90 --- /dev/null +++ b/examples/024_continued/roles/demo_app/files/demo/app/requirements.txt @@ -0,0 +1,2 @@ +Flask==0.10.1 +Flask-SQLAlchemy==2.0 diff --git a/examples/024_continued/roles/demo_app/files/demo/demo.conf b/examples/024_continued/roles/demo_app/files/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/024_continued/roles/demo_app/files/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/024_continued/roles/demo_app/handlers/main.yml b/examples/024_continued/roles/demo_app/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/024_continued/roles/demo_app/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/024_continued/roles/demo_app/meta/main.yml b/examples/024_continued/roles/demo_app/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/024_continued/roles/demo_app/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/024_continued/roles/demo_app/tasks/main.yml b/examples/024_continued/roles/demo_app/tasks/main.yml new file mode 100644 index 0000000..05a3d67 --- /dev/null +++ b/examples/024_continued/roles/demo_app/tasks/main.yml @@ -0,0 +1,27 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - python-pip-whl + - python3-virtualenv + - python3-mysqldb + +- name: copy demo app source + copy: src=demo/app/ dest=/var/www/demo mode=0755 + notify: restart apache2 + +- name: copy demo.wsgi + template: src=demo.wsgi.j2 dest=/var/www/demo/demo.wsgi 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: activate demo apache site + file: src=/etc/apache2/sites-available/demo.conf dest=/etc/apache2/sites-enabled/demo.conf state=link + notify: restart apache2 diff --git a/examples/024_continued/roles/demo_app/templates/demo.wsgi.j2 b/examples/024_continued/roles/demo_app/templates/demo.wsgi.j2 new file mode 100644 index 0000000..9232790 --- /dev/null +++ b/examples/024_continued/roles/demo_app/templates/demo.wsgi.j2 @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://{{ db_user }}:{{ db_pass }}@db01/{{ db_name }}' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application diff --git a/examples/024_continued/roles/demo_app/vars/main.yml b/examples/024_continued/roles/demo_app/vars/main.yml new file mode 100644 index 0000000..52fb613 --- /dev/null +++ b/examples/024_continued/roles/demo_app/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for demo_app diff --git a/examples/024_continued/roles/mysql/README.md b/examples/024_continued/roles/mysql/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/024_continued/roles/mysql/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/024_continued/roles/mysql/defaults/main.yml b/examples/024_continued/roles/mysql/defaults/main.yml new file mode 100644 index 0000000..2ea6760 --- /dev/null +++ b/examples/024_continued/roles/mysql/defaults/main.yml @@ -0,0 +1,5 @@ +--- +db_name: myapp +db_user_name: dbuser +db_user_pass: dbpass +db_user_host: localhost diff --git a/examples/024_continued/roles/mysql/handlers/main.yml b/examples/024_continued/roles/mysql/handlers/main.yml new file mode 100644 index 0000000..3755d8c --- /dev/null +++ b/examples/024_continued/roles/mysql/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart mysql + service: name=mysql state=restarted diff --git a/examples/024_continued/roles/mysql/meta/main.yml b/examples/024_continued/roles/mysql/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/024_continued/roles/mysql/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/024_continued/roles/mysql/tasks/main.yml b/examples/024_continued/roles/mysql/tasks/main.yml new file mode 100644 index 0000000..c8f006c --- /dev/null +++ b/examples/024_continued/roles/mysql/tasks/main.yml @@ -0,0 +1,24 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python3-mysqldb + - mysql-server + +- name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + +- name: ensure mysql listening on all ports + lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address + line="bind-address = {{ groups.database[0] }}" + notify: restart mysql + +- name: ensure mysql started + service: name=mysql state=started enabled=yes + +- name: create database + mysql_db: name={{ db_name }} state=present + +- name: create user + mysql_user: name={{ db_user_name }} password={{ db_user_pass }} priv={{ db_name }}.*:ALL + host='{{ db_user_host }}' state=present diff --git a/examples/024_continued/roles/mysql/vars/main.yml b/examples/024_continued/roles/mysql/vars/main.yml new file mode 100644 index 0000000..a79bfed --- /dev/null +++ b/examples/024_continued/roles/mysql/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for mysql diff --git a/examples/024_continued/roles/nginx/README.md b/examples/024_continued/roles/nginx/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/024_continued/roles/nginx/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/024_continued/roles/nginx/defaults/main.yml b/examples/024_continued/roles/nginx/defaults/main.yml new file mode 100644 index 0000000..0661d5d --- /dev/null +++ b/examples/024_continued/roles/nginx/defaults/main.yml @@ -0,0 +1,5 @@ +--- +sites: + myapp: + frontend: 80 + backend: 80 diff --git a/examples/024_continued/roles/nginx/handlers/main.yml b/examples/024_continued/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..92971d2 --- /dev/null +++ b/examples/024_continued/roles/nginx/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart nginx + service: name=nginx state=restarted diff --git a/examples/024_continued/roles/nginx/meta/main.yml b/examples/024_continued/roles/nginx/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/024_continued/roles/nginx/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/024_continued/roles/nginx/tasks/main.yml b/examples/024_continued/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..5e3e63a --- /dev/null +++ b/examples/024_continued/roles/nginx/tasks/main.yml @@ -0,0 +1,31 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python-httplib2 + +- name: install nginx + apt: name=nginx state=present update_cache=yes + +- name: configure nginx sites + template: src=nginx.conf.j2 dest=/etc/nginx/sites-available/{{ item.key }} mode=0644 + with_dict: "{{ sites }}" + notify: restart nginx + +- name: get active sites + shell: ls /etc/nginx/sites-enabled + register: active + +- name: de-activate sites + file: path=/etc/nginx/sites-enabled/{{ item }} state=absent + with_items: "{{ active.stdout_lines }}" + when: item not in sites + notify: restart nginx + +- name: activate nginx sites + file: src=/etc/nginx/sites-available/{{ item.key }} dest=/etc/nginx/sites-enabled/{{ item.key }} state=link + with_dict: "{{ sites }}" + notify: restart nginx + +- name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/024_continued/roles/nginx/templates/nginx.conf.j2 b/examples/024_continued/roles/nginx/templates/nginx.conf.j2 new file mode 100644 index 0000000..092c8be --- /dev/null +++ b/examples/024_continued/roles/nginx/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream {{ item.key }} { +{% for server in groups.webserver %} + server {{ server }}:{{ item.value.backend }}; +{% endfor %} +} + +server { + listen {{ item.value.frontend }}; + + location / { + proxy_pass http://{{ item.key }}; + } +} diff --git a/examples/024_continued/roles/nginx/vars/main.yml b/examples/024_continued/roles/nginx/vars/main.yml new file mode 100644 index 0000000..d45faf6 --- /dev/null +++ b/examples/024_continued/roles/nginx/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for nginx diff --git a/examples/024_continued/site.yml b/examples/024_continued/site.yml new file mode 100644 index 0000000..7299e9e --- /dev/null +++ b/examples/024_continued/site.yml @@ -0,0 +1,6 @@ +--- +- include: control.yml +- include: database.yml +- include: webserver.yml +- include: loadbalancer.yml +- include: playbooks/stack_status.yml diff --git a/examples/024_continued/webserver.yml b/examples/024_continued/webserver.yml new file mode 100644 index 0000000..e860380 --- /dev/null +++ b/examples/024_continued/webserver.yml @@ -0,0 +1,6 @@ +--- +- hosts: webserver + become: true + roles: + - apache2 + - { role: demo_app, db_user: demo, db_pass: demo, db_name: demo } diff --git a/examples/025_vars_files_group_vars/control.yml b/examples/025_vars_files_group_vars/control.yml new file mode 100644 index 0000000..c6a8d81 --- /dev/null +++ b/examples/025_vars_files_group_vars/control.yml @@ -0,0 +1,5 @@ +--- +- hosts: control + become: true + roles: + - control diff --git a/examples/025_vars_files_group_vars/database.yml b/examples/025_vars_files_group_vars/database.yml new file mode 100644 index 0000000..6d7b7eb --- /dev/null +++ b/examples/025_vars_files_group_vars/database.yml @@ -0,0 +1,8 @@ +--- +- hosts: database + become: true + roles: + - role: mysql + db_user_name: "{{ db_user }}" + db_user_pass: "{{ db_pass }}" + db_user_host: '%' diff --git a/examples/025_vars_files_group_vars/group_vars/all b/examples/025_vars_files_group_vars/group_vars/all new file mode 100644 index 0000000..2fd732e --- /dev/null +++ b/examples/025_vars_files_group_vars/group_vars/all @@ -0,0 +1,12 @@ +--- +#DB from role mysql +db_name: maykadb +db_user: mayka_user +db_pass: mayka_pass +db_user_host: localhost + +#nginx loadbalancer configuration +sites: + myappmayka: + frontend: 80 + backend: 80 diff --git a/examples/025_vars_files_group_vars/loadbalancer.yml b/examples/025_vars_files_group_vars/loadbalancer.yml new file mode 100644 index 0000000..651bc7d --- /dev/null +++ b/examples/025_vars_files_group_vars/loadbalancer.yml @@ -0,0 +1,5 @@ +--- +- hosts: loadbalancer + become: true + roles: + - nginx diff --git a/examples/025_vars_files_group_vars/playbooks/hostname.yml b/examples/025_vars_files_group_vars/playbooks/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/025_vars_files_group_vars/playbooks/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/025_vars_files_group_vars/playbooks/stack_restart.yml b/examples/025_vars_files_group_vars/playbooks/stack_restart.yml new file mode 100644 index 0000000..d89c326 --- /dev/null +++ b/examples/025_vars_files_group_vars/playbooks/stack_restart.yml @@ -0,0 +1,33 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + - wait_for: port=80 state=drained + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + - wait_for: port=80 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + - wait_for: host={{ ansible_eth0.ipv4.address }} port=3306 state=started + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + - wait_for: port=80 + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started + - wait_for: port=80 diff --git a/examples/025_vars_files_group_vars/playbooks/stack_status.yml b/examples/025_vars_files_group_vars/playbooks/stack_status.yml new file mode 100644 index 0000000..2abc0ea --- /dev/null +++ b/examples/025_vars_files_group_vars/playbooks/stack_status.yml @@ -0,0 +1,67 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: verify nginx service + command: service nginx status + + - name: verify nginx is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: webserver + become: true + tasks: + - name: verify apache2 service + command: service apache2 status + + - name: verify apache2 is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: database + become: true + tasks: + - name: verify mysql service + command: service mysql status + + - name: verify mysql is listening on 3306 + wait_for: port=3306 timeout=1 + +- hosts: control + tasks: + - name: verify end-to-end index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ 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}}" + + - name: verify end-to-end db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ 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}}" + +- hosts: loadbalancer + tasks: + - name: verify backend index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ groups.webserver }}" + register: app_index + +# - fail: msg="index failed to return content" +# when: "'Hello, from sunny {{ item.content }}!' not in item.content" +# with_items: "{{app_index.results}}" + + - name: verify backend db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ 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}}" diff --git a/examples/025_vars_files_group_vars/roles/apache2/README.md b/examples/025_vars_files_group_vars/roles/apache2/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/apache2/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/025_vars_files_group_vars/roles/apache2/defaults/main.yml b/examples/025_vars_files_group_vars/roles/apache2/defaults/main.yml new file mode 100644 index 0000000..0381169 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/apache2/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for apache2 diff --git a/examples/025_vars_files_group_vars/roles/apache2/handlers/main.yml b/examples/025_vars_files_group_vars/roles/apache2/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/apache2/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/025_vars_files_group_vars/roles/apache2/meta/main.yml b/examples/025_vars_files_group_vars/roles/apache2/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/apache2/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/025_vars_files_group_vars/roles/apache2/tasks/main.yml b/examples/025_vars_files_group_vars/roles/apache2/tasks/main.yml new file mode 100644 index 0000000..e1fd9a3 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/apache2/tasks/main.yml @@ -0,0 +1,17 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + +- name: ensure mod_wsgi enabled + apache2_module: state=present name=wsgi + notify: restart apache2 + +- name: de-activate default apache site + file: path=/etc/apache2/sites-enabled/000-default.conf state=absent + notify: restart apache2 + +- name: ensure apache2 started + service: name=apache2 state=started enabled=yes diff --git a/examples/025_vars_files_group_vars/roles/apache2/vars/main.yml b/examples/025_vars_files_group_vars/roles/apache2/vars/main.yml new file mode 100644 index 0000000..5d23ceb --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/apache2/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for apache2 diff --git a/examples/025_vars_files_group_vars/roles/control/README.md b/examples/025_vars_files_group_vars/roles/control/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/control/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/025_vars_files_group_vars/roles/control/defaults/main.yml b/examples/025_vars_files_group_vars/roles/control/defaults/main.yml new file mode 100644 index 0000000..9fe52bd --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/control/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for control diff --git a/examples/025_vars_files_group_vars/roles/control/handlers/main.yml b/examples/025_vars_files_group_vars/roles/control/handlers/main.yml new file mode 100644 index 0000000..4136893 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/control/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for control diff --git a/examples/025_vars_files_group_vars/roles/control/meta/main.yml b/examples/025_vars_files_group_vars/roles/control/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/control/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/025_vars_files_group_vars/roles/control/tasks/main.yml b/examples/025_vars_files_group_vars/roles/control/tasks/main.yml new file mode 100644 index 0000000..330e91c --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/control/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl + - python-httplib2 diff --git a/examples/025_vars_files_group_vars/roles/control/vars/main.yml b/examples/025_vars_files_group_vars/roles/control/vars/main.yml new file mode 100644 index 0000000..eadc8b6 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/control/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for control diff --git a/examples/025_vars_files_group_vars/roles/demo_app/README.md b/examples/025_vars_files_group_vars/roles/demo_app/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/demo_app/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/025_vars_files_group_vars/roles/demo_app/defaults/main.yml b/examples/025_vars_files_group_vars/roles/demo_app/defaults/main.yml new file mode 100644 index 0000000..914e957 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/demo_app/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for demo_app diff --git a/examples/025_vars_files_group_vars/roles/demo_app/files/demo/app/demo.py b/examples/025_vars_files_group_vars/roles/demo_app/files/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/demo_app/files/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/025_vars_files_group_vars/roles/demo_app/files/demo/app/demo.wsgi b/examples/025_vars_files_group_vars/roles/demo_app/files/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/demo_app/files/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/025_vars_files_group_vars/roles/demo_app/files/demo/app/requirements.txt b/examples/025_vars_files_group_vars/roles/demo_app/files/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/demo_app/files/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/025_vars_files_group_vars/roles/demo_app/files/demo/demo.conf b/examples/025_vars_files_group_vars/roles/demo_app/files/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/demo_app/files/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/025_vars_files_group_vars/roles/demo_app/handlers/main.yml b/examples/025_vars_files_group_vars/roles/demo_app/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/demo_app/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/025_vars_files_group_vars/roles/demo_app/meta/main.yml b/examples/025_vars_files_group_vars/roles/demo_app/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/demo_app/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/025_vars_files_group_vars/roles/demo_app/tasks/main.yml b/examples/025_vars_files_group_vars/roles/demo_app/tasks/main.yml new file mode 100644 index 0000000..05a3d67 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/demo_app/tasks/main.yml @@ -0,0 +1,27 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - python-pip-whl + - python3-virtualenv + - python3-mysqldb + +- name: copy demo app source + copy: src=demo/app/ dest=/var/www/demo mode=0755 + notify: restart apache2 + +- name: copy demo.wsgi + template: src=demo.wsgi.j2 dest=/var/www/demo/demo.wsgi 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: activate demo apache site + file: src=/etc/apache2/sites-available/demo.conf dest=/etc/apache2/sites-enabled/demo.conf state=link + notify: restart apache2 diff --git a/examples/025_vars_files_group_vars/roles/demo_app/templates/demo.wsgi.j2 b/examples/025_vars_files_group_vars/roles/demo_app/templates/demo.wsgi.j2 new file mode 100644 index 0000000..7d65a51 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/demo_app/templates/demo.wsgi.j2 @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://{{ db_user }}:{{ db_pass }}@{{ groups.database[0] }}/{{ db_name }}' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application diff --git a/examples/025_vars_files_group_vars/roles/demo_app/vars/main.yml b/examples/025_vars_files_group_vars/roles/demo_app/vars/main.yml new file mode 100644 index 0000000..52fb613 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/demo_app/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for demo_app diff --git a/examples/025_vars_files_group_vars/roles/mysql/README.md b/examples/025_vars_files_group_vars/roles/mysql/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/mysql/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/025_vars_files_group_vars/roles/mysql/defaults/main.yml b/examples/025_vars_files_group_vars/roles/mysql/defaults/main.yml new file mode 100644 index 0000000..eefca51 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/mysql/defaults/main.yml @@ -0,0 +1,5 @@ +--- +#db_name: myapp +#db_user_name: dbuser +#db_user_pass: dbpass +#db_user_host: localhost diff --git a/examples/025_vars_files_group_vars/roles/mysql/handlers/main.yml b/examples/025_vars_files_group_vars/roles/mysql/handlers/main.yml new file mode 100644 index 0000000..3755d8c --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/mysql/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart mysql + service: name=mysql state=restarted diff --git a/examples/025_vars_files_group_vars/roles/mysql/meta/main.yml b/examples/025_vars_files_group_vars/roles/mysql/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/mysql/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/025_vars_files_group_vars/roles/mysql/tasks/main.yml b/examples/025_vars_files_group_vars/roles/mysql/tasks/main.yml new file mode 100644 index 0000000..9cf064a --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/mysql/tasks/main.yml @@ -0,0 +1,27 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python3-mysqldb + +- name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + +- name: chmod 777 /etc/mysql/my.cnf + command: chmod 777 /etc/mysql/my.cnf + notify: restart mysql + +- name: ensure mysql listening on all ports + lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address + line="bind-address = {{ ansible_eth0.ipv4.address }}" + notify: restart mysql + +- name: ensure mysql started + service: name=mysql state=started enabled=yes + +- name: create database + mysql_db: name={{ db_name }} state=present + +- name: create user + mysql_user: name={{ db_user_name }} password={{ db_user_pass }} priv={{ db_name }}.*:ALL + host='{{ db_user_host }}' state=present diff --git a/examples/025_vars_files_group_vars/roles/mysql/vars/main.yml b/examples/025_vars_files_group_vars/roles/mysql/vars/main.yml new file mode 100644 index 0000000..a79bfed --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/mysql/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for mysql diff --git a/examples/025_vars_files_group_vars/roles/nginx/README.md b/examples/025_vars_files_group_vars/roles/nginx/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/nginx/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/025_vars_files_group_vars/roles/nginx/defaults/main.yml b/examples/025_vars_files_group_vars/roles/nginx/defaults/main.yml new file mode 100644 index 0000000..5a53da8 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/nginx/defaults/main.yml @@ -0,0 +1,5 @@ +#--- +#sites: +# myapp: +# frontend: 80 +# backend: 80 diff --git a/examples/025_vars_files_group_vars/roles/nginx/handlers/main.yml b/examples/025_vars_files_group_vars/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..92971d2 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/nginx/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart nginx + service: name=nginx state=restarted diff --git a/examples/025_vars_files_group_vars/roles/nginx/meta/main.yml b/examples/025_vars_files_group_vars/roles/nginx/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/nginx/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/025_vars_files_group_vars/roles/nginx/tasks/main.yml b/examples/025_vars_files_group_vars/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..4147480 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/nginx/tasks/main.yml @@ -0,0 +1,35 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python-httplib2 + +- name: install nginx + apt: name=nginx state=present update_cache=yes + +- name: configure nginx sites + template: src=nginx.conf.j2 dest=/etc/nginx/sites-available/{{ item.key }} mode=0644 + with_dict: "{{ sites }}" + notify: restart nginx + +- name: get active sites + shell: ls /etc/nginx/sites-enabled + register: result + +- name: de-activate default + file: path=/etc/nginx/sites-enabled/default state=absent + notify: restart nginx + +- name: de-activate sites + file: path=/etc/nginx/sites-enabled/{{ item }} state=absent + with_items: "{{ result.stdout_lines }}" + when: item not in sites + notify: restart nginx + +- name: activate nginx sites + file: src=/etc/nginx/sites-available/{{ item.key }} dest=/etc/nginx/sites-enabled/{{ item.key }} state=link + with_dict: "{{ sites }}" + notify: restart nginx + +- name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/025_vars_files_group_vars/roles/nginx/templates/nginx.conf.j2 b/examples/025_vars_files_group_vars/roles/nginx/templates/nginx.conf.j2 new file mode 100644 index 0000000..092c8be --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/nginx/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream {{ item.key }} { +{% for server in groups.webserver %} + server {{ server }}:{{ item.value.backend }}; +{% endfor %} +} + +server { + listen {{ item.value.frontend }}; + + location / { + proxy_pass http://{{ item.key }}; + } +} diff --git a/examples/025_vars_files_group_vars/roles/nginx/vars/main.yml b/examples/025_vars_files_group_vars/roles/nginx/vars/main.yml new file mode 100644 index 0000000..d45faf6 --- /dev/null +++ b/examples/025_vars_files_group_vars/roles/nginx/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for nginx diff --git a/examples/025_vars_files_group_vars/site.yml b/examples/025_vars_files_group_vars/site.yml new file mode 100644 index 0000000..7299e9e --- /dev/null +++ b/examples/025_vars_files_group_vars/site.yml @@ -0,0 +1,6 @@ +--- +- include: control.yml +- include: database.yml +- include: webserver.yml +- include: loadbalancer.yml +- include: playbooks/stack_status.yml diff --git a/examples/025_vars_files_group_vars/webserver.yml b/examples/025_vars_files_group_vars/webserver.yml new file mode 100644 index 0000000..195ec7f --- /dev/null +++ b/examples/025_vars_files_group_vars/webserver.yml @@ -0,0 +1,6 @@ +--- +- hosts: webserver + become: true + roles: + - apache2 + - demo_app diff --git a/examples/026_vault/control.yml b/examples/026_vault/control.yml new file mode 100644 index 0000000..c6a8d81 --- /dev/null +++ b/examples/026_vault/control.yml @@ -0,0 +1,5 @@ +--- +- hosts: control + become: true + roles: + - control diff --git a/examples/026_vault/database.yml b/examples/026_vault/database.yml new file mode 100644 index 0000000..6d7b7eb --- /dev/null +++ b/examples/026_vault/database.yml @@ -0,0 +1,8 @@ +--- +- hosts: database + become: true + roles: + - role: mysql + db_user_name: "{{ db_user }}" + db_user_pass: "{{ db_pass }}" + db_user_host: '%' diff --git a/examples/026_vault/group_vars/all b/examples/026_vault/group_vars/all new file mode 100644 index 0000000..9a0f43e --- /dev/null +++ b/examples/026_vault/group_vars/all @@ -0,0 +1,15 @@ +$ANSIBLE_VAULT;1.1;AES256 +34663065306632666162353539363635666666653431636164316639303935613066643837303234 +3330306265323566313134623831613361336262666562340a383330396362383333383462336363 +37616534393332313163633063303436653862343431633834396538363739373435396338323162 +3230356333323765300a346436343931636134656237613633646662663637333635356563373565 +31343938333731316439353938646536333531313439643233393932303134383763376464336434 +63656634316561656337633566643430643634663333356231376534636138396533326462303836 +30336561623364643936336662616431383062636438366136313466396639633332383062313830 +34393836666638316233353563653265303264636333643139393563386362363031373362353435 +63373962343664373834333237333331393833646236386139633837303461626266383037303032 +33303230303864306639363936616635333436383431666435343931306531313461363664366632 +63363562326665646438636364303465303161633234333863653162643739653566626430386430 +32383266626237623739376233633434636362646630376139353364333835623532363164636565 +33633134636239333132353135623266393838653139656332383562653030346634306666363664 +3038366163306633326466393537353966656265386238363338 diff --git a/examples/026_vault/loadbalancer.yml b/examples/026_vault/loadbalancer.yml new file mode 100644 index 0000000..651bc7d --- /dev/null +++ b/examples/026_vault/loadbalancer.yml @@ -0,0 +1,5 @@ +--- +- hosts: loadbalancer + become: true + roles: + - nginx diff --git a/examples/026_vault/playbooks/hostname.yml b/examples/026_vault/playbooks/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/026_vault/playbooks/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/026_vault/playbooks/stack_restart.yml b/examples/026_vault/playbooks/stack_restart.yml new file mode 100644 index 0000000..d89c326 --- /dev/null +++ b/examples/026_vault/playbooks/stack_restart.yml @@ -0,0 +1,33 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + - wait_for: port=80 state=drained + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + - wait_for: port=80 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + - wait_for: host={{ ansible_eth0.ipv4.address }} port=3306 state=started + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + - wait_for: port=80 + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started + - wait_for: port=80 diff --git a/examples/026_vault/playbooks/stack_status.yml b/examples/026_vault/playbooks/stack_status.yml new file mode 100644 index 0000000..2abc0ea --- /dev/null +++ b/examples/026_vault/playbooks/stack_status.yml @@ -0,0 +1,67 @@ +--- +- hosts: loadbalancer + become: true + tasks: + - name: verify nginx service + command: service nginx status + + - name: verify nginx is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: webserver + become: true + tasks: + - name: verify apache2 service + command: service apache2 status + + - name: verify apache2 is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: database + become: true + tasks: + - name: verify mysql service + command: service mysql status + + - name: verify mysql is listening on 3306 + wait_for: port=3306 timeout=1 + +- hosts: control + tasks: + - name: verify end-to-end index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ 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}}" + + - name: verify end-to-end db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ 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}}" + +- hosts: loadbalancer + tasks: + - name: verify backend index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ groups.webserver }}" + register: app_index + +# - fail: msg="index failed to return content" +# when: "'Hello, from sunny {{ item.content }}!' not in item.content" +# with_items: "{{app_index.results}}" + + - name: verify backend db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ 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}}" diff --git a/examples/026_vault/roles/apache2/README.md b/examples/026_vault/roles/apache2/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/026_vault/roles/apache2/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/026_vault/roles/apache2/defaults/main.yml b/examples/026_vault/roles/apache2/defaults/main.yml new file mode 100644 index 0000000..0381169 --- /dev/null +++ b/examples/026_vault/roles/apache2/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for apache2 diff --git a/examples/026_vault/roles/apache2/handlers/main.yml b/examples/026_vault/roles/apache2/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/026_vault/roles/apache2/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/026_vault/roles/apache2/meta/main.yml b/examples/026_vault/roles/apache2/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/026_vault/roles/apache2/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/026_vault/roles/apache2/tasks/main.yml b/examples/026_vault/roles/apache2/tasks/main.yml new file mode 100644 index 0000000..e1fd9a3 --- /dev/null +++ b/examples/026_vault/roles/apache2/tasks/main.yml @@ -0,0 +1,17 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + +- name: ensure mod_wsgi enabled + apache2_module: state=present name=wsgi + notify: restart apache2 + +- name: de-activate default apache site + file: path=/etc/apache2/sites-enabled/000-default.conf state=absent + notify: restart apache2 + +- name: ensure apache2 started + service: name=apache2 state=started enabled=yes diff --git a/examples/026_vault/roles/apache2/vars/main.yml b/examples/026_vault/roles/apache2/vars/main.yml new file mode 100644 index 0000000..5d23ceb --- /dev/null +++ b/examples/026_vault/roles/apache2/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for apache2 diff --git a/examples/026_vault/roles/control/README.md b/examples/026_vault/roles/control/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/026_vault/roles/control/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/026_vault/roles/control/defaults/main.yml b/examples/026_vault/roles/control/defaults/main.yml new file mode 100644 index 0000000..9fe52bd --- /dev/null +++ b/examples/026_vault/roles/control/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for control diff --git a/examples/026_vault/roles/control/handlers/main.yml b/examples/026_vault/roles/control/handlers/main.yml new file mode 100644 index 0000000..4136893 --- /dev/null +++ b/examples/026_vault/roles/control/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for control diff --git a/examples/026_vault/roles/control/meta/main.yml b/examples/026_vault/roles/control/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/026_vault/roles/control/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/026_vault/roles/control/tasks/main.yml b/examples/026_vault/roles/control/tasks/main.yml new file mode 100644 index 0000000..330e91c --- /dev/null +++ b/examples/026_vault/roles/control/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl + - python-httplib2 diff --git a/examples/026_vault/roles/control/vars/main.yml b/examples/026_vault/roles/control/vars/main.yml new file mode 100644 index 0000000..eadc8b6 --- /dev/null +++ b/examples/026_vault/roles/control/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for control diff --git a/examples/026_vault/roles/demo_app/README.md b/examples/026_vault/roles/demo_app/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/026_vault/roles/demo_app/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/026_vault/roles/demo_app/defaults/main.yml b/examples/026_vault/roles/demo_app/defaults/main.yml new file mode 100644 index 0000000..914e957 --- /dev/null +++ b/examples/026_vault/roles/demo_app/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for demo_app diff --git a/examples/026_vault/roles/demo_app/files/demo/app/demo.py b/examples/026_vault/roles/demo_app/files/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/026_vault/roles/demo_app/files/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/026_vault/roles/demo_app/files/demo/app/demo.wsgi b/examples/026_vault/roles/demo_app/files/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/026_vault/roles/demo_app/files/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/026_vault/roles/demo_app/files/demo/app/requirements.txt b/examples/026_vault/roles/demo_app/files/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/026_vault/roles/demo_app/files/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/026_vault/roles/demo_app/files/demo/demo.conf b/examples/026_vault/roles/demo_app/files/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/026_vault/roles/demo_app/files/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/026_vault/roles/demo_app/handlers/main.yml b/examples/026_vault/roles/demo_app/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/026_vault/roles/demo_app/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/026_vault/roles/demo_app/meta/main.yml b/examples/026_vault/roles/demo_app/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/026_vault/roles/demo_app/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/026_vault/roles/demo_app/tasks/main.yml b/examples/026_vault/roles/demo_app/tasks/main.yml new file mode 100644 index 0000000..05a3d67 --- /dev/null +++ b/examples/026_vault/roles/demo_app/tasks/main.yml @@ -0,0 +1,27 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - python-pip-whl + - python3-virtualenv + - python3-mysqldb + +- name: copy demo app source + copy: src=demo/app/ dest=/var/www/demo mode=0755 + notify: restart apache2 + +- name: copy demo.wsgi + template: src=demo.wsgi.j2 dest=/var/www/demo/demo.wsgi 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: activate demo apache site + file: src=/etc/apache2/sites-available/demo.conf dest=/etc/apache2/sites-enabled/demo.conf state=link + notify: restart apache2 diff --git a/examples/026_vault/roles/demo_app/templates/demo.wsgi.j2 b/examples/026_vault/roles/demo_app/templates/demo.wsgi.j2 new file mode 100644 index 0000000..7d65a51 --- /dev/null +++ b/examples/026_vault/roles/demo_app/templates/demo.wsgi.j2 @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://{{ db_user }}:{{ db_pass }}@{{ groups.database[0] }}/{{ db_name }}' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application diff --git a/examples/026_vault/roles/demo_app/vars/main.yml b/examples/026_vault/roles/demo_app/vars/main.yml new file mode 100644 index 0000000..52fb613 --- /dev/null +++ b/examples/026_vault/roles/demo_app/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for demo_app diff --git a/examples/026_vault/roles/mysql/README.md b/examples/026_vault/roles/mysql/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/026_vault/roles/mysql/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/026_vault/roles/mysql/defaults/main.yml b/examples/026_vault/roles/mysql/defaults/main.yml new file mode 100644 index 0000000..eefca51 --- /dev/null +++ b/examples/026_vault/roles/mysql/defaults/main.yml @@ -0,0 +1,5 @@ +--- +#db_name: myapp +#db_user_name: dbuser +#db_user_pass: dbpass +#db_user_host: localhost diff --git a/examples/026_vault/roles/mysql/handlers/main.yml b/examples/026_vault/roles/mysql/handlers/main.yml new file mode 100644 index 0000000..3755d8c --- /dev/null +++ b/examples/026_vault/roles/mysql/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart mysql + service: name=mysql state=restarted diff --git a/examples/026_vault/roles/mysql/meta/main.yml b/examples/026_vault/roles/mysql/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/026_vault/roles/mysql/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/026_vault/roles/mysql/tasks/main.yml b/examples/026_vault/roles/mysql/tasks/main.yml new file mode 100644 index 0000000..9cf064a --- /dev/null +++ b/examples/026_vault/roles/mysql/tasks/main.yml @@ -0,0 +1,27 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python3-mysqldb + +- name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + +- name: chmod 777 /etc/mysql/my.cnf + command: chmod 777 /etc/mysql/my.cnf + notify: restart mysql + +- name: ensure mysql listening on all ports + lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address + line="bind-address = {{ ansible_eth0.ipv4.address }}" + notify: restart mysql + +- name: ensure mysql started + service: name=mysql state=started enabled=yes + +- name: create database + mysql_db: name={{ db_name }} state=present + +- name: create user + mysql_user: name={{ db_user_name }} password={{ db_user_pass }} priv={{ db_name }}.*:ALL + host='{{ db_user_host }}' state=present diff --git a/examples/026_vault/roles/mysql/vars/main.yml b/examples/026_vault/roles/mysql/vars/main.yml new file mode 100644 index 0000000..a79bfed --- /dev/null +++ b/examples/026_vault/roles/mysql/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for mysql diff --git a/examples/026_vault/roles/nginx/README.md b/examples/026_vault/roles/nginx/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/026_vault/roles/nginx/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/026_vault/roles/nginx/defaults/main.yml b/examples/026_vault/roles/nginx/defaults/main.yml new file mode 100644 index 0000000..5a53da8 --- /dev/null +++ b/examples/026_vault/roles/nginx/defaults/main.yml @@ -0,0 +1,5 @@ +#--- +#sites: +# myapp: +# frontend: 80 +# backend: 80 diff --git a/examples/026_vault/roles/nginx/handlers/main.yml b/examples/026_vault/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..92971d2 --- /dev/null +++ b/examples/026_vault/roles/nginx/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart nginx + service: name=nginx state=restarted diff --git a/examples/026_vault/roles/nginx/meta/main.yml b/examples/026_vault/roles/nginx/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/026_vault/roles/nginx/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/026_vault/roles/nginx/tasks/main.yml b/examples/026_vault/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..643cca3 --- /dev/null +++ b/examples/026_vault/roles/nginx/tasks/main.yml @@ -0,0 +1,35 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python-httplib2 + +- name: install nginx + apt: name=nginx state=present update_cache=yes + +- name: configure nginx sites + template: src=nginx.conf.j2 dest=/etc/nginx/sites-available/{{ item.key }} mode=0644 + with_dict: "{{ sites }}" + notify: restart nginx + +- name: get active sites + shell: ls -l /etc/nginx/sites-enabled + register: result + +- name: de-activate default + file: path=/etc/nginx/sites-enabled/default state=absent + notify: restart nginx + +- name: de-activate sites + file: path=/etc/nginx/sites-enabled/{{ item }} state=absent + with_items: active.stdout_lines + when: item not in sites + notify: restart nginx + +- name: activate nginx sites + file: src=/etc/nginx/sites-available/{{ item.key }} dest=/etc/nginx/sites-enabled/{{ item.key }} state=link + with_dict: "{{ sites }}" + notify: restart nginx + +- name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/026_vault/roles/nginx/templates/nginx.conf.j2 b/examples/026_vault/roles/nginx/templates/nginx.conf.j2 new file mode 100644 index 0000000..092c8be --- /dev/null +++ b/examples/026_vault/roles/nginx/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream {{ item.key }} { +{% for server in groups.webserver %} + server {{ server }}:{{ item.value.backend }}; +{% endfor %} +} + +server { + listen {{ item.value.frontend }}; + + location / { + proxy_pass http://{{ item.key }}; + } +} diff --git a/examples/026_vault/roles/nginx/vars/main.yml b/examples/026_vault/roles/nginx/vars/main.yml new file mode 100644 index 0000000..d45faf6 --- /dev/null +++ b/examples/026_vault/roles/nginx/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for nginx diff --git a/examples/026_vault/site.yml b/examples/026_vault/site.yml new file mode 100644 index 0000000..7299e9e --- /dev/null +++ b/examples/026_vault/site.yml @@ -0,0 +1,6 @@ +--- +- include: control.yml +- include: database.yml +- include: webserver.yml +- include: loadbalancer.yml +- include: playbooks/stack_status.yml diff --git a/examples/026_vault/webserver.yml b/examples/026_vault/webserver.yml new file mode 100644 index 0000000..195ec7f --- /dev/null +++ b/examples/026_vault/webserver.yml @@ -0,0 +1,6 @@ +--- +- hosts: webserver + become: true + roles: + - apache2 + - demo_app diff --git a/examples/027_gather_facts/control.yml b/examples/027_gather_facts/control.yml new file mode 100644 index 0000000..c959863 --- /dev/null +++ b/examples/027_gather_facts/control.yml @@ -0,0 +1,6 @@ +--- +- hosts: control + become: true + gather_facts: false + roles: + - control diff --git a/examples/027_gather_facts/database.yml b/examples/027_gather_facts/database.yml new file mode 100644 index 0000000..6d7b7eb --- /dev/null +++ b/examples/027_gather_facts/database.yml @@ -0,0 +1,8 @@ +--- +- hosts: database + become: true + roles: + - role: mysql + db_user_name: "{{ db_user }}" + db_user_pass: "{{ db_pass }}" + db_user_host: '%' diff --git a/examples/027_gather_facts/group_vars/all b/examples/027_gather_facts/group_vars/all new file mode 100644 index 0000000..2fd732e --- /dev/null +++ b/examples/027_gather_facts/group_vars/all @@ -0,0 +1,12 @@ +--- +#DB from role mysql +db_name: maykadb +db_user: mayka_user +db_pass: mayka_pass +db_user_host: localhost + +#nginx loadbalancer configuration +sites: + myappmayka: + frontend: 80 + backend: 80 diff --git a/examples/027_gather_facts/loadbalancer.yml b/examples/027_gather_facts/loadbalancer.yml new file mode 100644 index 0000000..5d025e2 --- /dev/null +++ b/examples/027_gather_facts/loadbalancer.yml @@ -0,0 +1,6 @@ +--- +- hosts: loadbalancer + become: true + gather_facts: false + roles: + - nginx diff --git a/examples/027_gather_facts/playbooks/hostname.yml b/examples/027_gather_facts/playbooks/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/027_gather_facts/playbooks/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/027_gather_facts/playbooks/stack_restart.yml b/examples/027_gather_facts/playbooks/stack_restart.yml new file mode 100644 index 0000000..d89c326 --- /dev/null +++ b/examples/027_gather_facts/playbooks/stack_restart.yml @@ -0,0 +1,33 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + - wait_for: port=80 state=drained + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + - wait_for: port=80 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + - wait_for: host={{ ansible_eth0.ipv4.address }} port=3306 state=started + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + - wait_for: port=80 + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started + - wait_for: port=80 diff --git a/examples/027_gather_facts/playbooks/stack_status.yml b/examples/027_gather_facts/playbooks/stack_status.yml new file mode 100644 index 0000000..4dab982 --- /dev/null +++ b/examples/027_gather_facts/playbooks/stack_status.yml @@ -0,0 +1,71 @@ +--- +- hosts: loadbalancer + become: true + gather_facts: false + tasks: + - name: verify nginx service + command: service nginx status + + - name: verify nginx is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: webserver + become: true + gather_facts: false + tasks: + - name: verify apache2 service + command: service apache2 status + + - name: verify apache2 is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: database + become: true + tasks: + - name: verify mysql service + command: service mysql status + + - name: verify mysql is listening on 3306 + wait_for: port=3306 timeout=1 + +- hosts: control + gather_facts: false + tasks: + - name: verify end-to-end index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ 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}}" + + - name: verify end-to-end db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ 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}}" + +- hosts: loadbalancer + gather_facts: false + tasks: + - name: verify backend index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ groups.webserver }}" + register: app_index + +# - fail: msg="index failed to return content" +# when: "'Hello, from sunny {{ item.content }}!' not in item.content" +# with_items: "{{app_index.results}}" + + - name: verify backend db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ 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}}" diff --git a/examples/027_gather_facts/roles/apache2/README.md b/examples/027_gather_facts/roles/apache2/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/027_gather_facts/roles/apache2/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/027_gather_facts/roles/apache2/defaults/main.yml b/examples/027_gather_facts/roles/apache2/defaults/main.yml new file mode 100644 index 0000000..0381169 --- /dev/null +++ b/examples/027_gather_facts/roles/apache2/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for apache2 diff --git a/examples/027_gather_facts/roles/apache2/handlers/main.yml b/examples/027_gather_facts/roles/apache2/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/027_gather_facts/roles/apache2/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/027_gather_facts/roles/apache2/meta/main.yml b/examples/027_gather_facts/roles/apache2/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/027_gather_facts/roles/apache2/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/027_gather_facts/roles/apache2/tasks/main.yml b/examples/027_gather_facts/roles/apache2/tasks/main.yml new file mode 100644 index 0000000..e1fd9a3 --- /dev/null +++ b/examples/027_gather_facts/roles/apache2/tasks/main.yml @@ -0,0 +1,17 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + +- name: ensure mod_wsgi enabled + apache2_module: state=present name=wsgi + notify: restart apache2 + +- name: de-activate default apache site + file: path=/etc/apache2/sites-enabled/000-default.conf state=absent + notify: restart apache2 + +- name: ensure apache2 started + service: name=apache2 state=started enabled=yes diff --git a/examples/027_gather_facts/roles/apache2/vars/main.yml b/examples/027_gather_facts/roles/apache2/vars/main.yml new file mode 100644 index 0000000..5d23ceb --- /dev/null +++ b/examples/027_gather_facts/roles/apache2/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for apache2 diff --git a/examples/027_gather_facts/roles/control/README.md b/examples/027_gather_facts/roles/control/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/027_gather_facts/roles/control/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/027_gather_facts/roles/control/defaults/main.yml b/examples/027_gather_facts/roles/control/defaults/main.yml new file mode 100644 index 0000000..9fe52bd --- /dev/null +++ b/examples/027_gather_facts/roles/control/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for control diff --git a/examples/027_gather_facts/roles/control/handlers/main.yml b/examples/027_gather_facts/roles/control/handlers/main.yml new file mode 100644 index 0000000..4136893 --- /dev/null +++ b/examples/027_gather_facts/roles/control/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for control diff --git a/examples/027_gather_facts/roles/control/meta/main.yml b/examples/027_gather_facts/roles/control/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/027_gather_facts/roles/control/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/027_gather_facts/roles/control/tasks/main.yml b/examples/027_gather_facts/roles/control/tasks/main.yml new file mode 100644 index 0000000..330e91c --- /dev/null +++ b/examples/027_gather_facts/roles/control/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - curl + - python-httplib2 diff --git a/examples/027_gather_facts/roles/control/vars/main.yml b/examples/027_gather_facts/roles/control/vars/main.yml new file mode 100644 index 0000000..eadc8b6 --- /dev/null +++ b/examples/027_gather_facts/roles/control/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for control diff --git a/examples/027_gather_facts/roles/demo_app/README.md b/examples/027_gather_facts/roles/demo_app/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/027_gather_facts/roles/demo_app/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/027_gather_facts/roles/demo_app/defaults/main.yml b/examples/027_gather_facts/roles/demo_app/defaults/main.yml new file mode 100644 index 0000000..914e957 --- /dev/null +++ b/examples/027_gather_facts/roles/demo_app/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for demo_app diff --git a/examples/027_gather_facts/roles/demo_app/files/demo/app/demo.py b/examples/027_gather_facts/roles/demo_app/files/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/027_gather_facts/roles/demo_app/files/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/027_gather_facts/roles/demo_app/files/demo/app/demo.wsgi b/examples/027_gather_facts/roles/demo_app/files/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/027_gather_facts/roles/demo_app/files/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/027_gather_facts/roles/demo_app/files/demo/app/requirements.txt b/examples/027_gather_facts/roles/demo_app/files/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/027_gather_facts/roles/demo_app/files/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/027_gather_facts/roles/demo_app/files/demo/demo.conf b/examples/027_gather_facts/roles/demo_app/files/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/027_gather_facts/roles/demo_app/files/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/027_gather_facts/roles/demo_app/handlers/main.yml b/examples/027_gather_facts/roles/demo_app/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/027_gather_facts/roles/demo_app/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/027_gather_facts/roles/demo_app/meta/main.yml b/examples/027_gather_facts/roles/demo_app/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/027_gather_facts/roles/demo_app/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/027_gather_facts/roles/demo_app/tasks/main.yml b/examples/027_gather_facts/roles/demo_app/tasks/main.yml new file mode 100644 index 0000000..05a3d67 --- /dev/null +++ b/examples/027_gather_facts/roles/demo_app/tasks/main.yml @@ -0,0 +1,27 @@ +--- +- name: install web components + apt: name={{item}} state=present update_cache=yes + with_items: + - python-pip-whl + - python3-virtualenv + - python3-mysqldb + +- name: copy demo app source + copy: src=demo/app/ dest=/var/www/demo mode=0755 + notify: restart apache2 + +- name: copy demo.wsgi + template: src=demo.wsgi.j2 dest=/var/www/demo/demo.wsgi 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: activate demo apache site + file: src=/etc/apache2/sites-available/demo.conf dest=/etc/apache2/sites-enabled/demo.conf state=link + notify: restart apache2 diff --git a/examples/027_gather_facts/roles/demo_app/templates/demo.wsgi.j2 b/examples/027_gather_facts/roles/demo_app/templates/demo.wsgi.j2 new file mode 100644 index 0000000..7d65a51 --- /dev/null +++ b/examples/027_gather_facts/roles/demo_app/templates/demo.wsgi.j2 @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://{{ db_user }}:{{ db_pass }}@{{ groups.database[0] }}/{{ db_name }}' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application diff --git a/examples/027_gather_facts/roles/demo_app/vars/main.yml b/examples/027_gather_facts/roles/demo_app/vars/main.yml new file mode 100644 index 0000000..52fb613 --- /dev/null +++ b/examples/027_gather_facts/roles/demo_app/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for demo_app diff --git a/examples/027_gather_facts/roles/mysql/README.md b/examples/027_gather_facts/roles/mysql/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/027_gather_facts/roles/mysql/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/027_gather_facts/roles/mysql/defaults/main.yml b/examples/027_gather_facts/roles/mysql/defaults/main.yml new file mode 100644 index 0000000..eefca51 --- /dev/null +++ b/examples/027_gather_facts/roles/mysql/defaults/main.yml @@ -0,0 +1,5 @@ +--- +#db_name: myapp +#db_user_name: dbuser +#db_user_pass: dbpass +#db_user_host: localhost diff --git a/examples/027_gather_facts/roles/mysql/handlers/main.yml b/examples/027_gather_facts/roles/mysql/handlers/main.yml new file mode 100644 index 0000000..3755d8c --- /dev/null +++ b/examples/027_gather_facts/roles/mysql/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart mysql + service: name=mysql state=restarted diff --git a/examples/027_gather_facts/roles/mysql/meta/main.yml b/examples/027_gather_facts/roles/mysql/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/027_gather_facts/roles/mysql/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/027_gather_facts/roles/mysql/tasks/main.yml b/examples/027_gather_facts/roles/mysql/tasks/main.yml new file mode 100644 index 0000000..9cf064a --- /dev/null +++ b/examples/027_gather_facts/roles/mysql/tasks/main.yml @@ -0,0 +1,27 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python3-mysqldb + +- name: install mysql-server + apt: name=mysql-server state=present update_cache=yes + +- name: chmod 777 /etc/mysql/my.cnf + command: chmod 777 /etc/mysql/my.cnf + notify: restart mysql + +- name: ensure mysql listening on all ports + lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address + line="bind-address = {{ ansible_eth0.ipv4.address }}" + notify: restart mysql + +- name: ensure mysql started + service: name=mysql state=started enabled=yes + +- name: create database + mysql_db: name={{ db_name }} state=present + +- name: create user + mysql_user: name={{ db_user_name }} password={{ db_user_pass }} priv={{ db_name }}.*:ALL + host='{{ db_user_host }}' state=present diff --git a/examples/027_gather_facts/roles/mysql/vars/main.yml b/examples/027_gather_facts/roles/mysql/vars/main.yml new file mode 100644 index 0000000..a79bfed --- /dev/null +++ b/examples/027_gather_facts/roles/mysql/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for mysql diff --git a/examples/027_gather_facts/roles/nginx/README.md b/examples/027_gather_facts/roles/nginx/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/027_gather_facts/roles/nginx/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/027_gather_facts/roles/nginx/defaults/main.yml b/examples/027_gather_facts/roles/nginx/defaults/main.yml new file mode 100644 index 0000000..5a53da8 --- /dev/null +++ b/examples/027_gather_facts/roles/nginx/defaults/main.yml @@ -0,0 +1,5 @@ +#--- +#sites: +# myapp: +# frontend: 80 +# backend: 80 diff --git a/examples/027_gather_facts/roles/nginx/handlers/main.yml b/examples/027_gather_facts/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..92971d2 --- /dev/null +++ b/examples/027_gather_facts/roles/nginx/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart nginx + service: name=nginx state=restarted diff --git a/examples/027_gather_facts/roles/nginx/meta/main.yml b/examples/027_gather_facts/roles/nginx/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/027_gather_facts/roles/nginx/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/027_gather_facts/roles/nginx/tasks/main.yml b/examples/027_gather_facts/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..643cca3 --- /dev/null +++ b/examples/027_gather_facts/roles/nginx/tasks/main.yml @@ -0,0 +1,35 @@ +--- +- name: install tools + apt: name={{item}} state=present update_cache=yes + with_items: + - python-httplib2 + +- name: install nginx + apt: name=nginx state=present update_cache=yes + +- name: configure nginx sites + template: src=nginx.conf.j2 dest=/etc/nginx/sites-available/{{ item.key }} mode=0644 + with_dict: "{{ sites }}" + notify: restart nginx + +- name: get active sites + shell: ls -l /etc/nginx/sites-enabled + register: result + +- name: de-activate default + file: path=/etc/nginx/sites-enabled/default state=absent + notify: restart nginx + +- name: de-activate sites + file: path=/etc/nginx/sites-enabled/{{ item }} state=absent + with_items: active.stdout_lines + when: item not in sites + notify: restart nginx + +- name: activate nginx sites + file: src=/etc/nginx/sites-available/{{ item.key }} dest=/etc/nginx/sites-enabled/{{ item.key }} state=link + with_dict: "{{ sites }}" + notify: restart nginx + +- name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/027_gather_facts/roles/nginx/templates/nginx.conf.j2 b/examples/027_gather_facts/roles/nginx/templates/nginx.conf.j2 new file mode 100644 index 0000000..092c8be --- /dev/null +++ b/examples/027_gather_facts/roles/nginx/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream {{ item.key }} { +{% for server in groups.webserver %} + server {{ server }}:{{ item.value.backend }}; +{% endfor %} +} + +server { + listen {{ item.value.frontend }}; + + location / { + proxy_pass http://{{ item.key }}; + } +} diff --git a/examples/027_gather_facts/roles/nginx/vars/main.yml b/examples/027_gather_facts/roles/nginx/vars/main.yml new file mode 100644 index 0000000..d45faf6 --- /dev/null +++ b/examples/027_gather_facts/roles/nginx/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for nginx diff --git a/examples/027_gather_facts/site.yml b/examples/027_gather_facts/site.yml new file mode 100644 index 0000000..7299e9e --- /dev/null +++ b/examples/027_gather_facts/site.yml @@ -0,0 +1,6 @@ +--- +- include: control.yml +- include: database.yml +- include: webserver.yml +- include: loadbalancer.yml +- include: playbooks/stack_status.yml diff --git a/examples/027_gather_facts/webserver.yml b/examples/027_gather_facts/webserver.yml new file mode 100644 index 0000000..98f1b45 --- /dev/null +++ b/examples/027_gather_facts/webserver.yml @@ -0,0 +1,7 @@ +--- +- hosts: webserver + become: true + gather_facts: false + roles: + - apache2 + - demo_app diff --git a/examples/028_apt_cache_one_day/control.yml b/examples/028_apt_cache_one_day/control.yml new file mode 100644 index 0000000..c959863 --- /dev/null +++ b/examples/028_apt_cache_one_day/control.yml @@ -0,0 +1,6 @@ +--- +- hosts: control + become: true + gather_facts: false + roles: + - control diff --git a/examples/028_apt_cache_one_day/database.yml b/examples/028_apt_cache_one_day/database.yml new file mode 100644 index 0000000..6d7b7eb --- /dev/null +++ b/examples/028_apt_cache_one_day/database.yml @@ -0,0 +1,8 @@ +--- +- hosts: database + become: true + roles: + - role: mysql + db_user_name: "{{ db_user }}" + db_user_pass: "{{ db_pass }}" + db_user_host: '%' diff --git a/examples/028_apt_cache_one_day/group_vars/all b/examples/028_apt_cache_one_day/group_vars/all new file mode 100644 index 0000000..2fd732e --- /dev/null +++ b/examples/028_apt_cache_one_day/group_vars/all @@ -0,0 +1,12 @@ +--- +#DB from role mysql +db_name: maykadb +db_user: mayka_user +db_pass: mayka_pass +db_user_host: localhost + +#nginx loadbalancer configuration +sites: + myappmayka: + frontend: 80 + backend: 80 diff --git a/examples/028_apt_cache_one_day/loadbalancer.yml b/examples/028_apt_cache_one_day/loadbalancer.yml new file mode 100644 index 0000000..5d025e2 --- /dev/null +++ b/examples/028_apt_cache_one_day/loadbalancer.yml @@ -0,0 +1,6 @@ +--- +- hosts: loadbalancer + become: true + gather_facts: false + roles: + - nginx diff --git a/examples/028_apt_cache_one_day/playbooks/hostname.yml b/examples/028_apt_cache_one_day/playbooks/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/028_apt_cache_one_day/playbooks/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/028_apt_cache_one_day/playbooks/stack_restart.yml b/examples/028_apt_cache_one_day/playbooks/stack_restart.yml new file mode 100644 index 0000000..d89c326 --- /dev/null +++ b/examples/028_apt_cache_one_day/playbooks/stack_restart.yml @@ -0,0 +1,33 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + - wait_for: port=80 state=drained + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + - wait_for: port=80 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + - wait_for: host={{ ansible_eth0.ipv4.address }} port=3306 state=started + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + - wait_for: port=80 + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started + - wait_for: port=80 diff --git a/examples/028_apt_cache_one_day/playbooks/stack_status.yml b/examples/028_apt_cache_one_day/playbooks/stack_status.yml new file mode 100644 index 0000000..4dab982 --- /dev/null +++ b/examples/028_apt_cache_one_day/playbooks/stack_status.yml @@ -0,0 +1,71 @@ +--- +- hosts: loadbalancer + become: true + gather_facts: false + tasks: + - name: verify nginx service + command: service nginx status + + - name: verify nginx is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: webserver + become: true + gather_facts: false + tasks: + - name: verify apache2 service + command: service apache2 status + + - name: verify apache2 is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: database + become: true + tasks: + - name: verify mysql service + command: service mysql status + + - name: verify mysql is listening on 3306 + wait_for: port=3306 timeout=1 + +- hosts: control + gather_facts: false + tasks: + - name: verify end-to-end index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ 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}}" + + - name: verify end-to-end db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ 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}}" + +- hosts: loadbalancer + gather_facts: false + tasks: + - name: verify backend index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ groups.webserver }}" + register: app_index + +# - fail: msg="index failed to return content" +# when: "'Hello, from sunny {{ item.content }}!' not in item.content" +# with_items: "{{app_index.results}}" + + - name: verify backend db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ 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}}" diff --git a/examples/028_apt_cache_one_day/roles/apache2/README.md b/examples/028_apt_cache_one_day/roles/apache2/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/apache2/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/028_apt_cache_one_day/roles/apache2/defaults/main.yml b/examples/028_apt_cache_one_day/roles/apache2/defaults/main.yml new file mode 100644 index 0000000..0381169 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/apache2/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for apache2 diff --git a/examples/028_apt_cache_one_day/roles/apache2/handlers/main.yml b/examples/028_apt_cache_one_day/roles/apache2/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/apache2/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/028_apt_cache_one_day/roles/apache2/meta/main.yml b/examples/028_apt_cache_one_day/roles/apache2/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/apache2/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/028_apt_cache_one_day/roles/apache2/tasks/main.yml b/examples/028_apt_cache_one_day/roles/apache2/tasks/main.yml new file mode 100644 index 0000000..ba9a5bb --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/apache2/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- name: update apt cache once day + apt: update_cache=yes cache_valid_time=86400 + +- name: install web components + apt: name={{item}} state=present + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + +- name: ensure mod_wsgi enabled + apache2_module: state=present name=wsgi + notify: restart apache2 + +- name: de-activate default apache site + file: path=/etc/apache2/sites-enabled/000-default.conf state=absent + notify: restart apache2 + +- name: ensure apache2 started + service: name=apache2 state=started enabled=yes diff --git a/examples/028_apt_cache_one_day/roles/apache2/vars/main.yml b/examples/028_apt_cache_one_day/roles/apache2/vars/main.yml new file mode 100644 index 0000000..5d23ceb --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/apache2/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for apache2 diff --git a/examples/028_apt_cache_one_day/roles/control/README.md b/examples/028_apt_cache_one_day/roles/control/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/control/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/028_apt_cache_one_day/roles/control/defaults/main.yml b/examples/028_apt_cache_one_day/roles/control/defaults/main.yml new file mode 100644 index 0000000..9fe52bd --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/control/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for control diff --git a/examples/028_apt_cache_one_day/roles/control/handlers/main.yml b/examples/028_apt_cache_one_day/roles/control/handlers/main.yml new file mode 100644 index 0000000..4136893 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/control/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for control diff --git a/examples/028_apt_cache_one_day/roles/control/meta/main.yml b/examples/028_apt_cache_one_day/roles/control/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/control/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/028_apt_cache_one_day/roles/control/tasks/main.yml b/examples/028_apt_cache_one_day/roles/control/tasks/main.yml new file mode 100644 index 0000000..fdd3144 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/control/tasks/main.yml @@ -0,0 +1,9 @@ +--- +- name: update apt cache once day + apt: update_cache=yes cache_valid_time=86400 + +- name: install tools + apt: name={{item}} state=present + with_items: + - curl + - python-httplib2 diff --git a/examples/028_apt_cache_one_day/roles/control/vars/main.yml b/examples/028_apt_cache_one_day/roles/control/vars/main.yml new file mode 100644 index 0000000..eadc8b6 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/control/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for control diff --git a/examples/028_apt_cache_one_day/roles/demo_app/README.md b/examples/028_apt_cache_one_day/roles/demo_app/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/demo_app/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/028_apt_cache_one_day/roles/demo_app/defaults/main.yml b/examples/028_apt_cache_one_day/roles/demo_app/defaults/main.yml new file mode 100644 index 0000000..914e957 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/demo_app/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for demo_app diff --git a/examples/028_apt_cache_one_day/roles/demo_app/files/demo/app/demo.py b/examples/028_apt_cache_one_day/roles/demo_app/files/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/demo_app/files/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/028_apt_cache_one_day/roles/demo_app/files/demo/app/demo.wsgi b/examples/028_apt_cache_one_day/roles/demo_app/files/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/demo_app/files/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/028_apt_cache_one_day/roles/demo_app/files/demo/app/requirements.txt b/examples/028_apt_cache_one_day/roles/demo_app/files/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/demo_app/files/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/028_apt_cache_one_day/roles/demo_app/files/demo/demo.conf b/examples/028_apt_cache_one_day/roles/demo_app/files/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/demo_app/files/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/028_apt_cache_one_day/roles/demo_app/handlers/main.yml b/examples/028_apt_cache_one_day/roles/demo_app/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/demo_app/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/028_apt_cache_one_day/roles/demo_app/meta/main.yml b/examples/028_apt_cache_one_day/roles/demo_app/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/demo_app/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/028_apt_cache_one_day/roles/demo_app/tasks/main.yml b/examples/028_apt_cache_one_day/roles/demo_app/tasks/main.yml new file mode 100644 index 0000000..c013724 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/demo_app/tasks/main.yml @@ -0,0 +1,30 @@ +--- +- name: update apt cache once day + apt: update_cache=yes cache_valid_time=86400 + +- name: install web components + apt: name={{item}} state=present + with_items: + - python-pip-whl + - python3-virtualenv + - python3-mysqldb + +- name: copy demo app source + copy: src=demo/app/ dest=/var/www/demo mode=0755 + notify: restart apache2 + +- name: copy demo.wsgi + template: src=demo.wsgi.j2 dest=/var/www/demo/demo.wsgi 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: activate demo apache site + file: src=/etc/apache2/sites-available/demo.conf dest=/etc/apache2/sites-enabled/demo.conf state=link + notify: restart apache2 diff --git a/examples/028_apt_cache_one_day/roles/demo_app/templates/demo.wsgi.j2 b/examples/028_apt_cache_one_day/roles/demo_app/templates/demo.wsgi.j2 new file mode 100644 index 0000000..7d65a51 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/demo_app/templates/demo.wsgi.j2 @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://{{ db_user }}:{{ db_pass }}@{{ groups.database[0] }}/{{ db_name }}' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application diff --git a/examples/028_apt_cache_one_day/roles/demo_app/vars/main.yml b/examples/028_apt_cache_one_day/roles/demo_app/vars/main.yml new file mode 100644 index 0000000..52fb613 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/demo_app/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for demo_app diff --git a/examples/028_apt_cache_one_day/roles/mysql/README.md b/examples/028_apt_cache_one_day/roles/mysql/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/mysql/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/028_apt_cache_one_day/roles/mysql/defaults/main.yml b/examples/028_apt_cache_one_day/roles/mysql/defaults/main.yml new file mode 100644 index 0000000..eefca51 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/mysql/defaults/main.yml @@ -0,0 +1,5 @@ +--- +#db_name: myapp +#db_user_name: dbuser +#db_user_pass: dbpass +#db_user_host: localhost diff --git a/examples/028_apt_cache_one_day/roles/mysql/handlers/main.yml b/examples/028_apt_cache_one_day/roles/mysql/handlers/main.yml new file mode 100644 index 0000000..3755d8c --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/mysql/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart mysql + service: name=mysql state=restarted diff --git a/examples/028_apt_cache_one_day/roles/mysql/meta/main.yml b/examples/028_apt_cache_one_day/roles/mysql/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/mysql/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/028_apt_cache_one_day/roles/mysql/tasks/main.yml b/examples/028_apt_cache_one_day/roles/mysql/tasks/main.yml new file mode 100644 index 0000000..01080e4 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/mysql/tasks/main.yml @@ -0,0 +1,30 @@ +--- +- name: update apt cache once day + apt: update_cache=yes cache_valid_time=86400 + +- name: install tools + apt: name={{item}} state=present + with_items: + - python3-mysqldb + +- name: install mysql-server + apt: name=mysql-server state=present + +- name: chmod 777 /etc/mysql/my.cnf + command: chmod 777 /etc/mysql/my.cnf + notify: restart mysql + +- name: ensure mysql listening on all ports + lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address + line="bind-address = {{ ansible_eth0.ipv4.address }}" + notify: restart mysql + +- name: ensure mysql started + service: name=mysql state=started enabled=yes + +- name: create database + mysql_db: name={{ db_name }} state=present + +- name: create user + mysql_user: name={{ db_user_name }} password={{ db_user_pass }} priv={{ db_name }}.*:ALL + host='{{ db_user_host }}' state=present diff --git a/examples/028_apt_cache_one_day/roles/mysql/vars/main.yml b/examples/028_apt_cache_one_day/roles/mysql/vars/main.yml new file mode 100644 index 0000000..a79bfed --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/mysql/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for mysql diff --git a/examples/028_apt_cache_one_day/roles/nginx/README.md b/examples/028_apt_cache_one_day/roles/nginx/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/nginx/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/028_apt_cache_one_day/roles/nginx/defaults/main.yml b/examples/028_apt_cache_one_day/roles/nginx/defaults/main.yml new file mode 100644 index 0000000..5a53da8 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/nginx/defaults/main.yml @@ -0,0 +1,5 @@ +#--- +#sites: +# myapp: +# frontend: 80 +# backend: 80 diff --git a/examples/028_apt_cache_one_day/roles/nginx/handlers/main.yml b/examples/028_apt_cache_one_day/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..92971d2 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/nginx/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart nginx + service: name=nginx state=restarted diff --git a/examples/028_apt_cache_one_day/roles/nginx/meta/main.yml b/examples/028_apt_cache_one_day/roles/nginx/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/nginx/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/028_apt_cache_one_day/roles/nginx/tasks/main.yml b/examples/028_apt_cache_one_day/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..45b08dc --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/nginx/tasks/main.yml @@ -0,0 +1,38 @@ +--- +- name: update apt cache once day + apt: update_cache=yes cache_valid_time=86400 + +- name: install tools + apt: name={{item}} state=present + with_items: + - python-httplib2 + +- name: install nginx + apt: name=nginx state=present + +- name: configure nginx sites + template: src=nginx.conf.j2 dest=/etc/nginx/sites-available/{{ item.key }} mode=0644 + with_dict: "{{ sites }}" + notify: restart nginx + +- name: get active sites + shell: ls -l /etc/nginx/sites-enabled + register: result + +- name: de-activate default + file: path=/etc/nginx/sites-enabled/default state=absent + notify: restart nginx + +- name: de-activate sites + file: path=/etc/nginx/sites-enabled/{{ item }} state=absent + with_items: active.stdout_lines + when: item not in sites + notify: restart nginx + +- name: activate nginx sites + file: src=/etc/nginx/sites-available/{{ item.key }} dest=/etc/nginx/sites-enabled/{{ item.key }} state=link + with_dict: "{{ sites }}" + notify: restart nginx + +- name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/028_apt_cache_one_day/roles/nginx/templates/nginx.conf.j2 b/examples/028_apt_cache_one_day/roles/nginx/templates/nginx.conf.j2 new file mode 100644 index 0000000..092c8be --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/nginx/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream {{ item.key }} { +{% for server in groups.webserver %} + server {{ server }}:{{ item.value.backend }}; +{% endfor %} +} + +server { + listen {{ item.value.frontend }}; + + location / { + proxy_pass http://{{ item.key }}; + } +} diff --git a/examples/028_apt_cache_one_day/roles/nginx/vars/main.yml b/examples/028_apt_cache_one_day/roles/nginx/vars/main.yml new file mode 100644 index 0000000..d45faf6 --- /dev/null +++ b/examples/028_apt_cache_one_day/roles/nginx/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for nginx diff --git a/examples/028_apt_cache_one_day/site.yml b/examples/028_apt_cache_one_day/site.yml new file mode 100644 index 0000000..7299e9e --- /dev/null +++ b/examples/028_apt_cache_one_day/site.yml @@ -0,0 +1,6 @@ +--- +- include: control.yml +- include: database.yml +- include: webserver.yml +- include: loadbalancer.yml +- include: playbooks/stack_status.yml diff --git a/examples/028_apt_cache_one_day/webserver.yml b/examples/028_apt_cache_one_day/webserver.yml new file mode 100644 index 0000000..98f1b45 --- /dev/null +++ b/examples/028_apt_cache_one_day/webserver.yml @@ -0,0 +1,7 @@ +--- +- hosts: webserver + become: true + gather_facts: false + roles: + - apache2 + - demo_app diff --git a/examples/029_tags/control.yml b/examples/029_tags/control.yml new file mode 100644 index 0000000..c959863 --- /dev/null +++ b/examples/029_tags/control.yml @@ -0,0 +1,6 @@ +--- +- hosts: control + become: true + gather_facts: false + roles: + - control diff --git a/examples/029_tags/database.yml b/examples/029_tags/database.yml new file mode 100644 index 0000000..6d7b7eb --- /dev/null +++ b/examples/029_tags/database.yml @@ -0,0 +1,8 @@ +--- +- hosts: database + become: true + roles: + - role: mysql + db_user_name: "{{ db_user }}" + db_user_pass: "{{ db_pass }}" + db_user_host: '%' diff --git a/examples/029_tags/group_vars/all b/examples/029_tags/group_vars/all new file mode 100644 index 0000000..2fd732e --- /dev/null +++ b/examples/029_tags/group_vars/all @@ -0,0 +1,12 @@ +--- +#DB from role mysql +db_name: maykadb +db_user: mayka_user +db_pass: mayka_pass +db_user_host: localhost + +#nginx loadbalancer configuration +sites: + myappmayka: + frontend: 80 + backend: 80 diff --git a/examples/029_tags/loadbalancer.yml b/examples/029_tags/loadbalancer.yml new file mode 100644 index 0000000..5d025e2 --- /dev/null +++ b/examples/029_tags/loadbalancer.yml @@ -0,0 +1,6 @@ +--- +- hosts: loadbalancer + become: true + gather_facts: false + roles: + - nginx diff --git a/examples/029_tags/playbooks/hostname.yml b/examples/029_tags/playbooks/hostname.yml new file mode 100644 index 0000000..a1a3ad6 --- /dev/null +++ b/examples/029_tags/playbooks/hostname.yml @@ -0,0 +1,5 @@ +--- + - hosts: all + tasks: + - name: get server hostname + command: hostname diff --git a/examples/029_tags/playbooks/stack_restart.yml b/examples/029_tags/playbooks/stack_restart.yml new file mode 100644 index 0000000..d89c326 --- /dev/null +++ b/examples/029_tags/playbooks/stack_restart.yml @@ -0,0 +1,33 @@ +--- +# Bring stack down +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=stopped + - wait_for: port=80 state=drained + +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=stopped + - wait_for: port=80 state=stopped + +# Restart mysql +- hosts: database + become: true + tasks: + - service: name=mysql state=restarted + - wait_for: host={{ ansible_eth0.ipv4.address }} port=3306 state=started + +# Bring stack up +- hosts: webserver + become: true + tasks: + - service: name=apache2 state=started + - wait_for: port=80 + +- hosts: loadbalancer + become: true + tasks: + - service: name=nginx state=started + - wait_for: port=80 diff --git a/examples/029_tags/playbooks/stack_status.yml b/examples/029_tags/playbooks/stack_status.yml new file mode 100644 index 0000000..4dab982 --- /dev/null +++ b/examples/029_tags/playbooks/stack_status.yml @@ -0,0 +1,71 @@ +--- +- hosts: loadbalancer + become: true + gather_facts: false + tasks: + - name: verify nginx service + command: service nginx status + + - name: verify nginx is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: webserver + become: true + gather_facts: false + tasks: + - name: verify apache2 service + command: service apache2 status + + - name: verify apache2 is listening on 80 + wait_for: port=80 timeout=1 + +- hosts: database + become: true + tasks: + - name: verify mysql service + command: service mysql status + + - name: verify mysql is listening on 3306 + wait_for: port=3306 timeout=1 + +- hosts: control + gather_facts: false + tasks: + - name: verify end-to-end index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ 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}}" + + - name: verify end-to-end db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ 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}}" + +- hosts: loadbalancer + gather_facts: false + tasks: + - name: verify backend index response + uri: url=http://{{item}} return_content=yes + with_items: "{{ groups.webserver }}" + register: app_index + +# - fail: msg="index failed to return content" +# when: "'Hello, from sunny {{ item.content }}!' not in item.content" +# with_items: "{{app_index.results}}" + + - name: verify backend db response + uri: url=http://{{item}}/db return_content=yes + with_items: "{{ 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}}" diff --git a/examples/029_tags/roles/apache2/README.md b/examples/029_tags/roles/apache2/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/029_tags/roles/apache2/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/029_tags/roles/apache2/defaults/main.yml b/examples/029_tags/roles/apache2/defaults/main.yml new file mode 100644 index 0000000..0381169 --- /dev/null +++ b/examples/029_tags/roles/apache2/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for apache2 diff --git a/examples/029_tags/roles/apache2/handlers/main.yml b/examples/029_tags/roles/apache2/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/029_tags/roles/apache2/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/029_tags/roles/apache2/meta/main.yml b/examples/029_tags/roles/apache2/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/029_tags/roles/apache2/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/029_tags/roles/apache2/tasks/main.yml b/examples/029_tags/roles/apache2/tasks/main.yml new file mode 100644 index 0000000..0d36b08 --- /dev/null +++ b/examples/029_tags/roles/apache2/tasks/main.yml @@ -0,0 +1,21 @@ +--- +- name: update apt cache once day + apt: update_cache=yes cache_valid_time=86400 + +- name: install web components + apt: name={{item}} state=present + with_items: + - apache2 + - libapache2-mod-wsgi-py3 + +- name: ensure mod_wsgi enabled + apache2_module: state=present name=wsgi + notify: restart apache2 + +- name: de-activate default apache site + file: path=/etc/apache2/sites-enabled/000-default.conf state=absent + tags: [ 'deploy' ] + notify: restart apache2 + +- name: ensure apache2 started + service: name=apache2 state=started enabled=yes diff --git a/examples/029_tags/roles/apache2/vars/main.yml b/examples/029_tags/roles/apache2/vars/main.yml new file mode 100644 index 0000000..5d23ceb --- /dev/null +++ b/examples/029_tags/roles/apache2/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for apache2 diff --git a/examples/029_tags/roles/control/README.md b/examples/029_tags/roles/control/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/029_tags/roles/control/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/029_tags/roles/control/defaults/main.yml b/examples/029_tags/roles/control/defaults/main.yml new file mode 100644 index 0000000..9fe52bd --- /dev/null +++ b/examples/029_tags/roles/control/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for control diff --git a/examples/029_tags/roles/control/handlers/main.yml b/examples/029_tags/roles/control/handlers/main.yml new file mode 100644 index 0000000..4136893 --- /dev/null +++ b/examples/029_tags/roles/control/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for control diff --git a/examples/029_tags/roles/control/meta/main.yml b/examples/029_tags/roles/control/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/029_tags/roles/control/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/029_tags/roles/control/tasks/main.yml b/examples/029_tags/roles/control/tasks/main.yml new file mode 100644 index 0000000..fdd3144 --- /dev/null +++ b/examples/029_tags/roles/control/tasks/main.yml @@ -0,0 +1,9 @@ +--- +- name: update apt cache once day + apt: update_cache=yes cache_valid_time=86400 + +- name: install tools + apt: name={{item}} state=present + with_items: + - curl + - python-httplib2 diff --git a/examples/029_tags/roles/control/vars/main.yml b/examples/029_tags/roles/control/vars/main.yml new file mode 100644 index 0000000..eadc8b6 --- /dev/null +++ b/examples/029_tags/roles/control/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for control diff --git a/examples/029_tags/roles/demo_app/README.md b/examples/029_tags/roles/demo_app/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/029_tags/roles/demo_app/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/029_tags/roles/demo_app/defaults/main.yml b/examples/029_tags/roles/demo_app/defaults/main.yml new file mode 100644 index 0000000..914e957 --- /dev/null +++ b/examples/029_tags/roles/demo_app/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for demo_app diff --git a/examples/029_tags/roles/demo_app/files/demo/app/demo.py b/examples/029_tags/roles/demo_app/files/demo/app/demo.py new file mode 100644 index 0000000..f093790 --- /dev/null +++ b/examples/029_tags/roles/demo_app/files/demo/app/demo.py @@ -0,0 +1,20 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +import os, socket + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +hostname = socket.gethostname() + +@app.route('/') +def index(): + return 'Hello, from sunny %s!\n' % hostname + +@app.route('/db') +def dbtest(): + return 'Database Connected from %s!\n' % hostname + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/examples/029_tags/roles/demo_app/files/demo/app/demo.wsgi b/examples/029_tags/roles/demo_app/files/demo/app/demo.wsgi new file mode 100644 index 0000000..0b81ee5 --- /dev/null +++ b/examples/029_tags/roles/demo_app/files/demo/app/demo.wsgi @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://demo:demo@db01/demo' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application \ No newline at end of file diff --git a/examples/029_tags/roles/demo_app/files/demo/app/requirements.txt b/examples/029_tags/roles/demo_app/files/demo/app/requirements.txt new file mode 100644 index 0000000..d51b4ef --- /dev/null +++ b/examples/029_tags/roles/demo_app/files/demo/app/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.4 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +itsdangerous==1.1.0 +Jinja2==2.11.3 +MarkupSafe==2.0.1 +SQLAlchemy==1.4.32 +Werkzeug==1.0.1 \ No newline at end of file diff --git a/examples/029_tags/roles/demo_app/files/demo/demo.conf b/examples/029_tags/roles/demo_app/files/demo/demo.conf new file mode 100644 index 0000000..ac7b9e2 --- /dev/null +++ b/examples/029_tags/roles/demo_app/files/demo/demo.conf @@ -0,0 +1,11 @@ + + WSGIDaemonProcess demo threads=5 + WSGIScriptAlias / /var/www/demo/demo.wsgi + + + WSGIProcessGroup demo + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/examples/029_tags/roles/demo_app/handlers/main.yml b/examples/029_tags/roles/demo_app/handlers/main.yml new file mode 100644 index 0000000..b50f192 --- /dev/null +++ b/examples/029_tags/roles/demo_app/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart apache2 + service: name=apache2 state=restarted diff --git a/examples/029_tags/roles/demo_app/meta/main.yml b/examples/029_tags/roles/demo_app/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/029_tags/roles/demo_app/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/029_tags/roles/demo_app/tasks/main.yml b/examples/029_tags/roles/demo_app/tasks/main.yml new file mode 100644 index 0000000..3267250 --- /dev/null +++ b/examples/029_tags/roles/demo_app/tasks/main.yml @@ -0,0 +1,35 @@ +--- +- name: update apt cache once day + apt: update_cache=yes cache_valid_time=86400 + +- name: install web components + apt: name={{item}} state=present + with_items: + - python-pip-whl + - python3-virtualenv + - python3-mysqldb + +- name: copy demo app source + copy: src=demo/app/ dest=/var/www/demo mode=0755 + tags: [ 'deploy' ] + notify: restart apache2 + +- name: copy demo.wsgi + template: src=demo.wsgi.j2 dest=/var/www/demo/demo.wsgi mode=0755 + tags: [ 'deploy' ] + notify: restart apache2 + +- name: copy apache virtual host config + copy: src=demo/demo.conf dest=/etc/apache2/sites-available mode=0755 + tags: [ 'deploy' ] + notify: restart apache2 + +- name: setup python virtualenv + pip: requirements=/var/www/demo/requirements.txt virtualenv=/var/www/demo/.venv + tags: [ 'deploy' ] + 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 + tags: [ 'deploy' ] + notify: restart apache2 diff --git a/examples/029_tags/roles/demo_app/templates/demo.wsgi.j2 b/examples/029_tags/roles/demo_app/templates/demo.wsgi.j2 new file mode 100644 index 0000000..7d65a51 --- /dev/null +++ b/examples/029_tags/roles/demo_app/templates/demo.wsgi.j2 @@ -0,0 +1,10 @@ +activate_this = '/var/www/demo/.venv/bin/activate_this.py' +exec(open(activate_this).read(), {'__file__': activate_this}) + +import os +os.environ['DATABASE_URI'] = 'mysql://{{ db_user }}:{{ db_pass }}@{{ groups.database[0] }}/{{ db_name }}' + +import sys +sys.path.insert(0, '/var/www/demo') + +from demo import app as application diff --git a/examples/029_tags/roles/demo_app/vars/main.yml b/examples/029_tags/roles/demo_app/vars/main.yml new file mode 100644 index 0000000..52fb613 --- /dev/null +++ b/examples/029_tags/roles/demo_app/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for demo_app diff --git a/examples/029_tags/roles/mysql/README.md b/examples/029_tags/roles/mysql/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/029_tags/roles/mysql/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/029_tags/roles/mysql/defaults/main.yml b/examples/029_tags/roles/mysql/defaults/main.yml new file mode 100644 index 0000000..eefca51 --- /dev/null +++ b/examples/029_tags/roles/mysql/defaults/main.yml @@ -0,0 +1,5 @@ +--- +#db_name: myapp +#db_user_name: dbuser +#db_user_pass: dbpass +#db_user_host: localhost diff --git a/examples/029_tags/roles/mysql/handlers/main.yml b/examples/029_tags/roles/mysql/handlers/main.yml new file mode 100644 index 0000000..3755d8c --- /dev/null +++ b/examples/029_tags/roles/mysql/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart mysql + service: name=mysql state=restarted diff --git a/examples/029_tags/roles/mysql/meta/main.yml b/examples/029_tags/roles/mysql/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/029_tags/roles/mysql/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/029_tags/roles/mysql/tasks/main.yml b/examples/029_tags/roles/mysql/tasks/main.yml new file mode 100644 index 0000000..01080e4 --- /dev/null +++ b/examples/029_tags/roles/mysql/tasks/main.yml @@ -0,0 +1,30 @@ +--- +- name: update apt cache once day + apt: update_cache=yes cache_valid_time=86400 + +- name: install tools + apt: name={{item}} state=present + with_items: + - python3-mysqldb + +- name: install mysql-server + apt: name=mysql-server state=present + +- name: chmod 777 /etc/mysql/my.cnf + command: chmod 777 /etc/mysql/my.cnf + notify: restart mysql + +- name: ensure mysql listening on all ports + lineinfile: dest=/etc/mysql/my.cnf regexp=^bind-address + line="bind-address = {{ ansible_eth0.ipv4.address }}" + notify: restart mysql + +- name: ensure mysql started + service: name=mysql state=started enabled=yes + +- name: create database + mysql_db: name={{ db_name }} state=present + +- name: create user + mysql_user: name={{ db_user_name }} password={{ db_user_pass }} priv={{ db_name }}.*:ALL + host='{{ db_user_host }}' state=present diff --git a/examples/029_tags/roles/mysql/vars/main.yml b/examples/029_tags/roles/mysql/vars/main.yml new file mode 100644 index 0000000..a79bfed --- /dev/null +++ b/examples/029_tags/roles/mysql/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for mysql diff --git a/examples/029_tags/roles/nginx/README.md b/examples/029_tags/roles/nginx/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/examples/029_tags/roles/nginx/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/examples/029_tags/roles/nginx/defaults/main.yml b/examples/029_tags/roles/nginx/defaults/main.yml new file mode 100644 index 0000000..5a53da8 --- /dev/null +++ b/examples/029_tags/roles/nginx/defaults/main.yml @@ -0,0 +1,5 @@ +#--- +#sites: +# myapp: +# frontend: 80 +# backend: 80 diff --git a/examples/029_tags/roles/nginx/handlers/main.yml b/examples/029_tags/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..92971d2 --- /dev/null +++ b/examples/029_tags/roles/nginx/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart nginx + service: name=nginx state=restarted diff --git a/examples/029_tags/roles/nginx/meta/main.yml b/examples/029_tags/roles/nginx/meta/main.yml new file mode 100644 index 0000000..62c7d35 --- /dev/null +++ b/examples/029_tags/roles/nginx/meta/main.yml @@ -0,0 +1,139 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/examples/029_tags/roles/nginx/tasks/main.yml b/examples/029_tags/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..45b08dc --- /dev/null +++ b/examples/029_tags/roles/nginx/tasks/main.yml @@ -0,0 +1,38 @@ +--- +- name: update apt cache once day + apt: update_cache=yes cache_valid_time=86400 + +- name: install tools + apt: name={{item}} state=present + with_items: + - python-httplib2 + +- name: install nginx + apt: name=nginx state=present + +- name: configure nginx sites + template: src=nginx.conf.j2 dest=/etc/nginx/sites-available/{{ item.key }} mode=0644 + with_dict: "{{ sites }}" + notify: restart nginx + +- name: get active sites + shell: ls -l /etc/nginx/sites-enabled + register: result + +- name: de-activate default + file: path=/etc/nginx/sites-enabled/default state=absent + notify: restart nginx + +- name: de-activate sites + file: path=/etc/nginx/sites-enabled/{{ item }} state=absent + with_items: active.stdout_lines + when: item not in sites + notify: restart nginx + +- name: activate nginx sites + file: src=/etc/nginx/sites-available/{{ item.key }} dest=/etc/nginx/sites-enabled/{{ item.key }} state=link + with_dict: "{{ sites }}" + notify: restart nginx + +- name: ensure nginx started + service: name=nginx state=started enabled=yes diff --git a/examples/029_tags/roles/nginx/templates/nginx.conf.j2 b/examples/029_tags/roles/nginx/templates/nginx.conf.j2 new file mode 100644 index 0000000..092c8be --- /dev/null +++ b/examples/029_tags/roles/nginx/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +upstream {{ item.key }} { +{% for server in groups.webserver %} + server {{ server }}:{{ item.value.backend }}; +{% endfor %} +} + +server { + listen {{ item.value.frontend }}; + + location / { + proxy_pass http://{{ item.key }}; + } +} diff --git a/examples/029_tags/roles/nginx/vars/main.yml b/examples/029_tags/roles/nginx/vars/main.yml new file mode 100644 index 0000000..d45faf6 --- /dev/null +++ b/examples/029_tags/roles/nginx/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for nginx diff --git a/examples/029_tags/site.yml b/examples/029_tags/site.yml new file mode 100644 index 0000000..7299e9e --- /dev/null +++ b/examples/029_tags/site.yml @@ -0,0 +1,6 @@ +--- +- include: control.yml +- include: database.yml +- include: webserver.yml +- include: loadbalancer.yml +- include: playbooks/stack_status.yml diff --git a/examples/029_tags/webserver.yml b/examples/029_tags/webserver.yml new file mode 100644 index 0000000..98f1b45 --- /dev/null +++ b/examples/029_tags/webserver.yml @@ -0,0 +1,7 @@ +--- +- hosts: webserver + become: true + gather_facts: false + roles: + - apache2 + - demo_app diff --git a/examples/030_windows/README.md b/examples/030_windows/README.md new file mode 100644 index 0000000..acb1021 --- /dev/null +++ b/examples/030_windows/README.md @@ -0,0 +1,71 @@ +# Inventario máquina Windows + +--- + +> **Notas previas:** + +> Se debe tener la máquina con la red en privado y no en público, se debe cambiar. + +> Este ejemplo usa autenticación básica y conexiones no cifradas, que **no es seguro para entornos de producción**. Para producción, debes usar HTTPS y autenticación cifrada. + +--- + +# 1. Habilitar WinRM en la máquina Windows + +Puedes ejecutar este script en **PowerShell** como administrador en la máquina Windows: + +````markdown +# Habilita WinRM y configura la autenticación básica (sólo para pruebas/lab) +winrm quickconfig -force +winrm set winrm/config/service '@{AllowUnencrypted="true"}' +winrm set winrm/config/service/auth '@{Basic="true"}' + +# Permite conexiones desde cualquier IP (ajusta según tus necesidades) +Set-Item -Path WSMan:\localhost\Service\AllowUnencrypted -Value $true +Set-Item -Path WSMan:\localhost\Service\Auth\Basic -Value $true + +# Abre el puerto 5985 en el firewall (HTTP) +netsh advfirewall firewall add rule name="WinRM HTTP" dir=in action=allow protocol=TCP localport=5985 + +# Crea regla del Firewall para el puerto 5985 (HTTP) +New-NetFirewallRule -Name "WinRM HTTP" -DisplayName "WinRM HTTP" -Enabled True -Direction Inbound -Protocol TCP -Localport 5985 -Action Allow +```` +--- + +# 2. Crear un usuario administrador o usar uno existente + +Asegúrate de tener un usuario con privilegios de administrador en la máquina Windows. +Recuerda la contraseña, la necesitarás para la conexión. + +--- + +# 3. Ejemplo de inventario Ansible para Windows + +Tu archivo `hosts` (inventario) podría verse así: + +````markdown +[windows] +mi_windows_server ansible_host=192.168.1.100 + +[windows:vars] +ansible_user=Administrador +ansible_password=TuContraseña +ansible_port=5985 +ansible_connection=winrm +ansible_winrm_server_cert_validation=ignore +```` + +--- + +# 4. Ejemplo de playbook Ansible para Windows + +Aquí tienes un playbook sencillo para probar la conexión: + +````markdown +--- +- name: Prueba de conexión a Windows + hosts: windows + tasks: + - name: Hacer ping a la máquina Windows + ansible.windows.win_ping: +```` \ No newline at end of file diff --git a/examples/030_windows/all-hosts b/examples/030_windows/all-hosts new file mode 100644 index 0000000..bae74b1 --- /dev/null +++ b/examples/030_windows/all-hosts @@ -0,0 +1,9 @@ +[windows] +win101 ansible_host=192.168.1.175 + +[windows:vars] +ansible_user=vboxuser +ansible_password=changeme +ansible_port=5985 +ansible_connection=winrm +ansible_winrm_server_cert_validation=ignore \ No newline at end of file diff --git a/examples/030_windows/windows.yml b/examples/030_windows/windows.yml new file mode 100644 index 0000000..036af2e --- /dev/null +++ b/examples/030_windows/windows.yml @@ -0,0 +1,41 @@ +- name: Ping a Máquina Windows + hosts: windows + tasks: + - name: Ping the Windows machine + win_ping: + register: ping_result + + - name: Display the ping result + debug: + var: ping_result + + - name: Create folder C:\Temp if it does not exist + win_file: + path: C:\Temp + state: directory + + - name: Download Google Chrome installer + win_get_url: + url: https://dl.google.com/chrome/install/375.126/chrome_installer.exe + dest: C:\Temp\chrome_installer.exe + + - name: Install Google Chrome + win_package: + path: C:\Temp\chrome_installer.exe + arguments: /silent /install + state: present + + - name: Ensure Google Chrome is installed + win_shell: | + $chromePath = "C:\Program Files\Google\Chrome\Application\chrome.exe" + if (Test-Path $chromePath) { + Write-Output "Google Chrome is installed." + } else { + Write-Output "Google Chrome is not installed." + exit 1 + } + register: chrome_check + + - name: Display the Chrome Check result + debug: + var: chrome_check \ No newline at end of file diff --git a/examples/031_aws/README.md b/examples/031_aws/README.md new file mode 100644 index 0000000..6952d1b --- /dev/null +++ b/examples/031_aws/README.md @@ -0,0 +1,33 @@ +# Ejemplo Inventario dinámico AWS + +## 1. Instalación de los collections de AWS + +````markdown +ansible-galaxy collection install amazon.cloud +ansible-galaxy collection install amazon.aws +```` + +## 2. Instalación del cliente AWS en máquina agente de control ansible + +````markdown +curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" +unzip awscliv2.zip +sudo apt install unzip +unzip awscliv2.zip +sudo ./aws/install +aws --version +aws configure #Se necesita un usuario con acceso +```` + +Comprobamos que todo funciona del lado del AWS Cli + +````markdown +aws sts get-caller-identity +```` + +## 3. Creación de llave para EC2 + +````markdown +aws ec2 create-key-pair --key-name mi-clave-ec2 --query "KeyMaterial" --output text > /home/vagrant/.ssh/mi-clave-ec2.pem +chmod 400 /home/vagrant/.ssh/mi-clave-ec2.pem +```` \ No newline at end of file diff --git a/examples/031_aws/aws-example.yml b/examples/031_aws/aws-example.yml new file mode 100644 index 0000000..15adedf --- /dev/null +++ b/examples/031_aws/aws-example.yml @@ -0,0 +1,53 @@ +- name: Levantar instancias EC2 y configurar SSH + hosts: localhost + gather_facts: no + vars: + key_name: mi-clave-ec2.pem + region: eu-central-1 + instance_type: t2.micro + image: ami-02b7d5b1e55a7b5f1 # Amazon Linux 2023 AMI 2023.7.20250512.0 x86_64 HVM kernel-6.1 + tasks: + - name: Create instances EC2 with SSH key + amazon.aws.ec2_instance: + name: "{{ item }}" + key_name: "{{ key_name }}" + region: "{{ region }}" + instance_type: "{{ instance_type }}" + image_id: "{{ image }}" + vpc_subnet_id: subnet-0426901b07d63d0f4 + loop: + - instancia-curso-ansible-1 + - instancia-curso-ansible-2 + + - name: Show public instance_types + amazon.aws.ec2_instance_info: + region: "{{ region }}" + register: ec2_info + + - name: Show public IPs + debug: + msg: "Public IP: {{ item.public_ip_address }}" + loop: "{{ ec2_info.instances }}" + + - name: Add instances to inventory + add_host: + name: "{{ item.public_ip_address }}" + ansible_user: ec2-user + ansible_ssh_private_key_file: "{{ key_name }}" + loop: "{{ ec2_info.instances }}" + + - name: Save EC2 hosts to file + copy: + content: | + [ec2_instances] + {% for instance in ec2_info.instances %} + {{ instance.public_dns_name }} {{ instance.public_ip_address }} + {% endfor %} + dest: ./ec2_hosts.ini + + - name: Delete EC2 instances + amazon.aws.ec2_instance: + state: absent + region: "{{ region }}" + instance_ids: "{{ ec2_info.instances | map(attribute='id') | list }}" + when: ec2_info.instances | length > 0 \ No newline at end of file diff --git a/examples/032_azure/README.md b/examples/032_azure/README.md new file mode 100644 index 0000000..c9910b3 --- /dev/null +++ b/examples/032_azure/README.md @@ -0,0 +1,3 @@ +# Ejemplo Azure + + diff --git a/examples/032_azure/test_ansible_azure.yml b/examples/032_azure/test_ansible_azure.yml new file mode 100644 index 0000000..b03947b --- /dev/null +++ b/examples/032_azure/test_ansible_azure.yml @@ -0,0 +1,60 @@ +- name: Test Azure Connection + hosts: localhost + connection: local + vars: + username: adminuser + password: "P@ssw0rd123!" + tasks: + - name: Crear un grupo de recursos + azure_rm_resourcegroup: + name: TestCursoAnsibleGroup + location: westeurope + register: rg + + - name: Crear un conjunto de disponibilidad + azure_rm_availabilityset: + resource_group: TestCursoAnsibleGroup + name: miConjuntoDisponibilidad + location: westeurope + when: rg is succeeded + + - name: Crear una red virtual + azure_rm_virtualnetwork: + resource_group: TestCursoAnsibleGroup + name: miRedVirtual + address_prefixes: "10.0.0.0/16" + location: westeurope + when: rg is succeeded + + - name: Crear una subred + azure_rm_subnet: + resource_group: TestCursoAnsibleGroup + name: miSubRed + address_prefixes: "10.0.1.0/24" + virtual_network: miRedVirtual + when: rg is succeeded + + - name: Crear una interfaz de red + azure_rm_networkinterface: + resource_group: TestCursoAnsibleGroup + name: miInterfazDeRed + location: westeurope + virtual_network: miRedVirtual + subnet_name: miSubRed + when: rg is succeeded + + - name: Crear VM con imagen de Debian 12 + azure_rm_virtualmachine: + resource_group: TestCursoAnsibleGroup + name: miMaquinaVirtual + admin_username: "{{ username }}" + admin_password: "{{ password }}" + vm_size: Standard_B2als_v2 + network_interfaces: miInterfazDeRed + availability_set: miConjuntoDisponibilidad + location: westeurope + image: + offer: Debian-12 + publisher: Debian + sku: 12 + version: latest \ No newline at end of file diff --git a/examples/extra_vagrant_files/Vagrantfile1804 b/examples/extra_vagrant_files/Vagrantfile1804 new file mode 100644 index 0000000..bf50e44 --- /dev/null +++ b/examples/extra_vagrant_files/Vagrantfile1804 @@ -0,0 +1,28 @@ +Vagrant.configure(2) do |config| + config.vm.define "ansible" do |ansible| + ansible.vm.box = "bento/ubuntu-18.04" + ansible.vm.network "private_network", ip: "192.168.0.254" + ansible.vm.hostname = "ansible" + ansible.vm.provision :shell, :path => "ansible.sh" + end + config.vm.define "alfa" do |alfa| + alfa.vm.box = "bento/ubuntu-18.04" + alfa.vm.network "private_network", ip: "192.168.0.2" + alfa.vm.hostname = "alfa" + alfa.vm.provision :shell, :path => "ansible.sh" + alfa.vm.network "forwarded_port", guest: 3306, host: 3306 + end + config.vm.define "bravo" do |bravo| + bravo.vm.box = "bento/ubuntu-18.04" + bravo.vm.network "private_network", ip: "192.168.0.3" + bravo.vm.hostname = "bravo" + bravo.vm.provision :shell, :path => "ansible.sh" + end + config.vm.define "charlie" do |charlie| + charlie.vm.box = "bento/ubuntu-18.04" + charlie.vm.network "private_network", ip: "192.168.0.4" + charlie.vm.hostname = "charlie" + charlie.vm.provision :shell, :path => "ansible.sh" + charlie.vm.network "forwarded_port", guest: 80, host: 80 + end +end \ No newline at end of file diff --git a/examples/extra_vagrant_files/Vagrantfile2004 b/examples/extra_vagrant_files/Vagrantfile2004 new file mode 100644 index 0000000..c40a200 --- /dev/null +++ b/examples/extra_vagrant_files/Vagrantfile2004 @@ -0,0 +1,28 @@ +Vagrant.configure(2) do |config| + config.vm.define "ansible" do |ansible| + ansible.vm.box = "bento/ubuntu-20.04" + ansible.vm.network "private_network", ip: "192.168.0.254" + ansible.vm.hostname = "ansible" + ansible.vm.provision :shell, :path => "ansible.sh" + end + config.vm.define "alfa" do |alfa| + alfa.vm.box = "bento/ubuntu-20.04" + alfa.vm.network "private_network", ip: "192.168.0.2" + alfa.vm.hostname = "alfa" + alfa.vm.provision :shell, :path => "ansible.sh" + alfa.vm.network "forwarded_port", guest: 3306, host: 3306 + end + config.vm.define "bravo" do |bravo| + bravo.vm.box = "bento/ubuntu-20.04" + bravo.vm.network "private_network", ip: "192.168.0.3" + bravo.vm.hostname = "bravo" + bravo.vm.provision :shell, :path => "ansible.sh" + end + config.vm.define "charlie" do |charlie| + charlie.vm.box = "bento/ubuntu-20.04" + charlie.vm.network "private_network", ip: "192.168.0.4" + charlie.vm.hostname = "charlie" + charlie.vm.provision :shell, :path => "ansible.sh" + charlie.vm.network "forwarded_port", guest: 80, host: 80 + end + end \ No newline at end of file diff --git a/examples/extra_vagrant_files/Vagrantfile2104 b/examples/extra_vagrant_files/Vagrantfile2104 new file mode 100644 index 0000000..ae64d87 --- /dev/null +++ b/examples/extra_vagrant_files/Vagrantfile2104 @@ -0,0 +1,28 @@ +Vagrant.configure(2) do |config| + config.vm.define "ansible" do |ansible| + ansible.vm.box = "ubuntu/hirsute64" + ansible.vm.network "private_network", ip: "192.168.0.254" + ansible.vm.hostname = "ansible" + ansible.vm.provision :shell, :path => "ansible.sh" + end + config.vm.define "alfa" do |alfa| + alfa.vm.box = "ubuntu/hirsute64" + alfa.vm.network "private_network", ip: "192.168.0.2" + alfa.vm.hostname = "alfa" + alfa.vm.provision :shell, :path => "ansible.sh" + alfa.vm.network "forwarded_port", guest: 3306, host: 3306 + end + config.vm.define "bravo" do |bravo| + bravo.vm.box = "ubuntu/hirsute64" + bravo.vm.network "private_network", ip: "192.168.0.3" + bravo.vm.hostname = "bravo" + bravo.vm.provision :shell, :path => "ansible.sh" + end + config.vm.define "charlie" do |charlie| + charlie.vm.box = "ubuntu/hirsute64" + charlie.vm.network "private_network", ip: "192.168.0.4" + charlie.vm.hostname = "charlie" + charlie.vm.provision :shell, :path => "ansible.sh" + charlie.vm.network "forwarded_port", guest: 80, host: 80 + end + end \ No newline at end of file diff --git a/examples/extra_vagrant_files/VagrantfileDebian b/examples/extra_vagrant_files/VagrantfileDebian new file mode 100644 index 0000000..3f66f75 --- /dev/null +++ b/examples/extra_vagrant_files/VagrantfileDebian @@ -0,0 +1,28 @@ +Vagrant.configure(2) do |config| + config.vm.define "ansible" do |ansible| + ansible.vm.box = "debian/bullseye64" + ansible.vm.network "private_network", ip: "192.168.0.254" + ansible.vm.hostname = "ansible" + ansible.vm.provision :shell, :path => "ansible.sh" + end + config.vm.define "alfa" do |alfa| + alfa.vm.box = "debian/bullseye64" + alfa.vm.network "private_network", ip: "192.168.0.2" + alfa.vm.hostname = "alfa" + alfa.vm.provision :shell, :path => "ansible.sh" + alfa.vm.network "forwarded_port", guest: 3306, host: 3306 + end + config.vm.define "bravo" do |bravo| + bravo.vm.box = "debian/bullseye64" + bravo.vm.network "private_network", ip: "192.168.0.3" + bravo.vm.hostname = "bravo" + bravo.vm.provision :shell, :path => "ansible.sh" + end + config.vm.define "charlie" do |charlie| + charlie.vm.box = "debian/bullseye64" + charlie.vm.network "private_network", ip: "192.168.0.4" + charlie.vm.hostname = "charlie" + charlie.vm.provision :shell, :path => "ansible.sh" + charlie.vm.network "forwarded_port", guest: 80, host: 80 + end + end \ No newline at end of file diff --git a/examples/extra_vagrant_files/essential_box/Vagrantfile b/examples/extra_vagrant_files/essential_box/Vagrantfile new file mode 100755 index 0000000..20409ae --- /dev/null +++ b/examples/extra_vagrant_files/essential_box/Vagrantfile @@ -0,0 +1,11 @@ +Vagrant.configure(2) do |config| + config.vm.box = "bento/ubuntu-18.04" + config.vm.network "private_network", ip: "192.168.33.10" + config.vm.hostname = "client.vagrant.local" + config.vm.provision :shell, :path => "install.sh" + config.vm.provider "virtualbox" do |v| + v.memory = 512 + v.cpus = 1 + v.name = "webserver" + end +end diff --git a/examples/extra_vagrant_files/essential_box/install.sh b/examples/extra_vagrant_files/essential_box/install.sh new file mode 100644 index 0000000..f776fdb --- /dev/null +++ b/examples/extra_vagrant_files/essential_box/install.sh @@ -0,0 +1,3 @@ +set -eux +apt-get update +apt-get install -y --no-install-recommends ansible \ No newline at end of file diff --git a/examples/extra_vagrant_files/multi_agent_setup/VagrantFile b/examples/extra_vagrant_files/multi_agent_setup/VagrantFile new file mode 100644 index 0000000..703a157 --- /dev/null +++ b/examples/extra_vagrant_files/multi_agent_setup/VagrantFile @@ -0,0 +1,39 @@ +Vagrant.configure(2) do |config| + config.vm.define "webserver01" do |webserver01| + webserver01.vm.box = "bento/ubuntu-18.04" + webserver01.vm.network "private_network", ip: "192.168.0.6" + webserver01.vm.hostname = "webserver01" + end + config.vm.define "webserver02" do |webserver02| + webserver02.vm.box = "bento/ubuntu-18.04" + webserver02.vm.network "private_network", ip: "192.168.0.9" + webserver02.vm.hostname = "webserver02" + end + config.vm.define "database01" do |database01| + database01.vm.box = "bento/ubuntu-18.04" + database01.vm.network "private_network", ip: "192.168.0.5" + database01.vm.hostname = "database01" + end + config.vm.define "database02" do |database02| + database02.vm.box = "bento/ubuntu-18.04" + database02.vm.network "private_network", ip: "192.168.0.8" + database02.vm.hostname = "database02" + end + config.vm.define "loadbalancer01" do |loadbalancer01| + loadbalancer01.vm.box = "bento/ubuntu-18.04" + loadbalancer01.vm.network "private_network", ip: "192.168.0.4" + loadbalancer01.vm.hostname = "loadbalancer01" + end + config.vm.define "loadbalancer02" do |loadbalancer02| + loadbalancer02.vm.box = "bento/ubuntu-18.04" + loadbalancer02.vm.network "private_network", ip: "192.168.0.7" + loadbalancer02.vm.hostname = "loadbalancer02" + end + + config.vm.define "ansible" do |ansible| + ansible.vm.box = "bento/ubuntu-18.04" + ansible.vm.network "private_network", ip: "192.168.0.254" + ansible.vm.hostname = "ansible" + ansible.vm.provision :shell, :path => "install.sh" + end +end diff --git a/examples/extra_vagrant_files/multi_agent_setup/install.sh b/examples/extra_vagrant_files/multi_agent_setup/install.sh new file mode 100644 index 0000000..f776fdb --- /dev/null +++ b/examples/extra_vagrant_files/multi_agent_setup/install.sh @@ -0,0 +1,3 @@ +set -eux +apt-get update +apt-get install -y --no-install-recommends ansible \ No newline at end of file diff --git a/misc/all-hosts b/misc/all-hosts new file mode 100644 index 0000000..321815f --- /dev/null +++ b/misc/all-hosts @@ -0,0 +1,11 @@ +[control] +192.168.11.10 ansible_connection=local + +[database] +192.168.11.20 + +[loadbalancer] +192.168.11.30 + +[webserver] +192.168.11.40 \ No newline at end of file diff --git a/misc/arquitectura-ansible.pdf b/misc/arquitectura-ansible.pdf new file mode 100644 index 0000000..1313e10 Binary files /dev/null and b/misc/arquitectura-ansible.pdf differ diff --git a/misc/nginx.conf b/misc/nginx.conf new file mode 100644 index 0000000..9b8dc01 --- /dev/null +++ b/misc/nginx.conf @@ -0,0 +1,56 @@ +# Archivo de configuración nginx.conf + +user www-data; +worker_processes auto; +pid /run/nginx.pid; +include /etc/nginx/modules-enabled/*.conf; + +events { + worker_connections 768; + # multi_accept on; +} + +http { + + ## + # Configuración básica + ## + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + ## + # Configuración de logs + ## + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + ## + # Gzip settings + ## + + gzip on; + gzip_disable "msie6"; + + # Configuración de virtual host + server { + listen 80 default_server; + listen [::]:80 default_server; + + root /var/www/html; + index index.html index.htm index.nginx-debian.html; + + server_name _; + + location / { + try_files $uri $uri/ =404; + } + } +}