Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion klanten/testklant/test/roles/common/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
- name: restart ntp
service:
name: ntp
state: restarted
state: restarted
27 changes: 13 additions & 14 deletions klanten/testklant/test/roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
---
- name: Add ufw rule for ssh
ufw:
community.general.ufw:
rule: allow
port: '22'
port: "22"

- name: Enable ufw
when: firewall
ufw:
community.general.ufw:
state: enabled

- name: Disable ufw
when: not firewall
ufw:
community.general.ufw:
state: disabled

- name: Install ntp
when: custom_ntp
apt:
tags: ntp
ansible.builtin.apt:
name: ntp
state: present
update_cache: yes
tags: ntp
update_cache: true

- name: Determine if timesyncd is enabled
register: timesyncdstatus
command: timedatectl status
changed_when: false
ansible.builtin.command: timedatectl status

- name: Disable timesyncd
command: timedatectl set-ntp off
when: "'systemd-timesyncd.service active: yes' in timesyncdstatus.stdout and
custom_ntp"
when: "'systemd-timesyncd.service active: yes' in timesyncdstatus.stdout and custom_ntp"
ansible.builtin.command: timedatectl set-ntp off

- name: Configure ntp file
when: custom_ntp
template:
src: ntp.conf.j2
dest: /etc/ntp.conf
tags: ntp
notify: restart ntp
ansible.builtin.template:
src: ntp.conf.j2
dest: /etc/ntp.conf
16 changes: 8 additions & 8 deletions klanten/testklant/test/roles/databaseservers/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
mysql_non_root_user_name: 'admin'
mysql_non_root_user_name: admin
mysql_root_hosts:
- 'localhost'
- '127.0.0.1'
- '::1'
- localhost
- 127.0.0.1
- ::1
mysql_non_root_user: true
mysql_non_root_user_hosts:
- 'localhost'
- '127.0.0.1'
- '::1'
- localhost
- 127.0.0.1
- ::1
mysql_enable: true
mysql_use_dump: false
mysql_remove_testdb: true
mysql_remove_anon_users: true
mysql_bind_addr: 127.0.0.1
mysql_check_ssl: true
mysql_non_root_user_privs: '*.*:USAGE'
mysql_non_root_user_privs: "*.*:USAGE"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: restart mysql
service:
name: 'mysql'
name: mysql
state: restarted
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
- name: Install MySQL Python libraries
apt:
name: 'python3-mysqldb'
ansible.builtin.apt:
name: python3-mysqldb
state: present
update_cache: yes
update_cache: true

- name: Install MySQL
apt:
ansible.builtin.apt:
pkg:
- 'mysql-common'
- 'mysql-server'
- mysql-common
- mysql-server
state: present
update_cache: yes
update_cache: true

- name: Add UFW rule for MySQL
ufw:
community.general.ufw:
rule: allow
port: '{{ mysql_port | mandatory }}'
port: "{{ mysql_port | mandatory }}"
3 changes: 2 additions & 1 deletion klanten/testklant/test/roles/databaseservers/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
- import_tasks: install_mysql.yml
- ansible.builtin.import_tasks: install_mysql.yml

- import_tasks: setup_mysql.yml
95 changes: 46 additions & 49 deletions klanten/testklant/test/roles/databaseservers/tasks/setup_mysql.yml
Original file line number Diff line number Diff line change
@@ -1,97 +1,94 @@
---
- name: Copy MySQL configuration
template:
notify: restart mysql
ansible.builtin.template:
src: my.cnf.j2
dest: '/etc/mysql/my.cnf'
dest: /etc/mysql/my.cnf
owner: root
group: root
mode: '0644'
notify: restart mysql
mode: "0644"

- name: Start MySQL
service:
name: 'mysql'
ansible.builtin.service:
name: mysql
state: started

- name: Enable MySQL
when: mysql_enable
service:
name: 'mysql'
enabled: 'yes'
ansible.builtin.service:
name: mysql
enabled: true

- name: Copy .my.cnf
template:
src: '.my.cnf.j2'
dest: '/root/.my.cnf'
ansible.builtin.template:
src: .my.cnf.j2
dest: /root/.my.cnf
owner: root
group: root
mode: '0600'
mode: "0600"

- name: Set root password
mysql_user:
no_log: true
community.mysql.mysql_user:
name: root
host: '{{ item }}'
password: '{{ mysql_root_password | mandatory }}'
host: "{{ item }}"
password: "{{ mysql_root_password | mandatory }}"
state: present
with_items:
- '{{ mysql_root_hosts }}'
no_log: true
loop:
- "{{ mysql_root_hosts }}"

- name: Copy database dump file
when: mysql_use_dump
copy:
src: '{{ mysql_db_file | mandatory }}'
ansible.builtin.copy:
src: "{{ mysql_db_file | mandatory }}"
dest: /tmp

- name: Restore database
when: mysql_use_dump
mysql_db:
name: '{{ mysql_db_name | mandatory }}'
community.mysql.mysql_db:
name: "{{ mysql_db_name | mandatory }}"
state: import
target: '/tmp/{{ mysql_db_file | mandatory }}'
target: /tmp/{{ mysql_db_file | mandatory }}

- name: Create non-root user
when: mysql_non_root_user
mysql_user:
name: '{{ mysql_non_root_user_name | mandatory }}'
host: '{{ item }}'
password: '{{ mysql_non_root_user_password }}'
priv: '{{ mysql_non_root_user_privs }}'
state: present
with_items:
- '{{ mysql_non_root_user_hosts }}'
no_log: true
community.mysql.mysql_user:
name: "{{ mysql_non_root_user_name | mandatory }}"
host: "{{ item }}"
password: "{{ mysql_non_root_user_password }}"
priv: "{{ mysql_non_root_user_privs }}"
state: present
loop:
- "{{ mysql_non_root_user_hosts }}"

