Deploy terraform from ansible
This commit is contained in:
parent
f9eb145876
commit
ed6f9239ec
2
ansible/ansible.cfg
Normal file
2
ansible/ansible.cfg
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[defaults]
|
||||||
|
host_key_checking=False
|
1
ansible/group_vars/web
Normal file
1
ansible/group_vars/web
Normal file
@ -0,0 +1 @@
|
|||||||
|
ansible_ssh_user: root
|
@ -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
|
- name: Setup LEMP stack
|
||||||
hosts: all
|
hosts: web
|
||||||
vars_files:
|
vars_files:
|
||||||
- vault.yaml
|
- vault.yaml
|
||||||
vars:
|
vars:
|
||||||
@ -18,9 +46,9 @@
|
|||||||
dir_owner: wordpress
|
dir_owner: wordpress
|
||||||
dir_group: www-data
|
dir_group: www-data
|
||||||
cluster:
|
cluster:
|
||||||
- 192.168.56.2
|
- 10.0.0.3
|
||||||
- 192.168.56.3
|
- 10.0.0.4
|
||||||
- 192.168.56.4
|
- 10.0.0.5
|
||||||
mysql:
|
mysql:
|
||||||
replication_user: replica_user
|
replication_user: replica_user
|
||||||
replication_master: web1
|
replication_master: web1
|
||||||
@ -30,20 +58,6 @@
|
|||||||
pre_tasks:
|
pre_tasks:
|
||||||
- debug: var=ansible_all_ipv4_addresses
|
- debug: var=ansible_all_ipv4_addresses
|
||||||
# we need gluster on all servers to configure peering
|
# 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:
|
roles:
|
||||||
- nginx
|
- nginx
|
||||||
- mysql
|
- mysql
|
||||||
|
@ -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
|
- name: Create brick dir
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ gluster.brick_dir }}"
|
path: "{{ gluster.brick_dir }}"
|
||||||
@ -25,7 +40,7 @@
|
|||||||
- name: Mount volume
|
- name: Mount volume
|
||||||
mount:
|
mount:
|
||||||
name: "{{ gluster.mount_dir }}"
|
name: "{{ gluster.mount_dir }}"
|
||||||
src: "{{ ansible_all_ipv4_addresses[1] }}:/{{ gluster.vol_name }}"
|
src: "{{ ansible_all_ipv4_addresses[0] }}:/{{ gluster.vol_name }}"
|
||||||
fstype: glusterfs
|
fstype: glusterfs
|
||||||
opts: "defaults,_netdev"
|
opts: "defaults,_netdev"
|
||||||
state: mounted
|
state: mounted
|
||||||
|
20
playbook.yaml
Normal file
20
playbook.yaml
Normal 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
|
Loading…
x
Reference in New Issue
Block a user