Skip to content
Snippets Groups Projects
Commit cfcd468b authored by jurgenhaas's avatar jurgenhaas
Browse files

ansible-playbooks/general#85 Linting

parent 16d50156
No related branches found
No related tags found
No related merge requests found
Showing
with 183 additions and 176 deletions
---
extends: 'default'
extends: default
rules:
truthy:
level: 'error'
level: error
allowed-values:
- 'yes'
- 'no'
- yes
- no
......@@ -115,7 +115,7 @@ because otherwise someone else could get access to your whole server farm.
your home directory.
3. Create your vault
Use the command ```ansible-vault create ~/.ansible/secrets``` and include
one line ```ansible_sudo_pass: 'YOURSUDOPASS'```. This is using your default
one line ```ansible_sudo_pass: YOURSUDOPASS```. This is using your default
editor for the console but you can configure that like ```export $EDITOR=nano```
to use the nano editor as an example. When saving the file, ansible-vault
will encrypt that file with your vault password contained in the vault.pwd file.
......
......@@ -5,46 +5,49 @@
---
# file: apt-pin.yml
- name: "Status"
- name: Status
hosts: all:!norootserver
become: yes
tags: 'status'
tags:
- status
tasks:
- name: "Get Apt Cache"
- name: Get Apt Cache
shell: apt-cache show {{ package }}
register: apt_cache
- name: "Get Installed Package"
- name: Get Installed Package
shell: dpkg -s {{ package }}
register: installed_package
- name: "Get Pin State"
- name: Get Pin State
stat: path='/etc/apt/preferences.d/{{ package }}'
register: pin_state
- name: "Show Apt Cache"
- name: Show Apt Cache
debug: var=apt_cache.stdout
- name: "Show Installed Package"
- name: Show Installed Package
debug: var=installed_package.stdout
- name: "Show Pin State"
- name: Show Pin State
debug: msg="Pin state is {{ pin_state.stat.exists }}"
- name: "Pin"
- name: Pin
hosts: all:!norootserver
become: yes
tags: 'pin'
tags:
- pin
tasks:
- name: "Pin Package"
- name: Pin Package
template:
src: 'apt-pin'
dest: '/etc/apt/preferences.d/{{ package }}'
owner: 'root'
group: 'root'
mode: '644'
src: apt-pin
dest: /etc/apt/preferences.d/{{ package }}
owner: root
group: root
mode: 644
- name: "Unpin"
- name: Unpin
hosts: all:!norootserver
become: yes
tags: 'unpin'
tags:
- unpin
tasks:
- name: "Unpin Package"
- name: Unpin Package
file:
path: '/etc/apt/preferences.d/{{ package }}'
state: 'absent'
path: /etc/apt/preferences.d/{{ package }}
state: absent
......@@ -7,23 +7,23 @@
- import_playbook: "validate.yml"
- name: "Flush Apt Cache"
- name: Flush Apt Cache
hosts: apt-proxy
gather_facts: false
become: yes
tasks:
- name: "Stop service"
- name: Stop service
service: name='apt-cacher-ng' state=stopped
- name: "Delete cache"
- name: Delete cache
file:
path=/var/cache/apt-cacher-ng
state=absent
- name: "Create empty cache"
- name: Create empty cache
file:
path=/var/cache/apt-cacher-ng
state=directory
owner=apt-cacher-ng
group=apt-cacher-ng
mode='755'
- name: "Start service"
- name: Start service
service: name='apt-cacher-ng' state=started
......@@ -5,8 +5,8 @@
---
# file: composer-app.yml
- name: "Common"
- name: Common
hosts: "all:!norootserver"
become: yes
roles:
- 'drupal-cli'
- drupal-cli
......@@ -5,33 +5,33 @@
# file: etckeeper.yml
- name: "Etckeeper repository"
- name: Etckeeper repository
hosts: "{{ host|default('all') }}"
gather_facts: false
become: yes
vars:
gitlab:
host: 'gitlab.lakedrops.com'
hostkey: 'ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBL6B/gcLUzV1W3FtqTedAPdCB9nJIi6Q/ZiMdqBpu8P8lNz4jsDjiSbUi4Cr6j7vn3OwA3Z3NFGlaLvLXZdRaIY='
host: gitlab.lakedrops.com
hostkey: ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBL6B/gcLUzV1W3FtqTedAPdCB9nJIi6Q/ZiMdqBpu8P8lNz4jsDjiSbUi4Cr6j7vn3OwA3Z3NFGlaLvLXZdRaIY=
tasks:
- name: "Ensure SSH directory"
- name: Ensure SSH directory
file:
path: '/root/.ssh'
state: 'directory'
- name: "Add repo server host key to known hosts"
path: /root/.ssh
state: directory
- name: Add repo server host key to known hosts
known_hosts:
name: '{{ gitlab.host }}'
key: "{{ gitlab.host }} {{ gitlab.hostkey }}"
hash_host: yes
ignore_errors: yes
- name: "Ensure Python Components"
- name: Ensure Python Components
pip:
name: '{{ packages }}'
state: 'present'
state: present
vars:
packages:
- 'python-gitlab'
- name: "Create and configure repository"
- python-gitlab
- name: Create and configure repository
gitlab_host:
server_url: '{{ gitlab_issue.url }}'
validate_certs: true
......
......@@ -7,13 +7,13 @@
- import_playbook: "validate.yml"
- name: "Common"
- name: Common
hosts: "all:!norootserver"
become: yes
roles:
- common
- name: "Webserver"
- name: Webserver
hosts: "webserver"
become: yes
roles:
......@@ -22,7 +22,7 @@
- memcache
- redis
- name: "Log servers"
- name: Log servers
hosts: "logserver"
become: yes
roles:
......@@ -30,7 +30,7 @@
- kibana
- elastalert
- name: "General stuff"
- name: General stuff
hosts: "all:!norootserver"
become: yes
roles:
......@@ -41,26 +41,26 @@
- fail2ban
- gitlab-client
- name: "Oracle servers"
- name: Oracle servers
hosts: "dbserver_oracle"
become: yes
roles:
- oracle
- name: "MySQL servers"
- name: MySQL servers
hosts: "dbserver_mysql"
become: yes
roles:
- mysql
- mysql-client
- name: "MongoDB servers"
- name: MongoDB servers
hosts: "dbserver-mongodb"
become: yes
roles:
- mongodb
- name: "Drupal servers"
- name: Drupal servers
hosts: "webserver_drupal"
become: yes
roles:
......@@ -71,87 +71,87 @@
- drush
- drupalconsole
- name: "NextCloud servers"
- name: NextCloud servers
hosts: "webserver_nextcloud"
become: yes
roles:
- nextcloud
- mysql-client
- name: "Varnish servers"
- name: Varnish servers
hosts: "varnishserver"
become: yes
roles:
- varnish
- name: "Matomo servers"
- name: Matomo servers
hosts: "matomoserver:piwikserver"
become: yes
roles:
- matomo
- name: "Proxy servers"
- name: Proxy servers
hosts: "proxyserver"
become: yes
roles:
- haproxy
- name: "GitLab servers"
- name: GitLab servers
hosts: "gitlabserver"
become: yes
roles:
- gitlab
- name: "Compass instances"
- name: Compass instances
hosts: "compassinstance"
become: yes
roles:
- compass
- name: "nodeJS servers"
- name: nodeJS servers
hosts: "nodejsserver"
become: yes
roles:
- nodejs
- name: "SVN servers"
- name: SVN servers
hosts: "svnserver"
become: yes
roles:
- svnserver
- name: "APT proxies"
- name: APT proxies
hosts: "apt-proxy"
become: yes
roles:
- aptproxy
- name: "OpenPhoto servers"
- name: OpenPhoto servers
hosts: "openphotoserver"
become: yes
roles:
- openphoto
- name: "SFTP servers"
- name: SFTP servers
hosts: "sftpserver:webserver"
become: yes
roles:
- sftp
- name: "S3 clients"
- name: S3 clients
hosts: "s3client"
become: yes
roles:
- s3
- name: "Uptime Monitoring Servers"
- name: Uptime Monitoring Servers
hosts: "uptime"
become: yes
roles:
- uptime
- matterbridge
- name: "More general stuff"
- name: More general stuff
hosts: "all:!norootserver"
become: yes
roles:
......
......@@ -7,23 +7,24 @@
- import_playbook: "validate.yml"
- name: "Unprotect Firewall for a period of time"
- name: Unprotect Firewall for a period of time
hosts: all
gather_facts: false
become: yes
tags: 'unprotect'
tags:
- unprotect
tasks:
- name: "Set flag for unprotected mode"
- name: Set flag for unprotected mode
file:
path='/tmp/ANSIBLE_UNPROTECT_FIREWALL'
state='touch'
- name: "Restart Firewall"
- name: Restart Firewall
service:
name='firewall'
state=restarted
- name: "Remove flag for unprotected mode"
- name: Remove flag for unprotected mode
file:
path='/tmp/ANSIBLE_UNPROTECT_FIREWALL'
state='absent'
- name: "Queue Restart Firewall"
- name: Queue Restart Firewall
shell: echo 'service firewall restart' | at now +{{ unprotect_period|default(30) }}min
......@@ -5,49 +5,49 @@
# file: firstuser.yml
- name: "Setup first user"
- name: Setup first user
hosts: "{{ host|default('all') }}"
gather_facts: false
user: "{{ inituser|default(lookup('env','USER')) }}"
become: yes
vars:
first_user:
- name: "{{ firstuser|default(lookup('env','USER')) }}"
- name: '{{ firstuser|default(lookup('env','USER')) }}'
password: "{{ ansible_sudo_pass|default('My First Password')|password_hash('sha512') }}"
- name: "gitlab-runner"
- name: gitlab-runner
password: "{{ gitlab_runner_sudo_pass|default('My First Password')|password_hash('sha512') }}"
first_groups:
- name: 'sambashare'
- name: 'docker'
- name: 'www-docker'
- name: sambashare
- name: docker
- name: www-docker
gid: 82
tasks:
- name: "Ensure first groups"
- name: Ensure first groups
group:
name: '{{ item.name }}'
gid: '{{ item.gid|default(omit) }}'
state: 'present'
state: present
with_items: '{{ first_groups }}'
- name: "InitHost | Create first user"
- name: InitHost | Create first user
user:
name: '{{ item.name }}'
password: '{{ item.password }}'
group: 'root'
group: root
groups: "{{ users[item.name].groups|default('root,sudo,www-data') }}"
home: '/home/{{ item.name }}'
generate_ssh_key: 'yes'
home: /home/{{ item.name }}
generate_ssh_key: yes
ssh_key_bits: 2048
with_items: '{{ first_user }}'
- name: "InitHost | install user's public key for desktop-to-server communication"
- name: InitHost | install user's public key for desktop-to-server communication
authorized_key:
user: '{{ item.name }}'
key: "{{ lookup('file', inventory_dir + '/files/keys/' + item.name + '.d2s.pub') }}"
with_items: '{{ first_user }}'
- name: "Allow first user admins to have passwordless sudo"
- name: Allow first user admins to have passwordless sudo
lineinfile:
dest: '/etc/sudoers'
state: 'present'
regexp: '^{{ item.name }}'
dest: /etc/sudoers
state: present
regexp: ^{{ item.name }}
line: '{{ item.name }} ALL=(ALL) NOPASSWD: ALL'
validate: 'visudo -cf %s'
validate: visudo -cf %s
with_items: '{{ first_user }}'
......@@ -6,7 +6,7 @@
- import_playbook: "validate.yml"
- name: "Update local host"
- name: Update local host
hosts: "all"
connection: local
gather_facts: false
......@@ -14,20 +14,20 @@
tasks:
- name: "Ensure host in /etc/hosts"
- name: Ensure host in /etc/hosts
lineinfile:
dest: '/etc/hosts'
dest: /etc/hosts
regexp: "^{{ hostvars[inventory_hostname]['static_ipv4'] }} "
line: "{{ hostvars[inventory_hostname]['static_ipv4'] }} {{ inventory_hostname }}"
delegate_to: localhost
- name: "Check if gSTM for tunnel configurations is present"
- name: Check if gSTM for tunnel configurations is present
stat: path=/home/{{ lookup('env','USER') }}/.gSTM
register: gstm_directory
delegate_to: localhost
become: false
- name: "Update gSTM tunnel configurations"
- name: Update gSTM tunnel configurations
template:
src=gstm
dest=/home/{{ lookup('env','USER') }}/.gSTM/{{inventory_hostname}}.gstm
......@@ -37,10 +37,10 @@
become: false
when: gstm_directory.stat.exists
- name: "Update checks for Uptime"
- name: Update checks for Uptime
action: uptime
- name: "Check if local netdata installation exists"
- name: Check if local netdata installation exists
local_action: stat
path='/usr/share/netdata/web/index.html'
delegate_to: localhost
......@@ -48,7 +48,7 @@
register: netdata_local_available
changed_when: false
- name: "Install local dashboard"
- name: Install local dashboard
template:
src=tv-company.html
dest=/usr/share/netdata/web/{{ lookup('env','ANSIBLE_COMPANY') }}.html
......@@ -59,26 +59,27 @@
run_once: true
when: netdata_local_available.stat.exists
- name: "Create ssh_config file for JuiceSSH client"
- name: Create ssh_config file for JuiceSSH client
template:
src: 'ssh_config.jinja2'
src: ssh_config.jinja2
dest: '{{ lookup("env","HOME") }}/.ssh/ssh_config_{{ lookup("env","ANSIBLE_COMPANY") }}'
mode: '0644'
mode: 0644
delegate_to: localhost
run_once: true
- name: "Concatenate ssh_config files for JuiceSSH client"
shell: 'cat {{ lookup("env","HOME") }}/.ssh/ssh_config_* >{{ lookup("env","HOME") }}/.ssh/juice_ssh_config'
- name: Concatenate ssh_config files for JuiceSSH client
shell: cat {{ lookup("env","HOME") }}/.ssh/ssh_config_* >{{ lookup("env","HOME") }}/.ssh/juice_ssh_config
delegate_to: localhost
run_once: true
- name: "Update Heartbeat configurations"
- name: Update Heartbeat configurations
template:
src: 'heartbeat.yml.jinja2'
dest: '/var/dev/Tools/ansible/inventory/paragon/files/heartbeat/{{ lookup("env","ANSIBLE_COMPANY") }}.yml'
src: heartbeat.yml.jinja2
dest: /var/dev/Tools/ansible/inventory/paragon/files/heartbeat/{{ lookup("env","ANSIBLE_COMPANY") }}.yml
owner: "{{ lookup('env','USER') }}"
mode: '644'
mode: 644
delegate_to: localhost
run_once: true
become: false
tags: "heartbeat"
tags:
- heartbeat
......@@ -8,6 +8,6 @@
that:
- "'{{ main.ip }}' == '{{ lookup('dig', domain, 'qtype=A', '@8.8.8.8') }}'"
- "'' == '{{ lookup('dig', domain, 'qtype=AAAA', '@8.8.8.8') }}'"
msg: 'Domain {{ domain }} has an ERROR'
msg: Domain {{ domain }} has an ERROR
when: domain != 'localhost'
ignore_errors: true
......@@ -5,15 +5,15 @@
# file: init-python.yml
- name: "Python cleanup"
- name: Python cleanup
hosts: "{{ host|default('all') }}"
gather_facts: false
become: yes
tasks:
- name: "Remove system components"
- name: Remove system components
file:
path: '/usr/lib/python{{ item.0 }}/dist-packages/{{ item.1 }}'
state: 'absent'
path: /usr/lib/python{{ item.0 }}/dist-packages/{{ item.1 }}
state: absent
with_nested:
- ['2.7', '3']
- [
......@@ -29,30 +29,30 @@
'simplejson',
'simplejson-3.8.1.egg-info',
]
- name: "Remove Python Setuptools"
- name: Remove Python Setuptools
apt:
pkg: '{{ packages }}'
state: absent
vars:
packages:
- 'python-setuptools'
- 'python3-setuptools'
- name: "Install Python Setuptools"
- python-setuptools
- python3-setuptools
- name: Install Python Setuptools
apt:
pkg: '{{ packages }}'
state: latest
vars:
packages:
- 'python-setuptools'
- 'python3-setuptools'
- name: "Install Python Components"
- python-setuptools
- python3-setuptools
- name: Install Python Components
pip:
name: '{{ packages }}'
state: 'present'
state: present
vars:
packages:
- 'pycurl'
- 'pygobject'
- 'pyicu'
- 'pyyaml'
- 'simplejson'
- pycurl
- pygobject
- pyicu
- pyyaml
- simplejson
......@@ -4,7 +4,7 @@
---
# file: inithost.yml
- name: "Prepare cloud"
- name: Prepare cloud
hosts: "localhost"
connection: local
gather_facts: false
......@@ -12,36 +12,36 @@
roles:
- { role: cloud, mode: inithost }
- name: "Prepare 1"
- name: Prepare 1
hosts: "{{ host }}"
connection: local
gather_facts: false
become: no
tasks:
- name: "InitHost | Remove previous entries from known_hosts"
- name: InitHost | Remove previous entries from known_hosts
known_hosts:
name="{{ item }}"
state="absent"
with_items:
- '{{ inithostip|default(static_ipv4) }}'
- '{{ host }}'
- name: "InitHost | Copy root id to new host"
- {{ inithostip|default(static_ipv4) }}
- {{ host }}
- name: InitHost | Copy root id to new host
shell: "ssh-copy-id -i {{ inituser }}@{{ inithostip|default(static_ipv4) }} -o ControlMaster=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no -o IdentitiesOnly=yes"
register: inithost_ssh_copy_id
changed_when: "inithost_ssh_copy_id.rc != 0"
failed_when: false
- name: "InitHost | Update APT"
- name: InitHost | Update APT
shell: "ssh -o ControlMaster=no {{ initauth }} -o IdentitiesOnly=yes {{ inituser }}@{{ inithostip|default(static_ipv4) }} 'sudo apt-get -y update'"
- name: "InitHost | Prepare remote Python"
- name: InitHost | Prepare remote Python
shell: "ssh -o ControlMaster=no {{ initauth }} -o IdentitiesOnly=yes {{ inituser }}@{{ inithostip|default(static_ipv4) }} 'sudo apt-get -y install python2.7 python-simplejson'"
- name: "Prepare 2"
- name: Prepare 2
hosts: "{{ host }}"
connection: local
gather_facts: false
become: yes
tasks:
- name: "InitHost | Include new host into /etc/hosts"
- name: InitHost | Include new host into /etc/hosts
lineinfile:
dest=/etc/hosts
regexp="^{{ inithostip|default(static_ipv4) }} "
......@@ -49,7 +49,7 @@
- import_playbook: "firstuser.yml"
- name: "Security setup"
- name: Security setup
hosts: "{{ host }}"
gather_facts: true
become: yes
......
......@@ -7,21 +7,21 @@
- import_playbook: "validate.yml"
- name: "List Details"
- name: List Details
hosts: all:!offline
tasks:
- name: "Default IP (Static IP)"
- name: Default IP (Static IP)
debug: msg='{{ static_ipv4 }}'
- name: "Validate DNS Records"
- name: Validate DNS Records
hosts: proxyserver:!offline
tasks:
- include_tasks: 'includes/dig.yml'
- include_tasks: includes/dig.yml
with_items: '{{ proxy_certificates|default([]) }}'
when: ip is not defined or item.ip == ip
- include_tasks: 'includes/dig.yml'
- include_tasks: includes/dig.yml
with_subelements:
- '{{ proxy_certificates }}'
- 'aliases'
- {{ proxy_certificates }}
- aliases
- skip_missing: 1
when: ip is not defined or item.0.ip == ip
......@@ -7,17 +7,17 @@
- import_playbook: "validate.yml"
- name: "Move floating IP to non-active host"
- name: Move floating IP to non-active host
hosts: proxyserver
gather_facts: false
become: yes
tasks:
- name: "Move IP"
- name: Move IP
jiffybox:
action: 'moveip'
action: moveip
group: '{{ groups.proxyserver }}'
- name: "Wait for a grace time"
- name: Wait for a grace time
pause:
seconds: 30
......@@ -7,34 +7,34 @@
- import_playbook: "validate.yml"
- name: "Prepare Source"
- name: Prepare Source
hosts: "{{ sourcehost }}"
become: no
tasks:
- name: "Dump Database"
- name: Dump Database
mysql_db:
login_host=127.0.0.1
name={{ dbname }}
state=dump
target=/tmp/{{ dbname }}.sql
- name: "Prepare Target"
- name: Prepare Target
hosts: "{{ targethost }}"
become: no
tasks:
- name: "Copy Database to Target"
- name: Copy Database to Target
shell: scp {{ sourcehost }}:/tmp/{{ dbname }}.sql /tmp/{{ dbname }}.sql
- name: "Remove Database"
- name: Remove Database
mysql_db:
login_host=127.0.0.1
name={{ dbname }}
state=absent
- name: "Create Database"
- name: Create Database
mysql_db:
login_host=127.0.0.1
name={{ dbname }}
state=present
- name: "Import Database"
- name: Import Database
mysql_db:
login_host=127.0.0.1
name={{ dbname }}
......
......@@ -16,31 +16,33 @@
- import_playbook: "validate.yml"
- name: "Skip 1 Replication Item"
- name: Skip 1 Replication Item
hosts: "dbserver_mysql-slave"
become: no
tags: 'skipbyone'
tags:
- skipbyone
tasks:
- name: "Stop slave"
- name: Stop slave
mysql_replication:
mode='stopslave'
- name: "Set Skip Counter"
- name: Set Skip Counter
mysql_variables:
variable='sql_slave_skip_counter'
value='1'
- name: "Start slave"
- name: Start slave
mysql_replication:
mode='startslave'
- name: "MySQL Replication"
- name: MySQL Replication
hosts: "dbserver_mysql-slave"
become: no
tags: 'changemaster'
tags:
- changemaster
tasks:
- name: "Stop Replication"
- name: Stop Replication
mysql_replication:
mode='stopslave'
- name: "Change Master"
- name: Change Master
mysql_replication:
mode='changemaster'
login_host='127.0.0.1'
......@@ -52,6 +54,6 @@
master_password='repl'
master_log_file='{{ binlog }}'
master_log_pos='{{ binpos }}'
- name: "Start Replication"
- name: Start Replication
mysql_replication:
mode='startslave'
......@@ -7,7 +7,7 @@
- import_playbook: "validate.yml"
- name: "Reboot set of redundant proxies"
- name: Reboot set of redundant proxies
hosts: proxyserver
gather_facts: false
become: yes
......@@ -15,13 +15,13 @@
- block:
- name: "Reboot hosts"
shell: 'sleep 3; reboot now'
- name: Reboot hosts
shell: sleep 3; reboot now
async: 1
poll: 0
ignore_errors: true
- name: "Wait for hosts to go down"
- name: Wait for hosts to go down
become: false
local_action: wait_for
host='{{ static_ipv4 }}'
......@@ -29,7 +29,7 @@
timeout=240
state='stopped'
- name: "Wait for hosts to come back"
- name: Wait for hosts to come back
become: false
local_action: wait_for
host='{{ static_ipv4 }}'
......@@ -38,11 +38,11 @@
timeout=600
state='present'
- name: "Start extra services"
- name: Start extra services
service:
name: '{{ item }}'
state: 'started'
state: started
with_items: '{{ reboot_services|default([]) }}'
ignore_errors: True
when: 'proxy_active is defined and not proxy_active'
when: proxy_active is defined and not proxy_active
......@@ -6,13 +6,13 @@
- import_playbook: "validate.yml"
- name: "Prepare cloud"
- name: Prepare cloud
hosts: "{{ host }}"
connection: local
gather_facts: false
become: no
vars_prompt:
- name: "are_you_sure"
- name: are_you_sure
prompt: "Really?"
roles:
- { role: cloud, mode: removehost }
......@@ -7,7 +7,7 @@
- import_playbook: "validate.yml"
- name: "Execute Role {{ role }}"
- name: Execute Role {{ role }}
hosts: "{{ hostslimit|default('all') }}:!norootserver"
become: yes
roles:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment