Merge branch 'refactor' into 'master'

Refactor

See merge request aurore/ansible!30
This commit is contained in:
Alexandre IOOSS 2019-03-26 08:36:21 +01:00
commit 00ccc4c377
21 changed files with 130 additions and 83 deletions

View file

@ -12,11 +12,20 @@
# Send email when there is something new # Send email when there is something new
- name: Configure apt-listchanges - name: Configure apt-listchanges
lineinfile: ini_file:
dest: /etc/apt/listchanges.conf path: /etc/apt/listchanges.conf
regexp: "^{{ item.key }}=" no_extra_spaces: true
line: "{{ item.value }}" section: apt
with_dict: option: "{{ item.option }}"
confirm: 'confirm=true' value: "{{ item.value }}"
email_address: "email_address={{ monitoring_mail }}" state: present
which: 'which=both' loop:
- option: confirm
value: "true"
- option: email_address
value: "{{ monitoring_mail }}"
- option: which
value: both
...

View file

@ -23,8 +23,8 @@
# Pimp my server # Pimp my server
- name: Customize motd - name: Customize motd
copy: copy:
src: 'update-motd.d/00-logo' src: update-motd.d/00-logo
dest: '/etc/update-motd.d/00-logo' dest: /etc/update-motd.d/00-logo
mode: 0755 mode: 0755
# Configure APT mirrors on Debian Stretch # Configure APT mirrors on Debian Stretch
@ -33,8 +33,8 @@
- ansible_distribution == 'Debian' - ansible_distribution == 'Debian'
- ansible_distribution_release == 'stretch' - ansible_distribution_release == 'stretch'
template: template:
src: 'apt/sources.list.j2' src: apt/sources.list.j2
dest: '/etc/apt/sources.list' dest: /etc/apt/sources.list
mode: 0644 mode: 0644
# Patriotisme # Patriotisme
@ -50,8 +50,7 @@
question: locales/default_environment_locale question: locales/default_environment_locale
value: fr_FR.UTF-8 value: fr_FR.UTF-8
vtype: select vtype: select
notify: notify: Reconfigure locales
- Reconfigure locales
# Molly-Guard : prevent accidental shutdowns # Molly-Guard : prevent accidental shutdowns
- include_tasks: molly-guard.yml - include_tasks: molly-guard.yml
@ -62,8 +61,8 @@
# User skeleton # User skeleton
- name: Configure user skeleton - name: Configure user skeleton
copy: copy:
src: skel/{{ item.key }} src: skel/dot_{{ item.key }}
dest: /etc/skel/{{ item.value }} dest: /etc/skel/.{{ item.value }}
with_dict: loop:
dot_zshrc: .zshrc - zshrc
dot_zshrc.local: .zshrc.local - zshrc.local

View file

@ -42,21 +42,45 @@
- name: Install fail2ban - name: Install fail2ban
apt: apt:
name: fail2ban name: fail2ban
state: present
register: apt_result register: apt_result
retries: 3 retries: 3
until: apt_result is succeeded until: apt_result is succeeded
- name: Configure fail2ban - name: Configure fail2ban
template: ini_file:
src: fail2ban/jail.d/local.conf.j2 path: /etc/fail2ban/jail.d/local.conf
dest: /etc/fail2ban/jail.d/local.conf section: "{{ item.section }}"
mode: 0644 option: "{{ item.option }}"
value: "{{ item.value }}"
state: present
notify: Restart fail2ban service notify: Restart fail2ban service
loop:
- section: DEFAULT
option: ignoreip
value: 10.128.0.254 # Whitelist bastion
- section: sshd
option: enabled
value: "true"
- section: sshd
option: bantime
value: 600
- section: sshd
option: findtime
value: 600
- section: sshd
option: maxretry
value: 5
# See altered packages and configurations with `debsums -ca` # See altered packages and configurations with `debsums -ca`
- name: Install debsums - name: Install debsums
apt: apt:
name: debsums name: debsums
state: present
register: apt_result register: apt_result
retries: 3 retries: 3
until: apt_result is succeeded until: apt_result is succeeded

View file

@ -1,12 +0,0 @@
# {{ ansible_managed }}
# Ban a host for 10mn
# if it has failed 5 times during the last 10mn
[sshd]
enabled = true
bantime = 600
findtime = 600
maxretry = 5
# Whitelist bastion
ignoreip = 10.128.0.254

View file

