@slueg
Denoting an element of a set which is unchanged in value when multiplied or otherwise operated on by itself.
(well... theoretically)
- hosts: cambuildr-servers
roles:
- basic-server-setup
- setup-cambuildr
- setup-filebeat
- setup-watchmancommon/ # this hierarchy represents a "role"
tasks/ #
main.yml # <-- tasks file can include smaller files if warranted
handlers/ #
main.yml # <-- handlers file
templates/ # <-- files for use with the template resource
ntp.conf.j2 # <------- templates end in .j2
files/ #
bar.txt # <-- files for use with the copy resource
foo.sh # <-- script files for use with the script resource
vars/ #
main.yml # <-- variables associated with this role
defaults/ #
main.yml # <-- default lower priority variables for this role
meta/ #
main.yml # <-- role dependencies- name: create cambuildr app and varys subfolders
file:
path: "{{ item }}"
state: directory
owner: "{{ cambuildr_user }}"
group: "{{ cambuildr_group }}"
with_items:
- "{{ cambuildr_app_dir }}/storage"
- "{{ cambuildr_app_dir }}/releases"
- "{{ cambuildr_app_dir }}/filesystem/private"
- "{{ cambuildr_app_dir }}/filesystem/public"
- "{{ cambuildr_varys_dir }}/releases"
- "{{ cambuildr_generic_theme_dir }}/releases"- name: Enable apache2 module <headers>
apache2_module:
state: present
name: headers
notify:
- restart apache2- name: Disable apache2 docs configuration for Apache 2.4 on Ubuntu 14.04
command: a2disconf apache2-doc
args:
removes: /etc/apache2/conf-enabled/apache2-doc.conf
when: ansible_distribution_major_version == "14"
notify:
- restart apache2- name: restart apache2
service:
name: apache2
state: restartedtask:
handler:
- name: flush to the rescue
meta: flush_handlers- name: set sshd_config file
template:
src: sshd_config.j2
dest: /etc/ssh/sshd_config
backup: yes
owner: root
group: root
mode: 0644
validate: '/usr/sbin/sshd -T -f %s'
notify:
- restart sshdtask:
###############################################################################
#
# {{ ansible_managed }}
#
#==============================================================================
# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
{% if ansible_distribution_major_version == "14" %}
HostKey /etc/ssh/ssh_host_ed25519_key
{% endif %}
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes
# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
{% if ansible_distribution_major_version == "12" %}
ServerKeyBits 768
{% else %}
ServerKeyBits 1024
{% endif %}sshd_config.j2:
(the last listed variables winning prioritization)
---
cambuildr_base_dir: XXX
cambuildr_user: XXX
cambuildr_group: XXX
db_username: XXX
db_password: XXX
mail_server_active: XXX
watchman_active: true
watchman_db_password: XXX
inventories/hosteurope-server/host-vars/myHostName:
ansible -m setup myHostName- name: set bash prompt
lineinfile:
dest: ~/.bashrc
line: 'export PS1="\[\e[1;37;41m\] {{ inventory_hostname }} (\u) \[\e[0m\]:\[\e[0;34m\]\w\[\e[0m\] ⚡️ "'
state: presentuse a fact:
---
# Stores the packages depending on the ubuntu version (12 or 14) with their state (absent or present)
basic_apt_packages_for_ubuntu:
"14":
- name: curl
state: present
- name: php5-curl
state: present
- name: php5-json
state: present
- name: php5-gd
state: present
- name: php5-readline
state: present
- name: php5-mysqlnd
state: present
"12":
- name: curl
state: present
- name: php5-curl
state: present
- name: php5-json
state: present
- name: php5-gd
state: present
- name: php5-mysql
state: present
define default:
- name: install basic packages
apt:
name: "{{ item.name }}"
state: "{{ item.state }}"
with_items: "{{ basic_apt_packages_for_ubuntu[ansible_distribution_major_version] }}"
use defined variable, fact and loop:
⚡️ ~ $ brew install ansiblesetup:
⚡️ ~ $ ansible --version
ansible 2.2.0.0
config file =
configured module search path = Default w/o overridesvalidate and check version:
⚡️ ~ $ ansible -m setup myHostName
⚡️ ~ $ ansible -m ping allrun a single module (facts and ping):
⚡️ ~ $ ansible-playbook my-playbook.ymlrun a playbook: