72 lines
2.3 KiB
YAML
72 lines
2.3 KiB
YAML
---
|
|
- name: Stage 1 - Terraform Infrastructure
|
|
hosts: localhost
|
|
connection: local
|
|
gather_facts: false
|
|
become: false
|
|
vars:
|
|
tf_dir: "{{ playbook_dir }}/../terraform"
|
|
tasks:
|
|
- name: Create terraform mirror config
|
|
copy:
|
|
dest: "/tmp/.terraformrc"
|
|
content: |
|
|
provider_installation {
|
|
network_mirror { url = "https://terraform-mirror.yandexcloud.net/" }
|
|
direct { exclude = ["registry.terraform.io/*/*"] }
|
|
}
|
|
|
|
- name: Cleanup old terraform files
|
|
shell: "rm -rf .terraform .terraform.lock.hcl"
|
|
args:
|
|
chdir: "{{ tf_dir }}"
|
|
|
|
- name: Terraform Init and Apply
|
|
shell: |
|
|
terraform init -reconfigure -no-color && \
|
|
terraform apply -auto-approve -no-color -lock=false
|
|
args:
|
|
chdir: "{{ tf_dir }}"
|
|
register: tf_result
|
|
ignore_errors: true
|
|
environment:
|
|
TF_CLI_CONFIG_FILE: "/tmp/.terraformrc"
|
|
TF_HTTP_ADDRESS: "{{ lookup('env', 'TF_HTTP_ADDRESS') }}"
|
|
TF_HTTP_USERNAME: "{{ lookup('env', 'TF_HTTP_USERNAME') }}"
|
|
TF_HTTP_PASSWORD: "{{ lookup('env', 'TF_HTTP_PASSWORD') }}"
|
|
TF_VAR_proxmox_api_token_id: "{{ lookup('env', 'TF_VAR_proxmox_api_token_id') }}"
|
|
TF_VAR_proxmox_api_token_secret: "{{ lookup('env', 'TF_VAR_proxmox_api_token_secret') }}"
|
|
TF_VAR_proxmox_api_url: "{{ lookup('env', 'TF_VAR_proxmox_api_url') }}"
|
|
|
|
- name: Add Master to memory
|
|
add_host:
|
|
name: "k8s-master"
|
|
groups: ["masters_group", "k8s_nodes"]
|
|
ansible_host: "10.33.33.201"
|
|
ansible_user: "ubuntu"
|
|
ansible_ssh_extra_args: "-o StrictHostKeyChecking=no"
|
|
|
|
- name: Add Workers to memory
|
|
add_host:
|
|
name: "{{ item.name }}"
|
|
groups: ["workers_group", "k8s_nodes"]
|
|
ansible_host: "{{ item.ip }}"
|
|
ansible_user: "ubuntu"
|
|
ansible_ssh_extra_args: "-o StrictHostKeyChecking=no"
|
|
loop:
|
|
- { name: 'k8s-worker-1', ip: '10.33.33.202' }
|
|
- { name: 'k8s-worker-2', ip: '10.33.33.203' }
|
|
|
|
- name: Stage 2 - Wait for SSH
|
|
hosts: k8s_nodes
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Wait for connection
|
|
wait_for_connection:
|
|
timeout: 300
|
|
|
|
- name: Stage 3 - Install K8s
|
|
import_playbook: k8s_setup.yml
|
|
|
|
- name: Stage 4 - Final Config
|
|
import_playbook: k8s_post_install.yml |