@ -2,8 +2,9 @@
# For HTTPS apt # For HTTPS apt
- name: Install HTTPS apt - name: Install HTTPS apt
apt: apt:
name: apt-transport-https
update_cache: true update_cache: true
name: apt-transport-https
state: present
register: apt_result register: apt_result
retries: 3 retries: 3
until: apt_result is succeeded until: apt_result is succeeded
@ -12,19 +13,22 @@
apt_key: apt_key:
url: https://dl.yarnpkg.com/debian/pubkey.gpg url: https://dl.yarnpkg.com/debian/pubkey.gpg
id: 1646B01B86E50310 id: 1646B01B86E50310
state: present
register: apt_key_result register: apt_key_result
retries: 3 retries: 3
until: apt_key_result is succeeded until: apt_key_result is succeeded
- name: Configure Yarn repository - name: Configure Yarn repository
apt_repository: apt_repository:
repo: "deb https://dl.yarnpkg.com/debian/ stable main" repo: deb https://dl.yarnpkg.com/debian/ stable main
state: present
# Install CodiMD dependencies # Install CodiMD dependencies
- name: Install required packages - name: Install required packages
apt: apt:
name: yarn
update_cache: true update_cache: true
name: yarn
state: present
register: apt_result register: apt_result
retries: 3 retries: 3
until: apt_result is succeeded until: apt_result is succeeded

View file

@ -47,8 +47,8 @@
# Service file # Service file
- name: Install CodiMD systemd unit - name: Install CodiMD systemd unit
template: template:
src: 'systemd/codimd.service.j2' src: systemd/codimd.service.j2
dest: '/etc/systemd/system/codimd.service' dest: /etc/systemd/system/codimd.service
owner: root owner: root
group: root group: root
mode: 0644 mode: 0644

View file

@ -22,8 +22,9 @@
# Install # Install
- name: Install DokuWiki - name: Install DokuWiki
apt: apt:
name: dokuwiki
update_cache: true update_cache: true
name: dokuwiki
state: present
register: apt_result register: apt_result
retries: 3 retries: 3
until: apt_result is succeeded until: apt_result is succeeded

View file

@ -2,8 +2,9 @@
# Install EtherPad dependencies # Install EtherPad dependencies
- name: Install required packages - name: Install required packages
apt: apt:
name: curl
update_cache: true update_cache: true
name: curl
state: present
register: apt_result register: apt_result
retries: 3 retries: 3
until: apt_result is succeeded until: apt_result is succeeded

View file

@ -1,6 +1,6 @@
--- ---
- name: Reconfigure libnss-ldapd package - name: Reconfigure libnss-ldapd package
command: 'dpkg-reconfigure libnss-ldapd -f noninteractive' command: dpkg-reconfigure libnss-ldapd -f noninteractive
- name: Restart nslcd service - name: Restart nslcd service
service: service:

View file

@ -2,11 +2,12 @@
# Install LDAP client packages # Install LDAP client packages
- name: Install LDAP client packages - name: Install LDAP client packages
apt: apt:
update_cache: true
name: name:
- nslcd - nslcd
- libnss-ldapd - libnss-ldapd
- libpam-ldapd - libpam-ldapd
update_cache: true state: present
register: apt_result register: apt_result
retries: 3 retries: 3
until: apt_result is succeeded until: apt_result is succeeded
@ -31,11 +32,11 @@
- name: Configure NSS to use LDAP - name: Configure NSS to use LDAP
lineinfile: lineinfile:
dest: /etc/nsswitch.conf dest: /etc/nsswitch.conf
regexp: "^{{ item.key }}:" regexp: "^{{ item }}:"
line: "{{ item.value }}" line: "{{ item }}: files ldap"
with_dict: loop:
passwd: 'passwd: files ldap' - passwd
group: 'group: files ldap' - group
shadow: 'shadow: files ldap' - shadow
sudoers: 'sudoers: files ldap' - sudoers
notify: Restart nslcd service notify: Restart nslcd service

View file

