· 5 years ago · Nov 08, 2019, 07:40 AM
1# Ansible, но можешь через баш делать
2
3---
4- name: "Step 1: Provision AIO"
5 hosts: localhost
6 gather_facts: false
7 connection: local
8 tasks:
9 - name: Collect info
10 terraform:
11 project_path: "{{ tf_project_path }}"
12 state: "{{ vm_state }}"
13 force_init: true
14 variables:
15 host_name: "{{ host_name }}"
16 variables_file: "{{ tf_variables_file }}"
17 backend_config:
18 key: "development/{{ host_name }}.tfstate"
19 access_key: "{{ minio_terraform_access_key }}"
20 secret_key: "{{ minio_terraform_secret_key }}"
21 register: create_vm
22 tags:
23 - destroy
24
25 - name: Print terraform output
26 debug:
27 var: create_vm
28 tags:
29 - destroy
30
31 - name: Add host to app group
32 add_host:
33 hostname: "{{ create_vm.outputs.server_name.value }}"
34 ansible_ssh_host: "{{ create_vm.outputs.server_ip.value }}"
35 groups:
36 - app
37 delegate_to: localhost
38 when: vm_state == "present"
39
40- name: "Step 3: Deploy application"
41 hosts: app
42 become: true
43 roles:
44 - { role: robocloud, when: vm_state == "present" }