Deploy terraform from ansible

This commit is contained in:
Johannes Rothe 2023-09-14 21:57:26 +02:00
parent f9eb145876
commit ed6f9239ec
Signed by: onjen
GPG Key ID: 73F092605AF3286C
5 changed files with 71 additions and 19 deletions

2
ansible/ansible.cfg Normal file
View File

@ -0,0 +1,2 @@
[defaults]
host_key_checking=False

1
ansible/group_vars/web Normal file
View File

@ -0,0 +1 @@
ansible_ssh_user: root

View File

@ -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

View File

@ -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

20
playbook.yaml Normal file
View File

@ -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