@ -3,8 +3,9 @@
- name: Filter SSH on groups - name: Filter SSH on groups
lineinfile: lineinfile:
dest: /etc/ssh/sshd_config dest: /etc/ssh/sshd_config
regexp: '^AllowGroups' regexp: ^AllowGroups
line: "AllowGroups root sudoldap aurore ssh" line: AllowGroups root sudoldap aurore ssh
state: present
# To gain root access with ldap rights # To gain root access with ldap rights
- name: Install SUDO package - name: Install SUDO package
@ -19,13 +20,17 @@
- name: Configure sudoers sudo group - name: Configure sudoers sudo group
lineinfile: lineinfile:
dest: /etc/sudoers dest: /etc/sudoers
regexp: "^%{{ sudo_group }}" regexp: ^%{{ sudo_group }}
line: "%{{ sudo_group }} ALL=(ALL:ALL) ALL" line: "%{{ sudo_group }} ALL=(ALL:ALL) ALL"
state: present
validate: /usr/sbin/visudo -cf %s
# Set sudo location group # Set sudo location group
- name: Configure sudoers sudo location group - name: Configure sudoers sudo location group
lineinfile: lineinfile:
dest: /etc/sudoers dest: /etc/sudoers
regexp: "^%{{ sudo_group_location }}" regexp: ^%{{ sudo_group_location }}
line: "%{{ sudo_group_location }} ALL=(ALL:ALL) ALL" line: "%{{ sudo_group_location }} ALL=(ALL:ALL) ALL"
state: present
validate: /usr/sbin/visudo -cf %s
when: sudo_group_location is defined when: sudo_group_location is defined

View file

@ -3,9 +3,9 @@
- name: Copy passwd and chsh scripts - name: Copy passwd and chsh scripts
template: template:
src: "{{ item }}.j2" src: "{{ item }}.j2"
dest: "/usr/local/bin/{{ item }}" dest: /usr/local/bin/{{ item }}
mode: 0755 mode: 0755
with_items: loop:
- chsh - chsh
- passwd - passwd

View file

@ -28,22 +28,26 @@
# Cry a bit # Cry a bit
- name: Remove old data - name: Remove old data
file: path={{ item }} state=absent file:
with_items: path: "{{ item }}"
state: absent
loop:
- /etc/ldap/slapd.d - /etc/ldap/slapd.d
- /var/lib/ldap - /var/lib/ldap
# Cry a lot # Cry a lot
- name: Recreate structure - name: Recreate structure
file: path={{ item }} state=directory file:
with_items: path: "{{ item }}"
state: directory
loop:
- /etc/ldap/slapd.d - /etc/ldap/slapd.d
- /var/lib/ldap - /var/lib/ldap
# Install schema as root # Install schema as root
# We can't do a `become_user` here # We can't do a `become_user` here
- name: Install LDAP schema - name: Install LDAP schema
command: 'slapadd -n 0 -l /etc/ldap/schema.ldiff -F /etc/ldap/slapd.d' command: slapadd -n 0 -l /etc/ldap/schema.ldiff -F /etc/ldap/slapd.d
# then fix permissions # then fix permissions
- name: Fix permissions - name: Fix permissions
@ -52,10 +56,12 @@
owner: openldap owner: openldap
group: openldap group: openldap
recurse: true recurse: true
with_items: loop:
- '/var/lib/ldap' - /var/lib/ldap
- '/etc/ldap/slapd.d' - /etc/ldap/slapd.d
# Save the day # Save the day
- name: Start LDAP server - name: Start LDAP server
service: name=slapd state=started service:
name: slapd
state: started

View file

@ -44,8 +44,8 @@
# Service file # Service file
- name: Install matrix-appservice-discord systemd unit - name: Install matrix-appservice-discord systemd unit
template: template:
src: 'systemd/matrix-appservice-discord.service.j2' src: systemd/matrix-appservice-discord.service.j2
dest: '/etc/systemd/system/matrix-appservice-discord.service' dest: /etc/systemd/system/matrix-appservice-discord.service
owner: root owner: root
group: root group: root
mode: 0644 mode: 0644

View file

@ -33,8 +33,8 @@
# Service file # Service file
- name: Install matrix-appservice-irc systemd unit - name: Install matrix-appservice-irc systemd unit
template: template:
src: 'systemd/matrix-appservice-irc.service.j2' src: systemd/matrix-appservice-irc.service.j2
dest: '/etc/systemd/system/matrix-appservice-irc.service' dest: /etc/systemd/system/matrix-appservice-irc.service
owner: root owner: root
group: root group: root
mode: 0644 mode: 0644

View file

@ -33,8 +33,8 @@
# Service file # Service file
- name: Install matrix-appservice-webhooks systemd unit - name: Install matrix-appservice-webhooks systemd unit
template: template:
src: 'systemd/matrix-appservice-webhooks.service.j2' src: systemd/matrix-appservice-webhooks.service.j2
dest: '/etc/systemd/system/matrix-appservice-webhooks.service' dest: /etc/systemd/system/matrix-appservice-webhooks.service
owner: root owner: root
group: root group: root
mode: 0644 mode: 0644

View file

@ -2,6 +2,7 @@
- name: Install mxisd - name: Install mxisd
apt: apt:
deb: "{{ mxisd_deb }}" deb: "{{ mxisd_deb }}"
state: present
register: apt_result register: apt_result
retries: 3 retries: 3
until: apt_result is succeeded until: apt_result is succeeded

