Added all files
This commit is contained in:
78
.gitignore
vendored
Executable file
78
.gitignore
vendored
Executable file
@@ -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
|
||||||
229
README.md
Executable file
229
README.md
Executable file
@@ -0,0 +1,229 @@
|
|||||||
|
[](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.
|
||||||
|
|
||||||
|
[](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)
|
||||||
59
Vagrantfile
vendored
Normal file
59
Vagrantfile
vendored
Normal file
@@ -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
|
||||||
6
ansible.sh
Normal file
6
ansible.sh
Normal file
@@ -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
|
||||||
3
examples/000_example/group_vars/all
Executable file
3
examples/000_example/group_vars/all
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
httpd_port: 80
|
||||||
|
ntpserver: 192.168.0.2
|
||||||
7
examples/000_example/group_vars/webservers
Executable file
7
examples/000_example/group_vars/webservers
Executable file
@@ -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
|
||||||
2
examples/000_example/hosts
Executable file
2
examples/000_example/hosts
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
[webservers]
|
||||||
|
192.168.0.2
|
||||||
38
examples/000_example/roles/apache/README.md
Executable file
38
examples/000_example/roles/apache/README.md
Executable file
@@ -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).
|
||||||
2
examples/000_example/roles/apache/defaults/main.yml
Executable file
2
examples/000_example/roles/apache/defaults/main.yml
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
# defaults file for apache
|
||||||
4
examples/000_example/roles/apache/handlers/main.yml
Executable file
4
examples/000_example/roles/apache/handlers/main.yml
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
# handlers file for apache
|
||||||
|
- name: restart apache
|
||||||
|
service: name=apache2 state=restarted
|
||||||
57
examples/000_example/roles/apache/meta/main.yml
Executable file
57
examples/000_example/roles/apache/meta/main.yml
Executable file
@@ -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.
|
||||||
19
examples/000_example/roles/apache/tasks/main.yml
Executable file
19
examples/000_example/roles/apache/tasks/main.yml
Executable file
@@ -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
|
||||||
225
examples/000_example/roles/apache/templates/httpd.conf.j2
Executable file
225
examples/000_example/roles/apache/templates/httpd.conf.j2
Executable file
@@ -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 <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>);
|
||||||
|
# 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 <VirtualHost>
|
||||||
|
# container, error messages relating to that virtual host will be
|
||||||
|
# logged here. If you *do* define an error logfile for a <VirtualHost>
|
||||||
|
# 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.
|
||||||
|
<Directory />
|
||||||
|
Options FollowSymLinks
|
||||||
|
AllowOverride None
|
||||||
|
Require all denied
|
||||||
|
</Directory>
|
||||||
|
|
||||||
|
<Directory /usr/share>
|
||||||
|
AllowOverride None
|
||||||
|
Require all granted
|
||||||
|
</Directory>
|
||||||
|
|
||||||
|
<Directory /var/www/>
|
||||||
|
Options FollowSymLinks
|
||||||
|
AllowOverride None
|
||||||
|
Require all granted
|
||||||
|
</Directory>
|
||||||
|
|
||||||
|
#<Directory /srv/>
|
||||||
|
# Options Indexes FollowSymLinks
|
||||||
|
# AllowOverride None
|
||||||
|
# Require all granted
|
||||||
|
#</Directory>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
<FilesMatch "^\.ht">
|
||||||
|
Require all denied
|
||||||
|
</FilesMatch>
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# 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
|
||||||
6
examples/000_example/roles/apache/templates/index.html.j2
Executable file
6
examples/000_example/roles/apache/templates/index.html.j2
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
{{ apache_test_message }} {{ ansible_distribution }} {{ ansible_distribution_version }} <br>
|
||||||
|
Current Host: {{ ansible_hostname }} <br>
|
||||||
|
Server list: <br>
|
||||||
|
{% for host in groups.webservers %}
|
||||||
|
{{ host }} <br>
|
||||||
|
{% endfor %}
|
||||||
2
examples/000_example/roles/apache/tests/inventory
Executable file
2
examples/000_example/roles/apache/tests/inventory
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
localhost
|
||||||
|
|
||||||
5
examples/000_example/roles/apache/tests/test.yml
Executable file
5
examples/000_example/roles/apache/tests/test.yml
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: webservers
|
||||||
|
remote_user: root
|
||||||
|
roles:
|
||||||
|
- apache
|
||||||
2
examples/000_example/roles/apache/vars/main.yml
Executable file
2
examples/000_example/roles/apache/vars/main.yml
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
# vars file for apache
|
||||||
38
examples/000_example/roles/common/README.md
Executable file
38
examples/000_example/roles/common/README.md
Executable file
@@ -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).
|
||||||
2
examples/000_example/roles/common/defaults/main.yml
Executable file
2
examples/000_example/roles/common/defaults/main.yml
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
# defaults file for common
|
||||||
4
examples/000_example/roles/common/handlers/main.yml
Executable file
4
examples/000_example/roles/common/handlers/main.yml
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
# handlers file for common
|
||||||
|
- name: restart ntp
|
||||||
|
service: name=ntpd state=restarted
|
||||||
57
examples/000_example/roles/common/meta/main.yml
Executable file
57
examples/000_example/roles/common/meta/main.yml
Executable file
@@ -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.
|
||||||
9
examples/000_example/roles/common/tasks/main.yml
Executable file
9
examples/000_example/roles/common/tasks/main.yml
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
# tasks file for common
|
||||||
|
- name: install epel repo
|
||||||
|
apt:
|
||||||
|
name: epel-release
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- include: selinux.yml
|
||||||
|
- include: ntp.yml
|
||||||
15
examples/000_example/roles/common/tasks/ntp.yml
Executable file
15
examples/000_example/roles/common/tasks/ntp.yml
Executable file
@@ -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
|
||||||
13
examples/000_example/roles/common/tasks/selinux.yml
Executable file
13
examples/000_example/roles/common/tasks/selinux.yml
Executable file
@@ -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
|
||||||
7
examples/000_example/roles/common/templates/ntp.conf.j2
Executable file
7
examples/000_example/roles/common/templates/ntp.conf.j2
Executable file
@@ -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
|
||||||
2
examples/000_example/roles/common/tests/inventory
Executable file
2
examples/000_example/roles/common/tests/inventory
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
localhost
|
||||||
|
|
||||||
5
examples/000_example/roles/common/tests/test.yml
Executable file
5
examples/000_example/roles/common/tests/test.yml
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: localhost
|
||||||
|
remote_user: root
|
||||||
|
roles:
|
||||||
|
- common
|
||||||
2
examples/000_example/roles/common/vars/main.yml
Executable file
2
examples/000_example/roles/common/vars/main.yml
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
# vars file for common
|
||||||
7
examples/000_example/site.yml
Executable file
7
examples/000_example/site.yml
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
- name: install and start apache
|
||||||
|
hosts: webservers
|
||||||
|
remote_user: root
|
||||||
|
become: yes
|
||||||
|
roles:
|
||||||
|
- apache
|
||||||
4
examples/000_initial_example/001-hostname.yml
Normal file
4
examples/000_initial_example/001-hostname.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
tasks:
|
||||||
|
- command: hostname
|
||||||
19
examples/000_initial_example/hosts
Normal file
19
examples/000_initial_example/hosts
Normal file
@@ -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
|
||||||
12
examples/000_initial_examples/etc_ansible_hosts
Executable file
12
examples/000_initial_examples/etc_ansible_hosts
Executable file
@@ -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
|
||||||
5
examples/000_initial_examples/hostname.yml
Normal file
5
examples/000_initial_examples/hostname.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
tasks:
|
||||||
|
- name: get server hostname
|
||||||
|
command: hostname
|
||||||
12
examples/000_initial_examples/your-first-hosts-file
Normal file
12
examples/000_initial_examples/your-first-hosts-file
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[loadbalancer]
|
||||||
|
lb01
|
||||||
|
|
||||||
|
[webserver]
|
||||||
|
app01
|
||||||
|
app02
|
||||||
|
|
||||||
|
[database]
|
||||||
|
db01
|
||||||
|
|
||||||
|
[control]
|
||||||
|
control ansible_connection=local
|
||||||
5
examples/001_apt/database.yml
Normal file
5
examples/001_apt/database.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: database
|
||||||
|
tasks:
|
||||||
|
- name: install mysql-server
|
||||||
|
apt: name=mysql-server state=present update_cache=yes
|
||||||
5
examples/001_apt/hostname.yml
Normal file
5
examples/001_apt/hostname.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
tasks:
|
||||||
|
- name: get server hostname
|
||||||
|
command: hostname
|
||||||
5
examples/001_apt/hosts
Normal file
5
examples/001_apt/hosts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
[database]
|
||||||
|
192.168.0.2
|
||||||
|
|
||||||
|
[loadbalancer]
|
||||||
|
192.168.0.3
|
||||||
5
examples/001_apt/loadbalancer.yml
Normal file
5
examples/001_apt/loadbalancer.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: loadbalancer
|
||||||
|
tasks:
|
||||||
|
- name: install nginx
|
||||||
|
apt: name=nginx state=present update_cache=yes
|
||||||
6
examples/002_become/database.yml
Normal file
6
examples/002_become/database.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
- hosts: database
|
||||||
|
become: true
|
||||||
|
tasks:
|
||||||
|
- name: install mysql-server
|
||||||
|
apt: name=mysql-server state=present update_cache=yes
|
||||||
5
examples/002_become/hostname.yml
Normal file
5
examples/002_become/hostname.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
tasks:
|
||||||
|
- name: get server hostname
|
||||||
|
command: hostname
|
||||||
8
examples/002_become/hosts
Normal file
8
examples/002_become/hosts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[database]
|
||||||
|
192.168.0.2
|
||||||
|
|
||||||
|
[loadbalancer]
|
||||||
|
192.168.0.3
|
||||||
|
|
||||||
|
[webserver]
|
||||||
|
192.168.0.4
|
||||||
6
examples/002_become/loadbalancer.yml
Normal file
6
examples/002_become/loadbalancer.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
- hosts: loadbalancer
|
||||||
|
become: true
|
||||||
|
tasks:
|
||||||
|
- name: install nginx
|
||||||
|
apt: name=nginx state=present update_cache=yes
|
||||||
6
examples/003_with_items/database.yml
Normal file
6
examples/003_with_items/database.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
- hosts: database
|
||||||
|
become: true
|
||||||
|
tasks:
|
||||||
|
- name: install mysql-server
|
||||||
|
apt: name=mysql-server state=present update_cache=yes
|
||||||
5
examples/003_with_items/hostname.yml
Normal file
5
examples/003_with_items/hostname.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
tasks:
|
||||||
|
- name: get server hostname
|
||||||
|
command: hostname
|
||||||
6
examples/003_with_items/loadbalancer.yml
Normal file
6
examples/003_with_items/loadbalancer.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
- hosts: loadbalancer
|
||||||
|
become: true
|
||||||
|
tasks:
|
||||||
|
- name: install nginx
|
||||||
|
apt: name=nginx state=present update_cache=yes
|
||||||
12
examples/003_with_items/webserver.yml
Normal file
12
examples/003_with_items/webserver.yml
Normal file
@@ -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
|
||||||
|
|
||||||
8
examples/004_services/control.yml
Normal file
8
examples/004_services/control.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
- hosts: control
|
||||||
|
become: true
|
||||||
|
tasks:
|
||||||
|
- name: install tools
|
||||||
|
apt: name={{item}} state=present update_cache=yes
|
||||||
|
with_items:
|
||||||
|
- uacme
|
||||||
9
examples/004_services/database.yml
Normal file
9
examples/004_services/database.yml
Normal file
@@ -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
|
||||||
9
examples/004_services/loadbalancer.yml
Normal file
9
examples/004_services/loadbalancer.yml
Normal file
@@ -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
|
||||||
5
examples/004_services/playbooks/hostname.yml
Normal file
5
examples/004_services/playbooks/hostname.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
tasks:
|
||||||
|
- name: get server hostname
|
||||||
|
command: hostname
|
||||||
18
examples/004_services/playbooks/stack_restart.yml
Normal file
18
examples/004_services/playbooks/stack_restart.yml
Normal file
@@ -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
|
||||||
17
examples/004_services/playbooks/stack_restart.yml.save
Normal file
17
examples/004_services/playbooks/stack_restart.yml.save
Normal file
@@ -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
|
||||||
18
examples/004_services/playbooks/stack_stopped.yml
Normal file
18
examples/004_services/playbooks/stack_stopped.yml
Normal file
@@ -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
|
||||||
14
examples/004_services/webserver.yml
Normal file
14
examples/004_services/webserver.yml
Normal file
@@ -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
|
||||||
8
examples/005_stack_restart/control.yml
Normal file
8
examples/005_stack_restart/control.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
- hosts: control
|
||||||
|
become: true
|
||||||
|
tasks:
|
||||||
|
- name: install tools
|
||||||
|
apt: name={{item}} state=present update_cache=yes
|
||||||
|
with_items:
|
||||||
|
- uacme
|
||||||
9
examples/005_stack_restart/database.yml
Normal file
9
examples/005_stack_restart/database.yml
Normal file
@@ -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
|
||||||
9
examples/005_stack_restart/loadbalancer.yml
Normal file
9
examples/005_stack_restart/loadbalancer.yml
Normal file
@@ -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
|
||||||
5
examples/005_stack_restart/playbook/hostname.yml
Normal file
5
examples/005_stack_restart/playbook/hostname.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
tasks:
|
||||||
|
- name: get server hostname
|
||||||
|
command: hostname
|
||||||
28
examples/005_stack_restart/playbook/stack_restart.yml
Normal file
28
examples/005_stack_restart/playbook/stack_restart.yml
Normal file
@@ -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
|
||||||
14
examples/005_stack_restart/webserver.yml
Normal file
14
examples/005_stack_restart/webserver.yml
Normal file
@@ -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
|
||||||
8
examples/006_notify_handlers/control.yml
Normal file
8
examples/006_notify_handlers/control.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
- hosts: control
|
||||||
|
become: true
|
||||||
|
tasks:
|
||||||
|
- name: install tools
|
||||||
|
apt: name={{item}} state=present update_cache=yes
|
||||||
|
with_items:
|
||||||
|
- curl
|
||||||
9
examples/006_notify_handlers/database.yml
Normal file
9
examples/006_notify_handlers/database.yml
Normal file
@@ -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
|
||||||
20
examples/006_notify_handlers/demo/app/demo.py
Normal file
20
examples/006_notify_handlers/demo/app/demo.py
Normal file
@@ -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()
|
||||||
10
examples/006_notify_handlers/demo/app/demo.wsgi
Normal file
10
examples/006_notify_handlers/demo/app/demo.wsgi
Normal file
@@ -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
|
||||||
9
examples/006_notify_handlers/demo/app/requirements.txt
Normal file
9
examples/006_notify_handlers/demo/app/requirements.txt
Normal file
@@ -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
|
||||||
11
examples/006_notify_handlers/demo/demo.conf
Normal file
11
examples/006_notify_handlers/demo/demo.conf
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<VirtualHost *>
|
||||||
|
WSGIDaemonProcess demo threads=5
|
||||||
|
WSGIScriptAlias / /var/www/demo/demo.wsgi
|
||||||
|
|
||||||
|
<Directory /var/www/demo>
|
||||||
|
WSGIProcessGroup demo
|
||||||
|
WSGIApplicationGroup %{GLOBAL}
|
||||||
|
Order deny,allow
|
||||||
|
Allow from all
|
||||||
|
</Directory>
|
||||||
|
</VirtualHost>
|
||||||
9
examples/006_notify_handlers/loadbalancer.yml
Normal file
9
examples/006_notify_handlers/loadbalancer.yml
Normal file
@@ -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
|
||||||
5
examples/006_notify_handlers/playbook/hostname.yml
Normal file
5
examples/006_notify_handlers/playbook/hostname.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
tasks:
|
||||||
|
- name: get server hostname
|
||||||
|
command: hostname
|
||||||
28
examples/006_notify_handlers/playbook/stack_restart.yml
Normal file
28
examples/006_notify_handlers/playbook/stack_restart.yml
Normal file
@@ -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
|
||||||
22
examples/006_notify_handlers/webserver.yml
Normal file
22
examples/006_notify_handlers/webserver.yml
Normal file
@@ -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
|
||||||
8
examples/007_files_copy/control.yml
Normal file
8
examples/007_files_copy/control.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
- hosts: control
|
||||||
|
become: true
|
||||||
|
tasks:
|
||||||
|
- name: install tools
|
||||||
|
apt: name={{item}} state=present update_cache=yes
|
||||||
|
with_items:
|
||||||
|
- curl
|
||||||
9
examples/007_files_copy/database.yml
Normal file
9
examples/007_files_copy/database.yml
Normal file
@@ -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
|
||||||
20
examples/007_files_copy/demo/app/demo.py
Normal file
20
examples/007_files_copy/demo/app/demo.py
Normal file
@@ -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()
|
||||||
10
examples/007_files_copy/demo/app/demo.wsgi
Normal file
10
examples/007_files_copy/demo/app/demo.wsgi
Normal file
@@ -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
|
||||||
9
examples/007_files_copy/demo/app/requirements.txt
Normal file
9
examples/007_files_copy/demo/app/requirements.txt
Normal file
@@ -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
|
||||||
11
examples/007_files_copy/demo/demo.conf
Normal file
11
examples/007_files_copy/demo/demo.conf
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<VirtualHost *>
|
||||||
|
WSGIDaemonProcess demo threads=5
|
||||||
|
WSGIScriptAlias / /var/www/demo/demo.wsgi
|
||||||
|
|
||||||
|
<Directory /var/www/demo>
|
||||||
|
WSGIProcessGroup demo
|
||||||
|
WSGIApplicationGroup %{GLOBAL}
|
||||||
|
Order deny,allow
|
||||||
|
Allow from all
|
||||||
|
</Directory>
|
||||||
|
</VirtualHost>
|
||||||
9
examples/007_files_copy/loadbalancer.yml
Normal file
9
examples/007_files_copy/loadbalancer.yml
Normal file
@@ -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
|
||||||
5
examples/007_files_copy/playbook/hostname.yml
Normal file
5
examples/007_files_copy/playbook/hostname.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
tasks:
|
||||||
|
- name: get server hostname
|
||||||
|
command: hostname
|
||||||
28
examples/007_files_copy/playbook/stack_restart.yml
Normal file
28
examples/007_files_copy/playbook/stack_restart.yml
Normal file
@@ -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
|
||||||
30
examples/007_files_copy/webserver.yml
Normal file
30
examples/007_files_copy/webserver.yml
Normal file
@@ -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
|
||||||
8
examples/008_pip/control.yml
Normal file
8
examples/008_pip/control.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
- hosts: control
|
||||||
|
become: true
|
||||||
|
tasks:
|
||||||
|
- name: install tools
|
||||||
|
apt: name={{item}} state=present update_cache=yes
|
||||||
|
with_items:
|
||||||
|
- curl
|
||||||
9
examples/008_pip/database.yml
Normal file
9
examples/008_pip/database.yml
Normal file
@@ -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
|
||||||
20
examples/008_pip/demo/app/demo.py
Normal file
20
examples/008_pip/demo/app/demo.py
Normal file
@@ -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()
|
||||||
10
examples/008_pip/demo/app/demo.wsgi
Normal file
10
examples/008_pip/demo/app/demo.wsgi
Normal file
@@ -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
|
||||||
9
examples/008_pip/demo/app/requirements.txt
Normal file
9
examples/008_pip/demo/app/requirements.txt
Normal file
@@ -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
|
||||||
11
examples/008_pip/demo/demo.conf
Normal file
11
examples/008_pip/demo/demo.conf
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<VirtualHost *>
|
||||||
|
WSGIDaemonProcess demo threads=5
|
||||||
|
WSGIScriptAlias / /var/www/demo/demo.wsgi
|
||||||
|
|
||||||
|
<Directory /var/www/demo>
|
||||||
|
WSGIProcessGroup demo
|
||||||
|
WSGIApplicationGroup %{GLOBAL}
|
||||||
|
Order deny,allow
|
||||||
|
Allow from all
|
||||||
|
</Directory>
|
||||||
|
</VirtualHost>
|
||||||
9
examples/008_pip/loadbalancer.yml
Normal file
9
examples/008_pip/loadbalancer.yml
Normal file
@@ -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
|
||||||
5
examples/008_pip/playbook/hostname.yml
Normal file
5
examples/008_pip/playbook/hostname.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
tasks:
|
||||||
|
- name: get server hostname
|
||||||
|
command: hostname
|
||||||
28
examples/008_pip/playbook/stack_restart.yml
Normal file
28
examples/008_pip/playbook/stack_restart.yml
Normal file
@@ -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
|
||||||
34
examples/008_pip/webserver.yml
Normal file
34
examples/008_pip/webserver.yml
Normal file
@@ -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
|
||||||
8
examples/009_files/control.yml
Normal file
8
examples/009_files/control.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
- hosts: control
|
||||||
|
become: true
|
||||||
|
tasks:
|
||||||
|
- name: install tools
|
||||||
|
apt: name={{item}} state=present update_cache=yes
|
||||||
|
with_items:
|
||||||
|
- curl
|
||||||
9
examples/009_files/database.yml
Normal file
9
examples/009_files/database.yml
Normal file
@@ -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
|
||||||
20
examples/009_files/demo/app/demo.py
Normal file
20
examples/009_files/demo/app/demo.py
Normal file
@@ -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()
|
||||||
10
examples/009_files/demo/app/demo.wsgi
Normal file
10
examples/009_files/demo/app/demo.wsgi
Normal file
@@ -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
|
||||||
9
examples/009_files/demo/app/requirements.txt
Normal file
9
examples/009_files/demo/app/requirements.txt
Normal file
@@ -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
|
||||||
11
examples/009_files/demo/demo.conf
Normal file
11
examples/009_files/demo/demo.conf
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<VirtualHost *>
|
||||||
|
WSGIDaemonProcess demo threads=5
|
||||||
|
WSGIScriptAlias / /var/www/demo/demo.wsgi
|
||||||
|
|
||||||
|
<Directory /var/www/demo>
|
||||||
|
WSGIProcessGroup demo
|
||||||
|
WSGIApplicationGroup %{GLOBAL}
|
||||||
|
Order deny,allow
|
||||||
|
Allow from all
|
||||||
|
</Directory>
|
||||||
|
</VirtualHost>
|
||||||
9
examples/009_files/loadbalancer.yml
Normal file
9
examples/009_files/loadbalancer.yml
Normal file
@@ -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
|
||||||
5
examples/009_files/playbook/hostname.yml
Normal file
5
examples/009_files/playbook/hostname.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
tasks:
|
||||||
|
- name: get server hostname
|
||||||
|
command: hostname
|
||||||
28
examples/009_files/playbook/stack_restart.yml
Normal file
28
examples/009_files/playbook/stack_restart.yml
Normal file
@@ -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
|
||||||
42
examples/009_files/webserver.yml
Normal file
42
examples/009_files/webserver.yml
Normal file
@@ -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
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user