Refactor setup_mysql into setup_controller

This commit is contained in:
Laurent Indermuehle 2023-01-04 17:29:06 +01:00
commit 7049a280cb
No known key found for this signature in database
GPG key ID: 93FA944C9F34DD09
15 changed files with 16 additions and 56 deletions

View file

@ -0,0 +1,26 @@
---
- name: "{{ role_name }} | install | Required package for testing"
ansible.builtin.apt:
name:
- mysql-client
- iproute2
state: present
update_cache: true
environment:
DEBIAN_FRONTEND: noninteractive
- name: "{{ role_name }} | install | install python packages"
ansible.builtin.pip:
name: "{{ python_packages }}"
register: connector
- name: "{{ role_name }} | install | Ensure fake root folder"
ansible.builtin.file:
path: "{{ playbook_dir }}/root"
state: directory
- name: "{{ role_name }} | install | Ensure fake root default file exists"
ansible.builtin.file:
path: "{{ playbook_dir }}/root/.my.cnf"
state: touch

View file

@ -0,0 +1,13 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
- name: Prepare the controller python and MySQL connector
ansible.builtin.import_tasks:
file: install.yml
- name: Set variables
ansible.builtin.import_tasks:
file: setvars.yml

View file

@ -0,0 +1,37 @@
---
- name: "{{ role_name }} | setvars | Extract Podman/Docker Network Gateway"
ansible.builtin.shell:
cmd: ip route|grep default|awk '{print $3}'
register: ip_route_output
- name: "{{ role_name }} | setvars | Set Fact"
ansible.builtin.set_fact:
connector_name: "{{ connector.name.0 }}"
gateway_addr: "{{ ip_route_output.stdout }}"
db_engine: "{{ db_engine_version | split(':') | first }}"
db_version: "{{ db_engine_version | split(':') | last }}"
- name: "{{ role_name }} | setvars | Set Fact using above facts"
ansible.builtin.set_fact:
connector_ver: "{{ connector_name.split('=')[2].strip() }}"
mysql_command: >-
mysql
-h{{ gateway_addr }}
-P{{ mysql_primary_port }}
-u{{ mysql_user }}
-p{{ mysql_password }}
--protocol=tcp
mysql_command_wo_port: >-
mysql
-h{{ gateway_addr }}
-u{{ mysql_user }}
-p{{ mysql_password }}
--protocol=tcp
- name: "{{ role_name }} | setvars | Debug connector info"
ansible.builtin.debug:
msg: >
Connector name: {{ connector_name }},
Connector version: {{ connector_ver }}
db_engine: {{ db_engine }}