View file

@ -2,8 +2,9 @@
# Install HTTPS support for APT # Install HTTPS support for APT
- name: Install apt-transport-https - name: Install apt-transport-https
apt: apt:
name: apt-transport-https
update_cache: true update_cache: true
name: apt-transport-https
state: present
register: apt_result register: apt_result
retries: 3 retries: 3
until: apt_result is succeeded until: apt_result is succeeded
@ -11,21 +12,24 @@
# Add the repository into source list # Add the repository into source list
- name: Configure riot repository - name: Configure riot repository
apt_repository: apt_repository:
repo: "deb https://riot.im/packages/debian/ {{ ansible_distribution_release }} main" repo: deb https://riot.im/packages/debian/ {{ ansible_distribution_release }} main
state: present
# Add the key # Add the key
- name: Configure the apt key - name: Configure the apt key
apt_key: apt_key:
url: https://riot.im/packages/debian/repo-key.asc url: https://riot.im/packages/debian/repo-key.asc
id: E019645248E8F4A1 id: E019645248E8F4A1
state: present
register: apt_key_result register: apt_key_result
retries: 3 retries: 3
until: apt_key_result is succeeded until: apt_key_result is succeeded
- name: Install riot-web - name: Install riot-web
apt: apt:
name: riot-web
update_cache: true update_cache: true
name: riot-web
state: present
register: apt_result register: apt_result
retries: 3 retries: 3
until: apt_result is succeeded until: apt_result is succeeded
@ -43,6 +47,7 @@
- name: Install nginx - name: Install nginx
apt: apt:
name: nginx name: nginx
state: present
register: apt_result register: apt_result
retries: 3 retries: 3
until: apt_result is succeeded until: apt_result is succeeded

View file

@ -1,8 +1,9 @@
--- ---
- name: Install matrix-synapse - name: Install matrix-synapse
apt: apt:
name: matrix-synapse
update_cache: true update_cache: true
name: matrix-synapse
state: present
default_release: stretch-backports default_release: stretch-backports
register: apt_result register: apt_result
retries: 3 retries: 3

View file

@ -4,8 +4,9 @@
# but also reduces the surface of attack # but also reduces the surface of attack
- name: Install NGINX server - name: Install NGINX server
apt: apt:
name: nginx-light
update_cache: true update_cache: true
name: nginx-light
state: present
register: apt_result register: apt_result
retries: 3 retries: 3
until: apt_result is succeeded until: apt_result is succeeded
@ -13,8 +14,8 @@
# Install proxy snippets # Install proxy snippets
- name: Configure NGINX proxy snippets - name: Configure NGINX proxy snippets
template: template:
src: "nginx/snippets/{{ item }}.j2" src: nginx/snippets/{{ item }}.j2
dest: "/etc/nginx/snippets/{{ item }}" dest: /etc/nginx/snippets/{{ item }}
mode: 0644 mode: 0644
loop: loop:
- proxy-common.conf - proxy-common.conf
@ -25,7 +26,7 @@
- name: Configure NGINX sites - name: Configure NGINX sites
template: template:
src: nginx/nginx-sites-available.j2 src: nginx/nginx-sites-available.j2
dest: "/etc/nginx/sites-available/{{ item.name }}" dest: /etc/nginx/sites-available/{{ item.name }}
mode: 0644 mode: 0644
loop: "{{ reversed_proxy_subdomains }}" loop: "{{ reversed_proxy_subdomains }}"
notify: Reload NGINX service notify: Reload NGINX service
@ -40,8 +41,8 @@
# Activate sites # Activate sites
- name: Activate sites - name: Activate sites
file: file:
src: "/etc/nginx/sites-available/{{ item.name }}" src: /etc/nginx/sites-available/{{ item.name }}
dest: "/etc/nginx/sites-enabled/{{ item.name }}" dest: /etc/nginx/sites-enabled/{{ item.name }}
state: link state: link
loop: "{{ reversed_proxy_subdomains }}" loop: "{{ reversed_proxy_subdomains }}"
notify: Reload NGINX service notify: Reload NGINX service

View file

@ -10,11 +10,12 @@
- name: Install required packages - name: Install required packages
apt: apt:
update_cache: true
name: name:
- nodejs - nodejs
- npm - npm
- build-essential # To build npm packages - build-essential # To build npm packages
update_cache: true state: present
register: apt_result register: apt_result
retries: 3 retries: 3
until: apt_result is succeeded until: apt_result is succeeded