- name: Remove test database
when: mysql_remove_testdb
mysql_db:
community.mysql.mysql_db:
name: test
state: absent

- name: Remove anonymous users
when: mysql_remove_anon_users
mysql_user:
name: ''
state: absent
host_all: yes
no_log: true
community.mysql.mysql_user:
name: ""
state: absent
host_all: true

- name: Bind to interface(s)
lineinfile:
path: /etc/mysql/mysql.conf.d/mysqld.cnf
regexp: '^bind-address'
line: 'bind-address = {{ mysql_bind_addr | mandatory }}'
notify: restart mysql
ansible.builtin.lineinfile:
path: /etc/mysql/mysql.conf.d/mysqld.cnf
regexp: ^bind-address
line: bind-address = {{ mysql_bind_addr | mandatory }}

- name: Check if SSL is enabled
when: mysql_check_ssl
mysql_info:
login_user: root
filter: settings
register: ssl
failed_when: >
('have_openssl:\": \"\"' in ssl.settings) or
('have_ssl:\": \"\"' in ssl.settings) or
('ssl_ca:\": \"\"' in ssl.settings) or
('ssl_cert:\": \"\"' in ssl.settings) or
('ssl_key:\": \"\"' in ssl.settings)
('have_openssl:\": \"\"' in ssl.settings) or ('have_ssl:\": \"\"' in ssl.settings) or ('ssl_ca:\": \"\"' in ssl.settings) or ('ssl_cert:\": \"\"' in ssl.settings)
or ('ssl_key:\": \"\"' in ssl.settings)
community.mysql.mysql_info:
login_user: root
filter: settings
16 changes: 8 additions & 8 deletions klanten/testklant/test/roles/databaseservers/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
mysql_use_dump: true
mysql_db_file: 'test.sql'
mysql_db_file: test.sql
mysql_non_root_user_hosts:
- '10.0.1.11'
- '10.0.1.12'
- 'localhost'
- '127.0.0.1'
- '::1'
mysql_bind_addr: 0.0.0.0
mysql_non_root_user_privs: 'vm2.test:SELECT'
- 10.0.1.11
- 10.0.1.12
- localhost
- 127.0.0.1
- ::1
mysql_bind_addr: "0.0.0.0"
mysql_non_root_user_privs: vm2.test:SELECT
4 changes: 2 additions & 2 deletions klanten/testklant/test/roles/loadbalancers/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ haproxy_timeout_connect: 5000
haproxy_timeout_client: 50000
haproxy_timeout_server: 50000
haproxy_enable_stats: false
haproxy_frontends: ''
haproxy_backends: ''
haproxy_frontends: ""
haproxy_backends: ""
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
---
- name: Check if default configuration exists
stat:
path: /etc/haproxy/haproxy.cfg*
register: haproxydefaultconfig
ansible.builtin.stat:
path: /etc/haproxy/haproxy.cfg*

- name: Rename default configuration
command: mv /etc/haproxy/haproxy.cfg{,.original}
when: haproxydefaultconfig.stat.exists
ansible.builtin.command: mv /etc/haproxy/haproxy.cfg{,.original}

- name: Copy new configuration
template:
notify: restart haproxy
ansible.builtin.template:
src: haproxy.cfg.j2
dest: /etc/haproxy/haproxy.cfg
notify: restart haproxy

- name: Verify configuration
command: haproxy -f /etc/haproxy/haproxy.cfg -c
register: haproxycfgchk
failed_when: "'error' in haproxycfgchk.stdout"
changed_when: false
ansible.builtin.command: haproxy -f /etc/haproxy/haproxy.cfg -c
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
---
- name: Install HAProxy
apt:
name: 'haproxy'
ansible.builtin.apt:
name: haproxy
state: present
update_cache: yes
update_cache: true

- name: Check if HAProxy is working
command: haproxy -v
register: haproxystatus
failed_when: "'version' not in haproxystatus.stdout"
changed_when: false
ansible.builtin.command: haproxy -v

- name: Add ufw rule for HAProxy
when: haproxy_ports_list is defined
ufw:
community.general.ufw:
rule: allow
port: '{{ item }}'
with_items:
- '{{ haproxy_ports_list }}'
port: "{{ item }}"
loop:
- "{{ haproxy_ports_list }}"
5 changes: 3 additions & 2 deletions klanten/testklant/test/roles/loadbalancers/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
- import_tasks: install_haproxy.yml
- import_tasks: configure_haproxy.yml
- ansible.builtin.import_tasks: install_haproxy.yml

- import_tasks: configure_haproxy.yml
8 changes: 4 additions & 4 deletions klanten/testklant/test/roles/loadbalancers/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ haproxy_stats_pass: !vault |
3566
haproxy_frontends:
- name: site
bind: '*'
bind: "*"
port: 80
options: forwardfor
default_backend: webservers
Expand All @@ -27,7 +27,7 @@ haproxy_backends:
- name: testklant-test-web02
port: 80
options: check
extra_options: 'option httpchk'
extra_options: option httpchk
haproxy_ports_list:
- '80'
- '8080'
- "80"
- "8080"
4 changes: 2 additions & 2 deletions klanten/testklant/test/roles/webservers/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
apache_directory_index: 'index.html index.cgi index.php index.pl index.xhtml index.htm'
apache_directory_index: index.html index.cgi index.php index.pl index.xhtml index.htm
install_php: false
apache_use_repo: https://github.com/muan/hello-world.git
apache_use_template: false
apache_virtual_hosts: ''
apache_virtual_hosts: ""
Loading