From ed6f9239ecfcb78baed5e8845778a147c64e4d14 Mon Sep 17 00:00:00 2001 From: Johannes Rothe Date: Thu, 14 Sep 2023 21:57:26 +0200 Subject: [PATCH] Deploy terraform from ansible --- ansible/ansible.cfg | 2 + ansible/group_vars/web | 1 + ansible/playbook.yaml | 50 ++++++++++++++++--------- ansible/roles/glusterfs/tasks/main.yaml | 17 ++++++++- playbook.yaml | 20 ++++++++++ 5 files changed, 71 insertions(+), 19 deletions(-) create mode 100644 ansible/ansible.cfg create mode 100644 ansible/group_vars/web create mode 100644 playbook.yaml diff --git a/ansible/ansible.cfg b/ansible/ansible.cfg new file mode 100644 index 0000000..f288284 --- /dev/null +++ b/ansible/ansible.cfg @@ -0,0 +1,2 @@ +[defaults] +host_key_checking=False diff --git a/ansible/group_vars/web b/ansible/group_vars/web new file mode 100644 index 0000000..36e2f30 --- /dev/null +++ b/ansible/group_vars/web @@ -0,0 +1 @@ +ansible_ssh_user: root diff --git a/ansible/playbook.yaml b/ansible/playbook.yaml index 15e4770..98d7b9a 100644 --- a/ansible/playbook.yaml +++ b/ansible/playbook.yaml @@ -1,6 +1,34 @@ --- +- name: Deploy terraform + hosts: localhost + gather_facts: false + tasks: + - name: Deploy terraform + community.general.terraform: + project_path: ../terraform/ + state: present + complex_vars: true + variables: + location: "nbg1" + network_zone: "eu-central" + server_count: 3 + subnetwork_ip_range: "10.0.0.0/24" + lb_internal_ip: "10.0.0.100" + lb_external_ip: "167.235.105.161" + lb_service_id: 1399502 + ssh_keys: + - "rothe.pub" + - "alt.pub" + register: tf_out + + - add_host: + name: "{{ item.key }}" + ansible_host: "{{ item.value }}" + group: web + loop: "{{ tf_out.outputs.server_ips.value | dict2items }}" + - name: Setup LEMP stack - hosts: all + hosts: web vars_files: - vault.yaml vars: @@ -18,9 +46,9 @@ dir_owner: wordpress dir_group: www-data cluster: - - 192.168.56.2 - - 192.168.56.3 - - 192.168.56.4 + - 10.0.0.3 + - 10.0.0.4 + - 10.0.0.5 mysql: replication_user: replica_user replication_master: web1 @@ -30,20 +58,6 @@ pre_tasks: - debug: var=ansible_all_ipv4_addresses # we need gluster on all servers to configure peering - - name: Install gluster - ansible.builtin.apt: - update_cache: true - cache_valid_time: 3600 - name: - - glusterfs-server - become: true - - - name: start service - ansible.builtin.service: - name: glusterd - state: started - enabled: true - become: true roles: - nginx - mysql diff --git a/ansible/roles/glusterfs/tasks/main.yaml b/ansible/roles/glusterfs/tasks/main.yaml index 551ecc5..47aaba6 100644 --- a/ansible/roles/glusterfs/tasks/main.yaml +++ b/ansible/roles/glusterfs/tasks/main.yaml @@ -1,4 +1,19 @@ --- +- name: Install gluster + ansible.builtin.apt: + update_cache: true + cache_valid_time: 3600 + name: + - glusterfs-server + become: true + +- name: start service + ansible.builtin.service: + name: glusterd + state: started + enabled: true + become: true + - name: Create brick dir ansible.builtin.file: path: "{{ gluster.brick_dir }}" @@ -25,7 +40,7 @@ - name: Mount volume mount: name: "{{ gluster.mount_dir }}" - src: "{{ ansible_all_ipv4_addresses[1] }}:/{{ gluster.vol_name }}" + src: "{{ ansible_all_ipv4_addresses[0] }}:/{{ gluster.vol_name }}" fstype: glusterfs opts: "defaults,_netdev" state: mounted diff --git a/playbook.yaml b/playbook.yaml new file mode 100644 index 0000000..115d071 --- /dev/null +++ b/playbook.yaml @@ -0,0 +1,20 @@ +--- +- name: Deploy terraform + hosts: localhost + tasks: + - name: Deploy terraform + community.general.terraform: + project_path: terraform/ + state: present + variables: + location: "nbg1" + network_zone: "eu-central" + server_count: 1 + subnetwork_ip_range: "10.0.0.0/24" + lb_internal_ip: "10.0.0.100" + lb_external_ip: "167.235.105.161" + lb_service_id: 1399502 + ssh_key: "rothe.pub" + register: tf_out + + - debug: var=tf_out