Обновить ansible/deploy_all.yml
This commit is contained in:
@@ -1,47 +1,34 @@
|
|||||||
---
|
---
|
||||||
- name: Step 1 - Terraform Provisioning
|
- name: Stage 1 - Terraform Infrastructure
|
||||||
hosts: localhost
|
hosts: localhost
|
||||||
connection: local
|
connection: local
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
become: false
|
become: false
|
||||||
vars:
|
vars:
|
||||||
tf_dir: "{{ playbook_dir }}/../terraform"
|
tf_dir: "{{ playbook_dir }}/../terraform"
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Create terraform mirror config
|
- name: Create terraform mirror config
|
||||||
copy:
|
copy:
|
||||||
dest: "/tmp/.terraformrc"
|
dest: "/tmp/.terraformrc"
|
||||||
content: |
|
content: |
|
||||||
provider_installation {
|
provider_installation {
|
||||||
network_mirror {
|
network_mirror { url = "https://terraform-mirror.yandexcloud.net/" }
|
||||||
url = "https://terraform-mirror.yandexcloud.net/"
|
direct { exclude = ["registry.terraform.io/*/*"] }
|
||||||
}
|
|
||||||
direct {
|
|
||||||
exclude = ["registry.terraform.io/*/*"]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- name: Total Cleanup
|
- name: Cleanup old terraform files
|
||||||
shell: "rm -rf .terraform .terraform.lock.hcl"
|
shell: "rm -rf .terraform .terraform.lock.hcl"
|
||||||
args:
|
args:
|
||||||
chdir: "{{ tf_dir }}"
|
chdir: "{{ tf_dir }}"
|
||||||
|
|
||||||
- name: Terraform Init
|
- name: Terraform Init and Apply
|
||||||
shell: terraform init -reconfigure -no-color
|
shell: |
|
||||||
args:
|
terraform init -reconfigure -no-color && \
|
||||||
chdir: "{{ tf_dir }}"
|
terraform apply -auto-approve -no-color -lock=false
|
||||||
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') }}"
|
|
||||||
|
|
||||||
- name: Terraform Apply
|
|
||||||
shell: terraform apply -auto-approve -no-color -lock=false
|
|
||||||
args:
|
args:
|
||||||
chdir: "{{ tf_dir }}"
|
chdir: "{{ tf_dir }}"
|
||||||
register: tf_result
|
register: tf_result
|
||||||
ignore_errors: true # <--- ДОБАВЬТЕ ЭТО, чтобы Ansible не останавливался, после создания вм на проксмокс
|
ignore_errors: true
|
||||||
environment:
|
environment:
|
||||||
TF_CLI_CONFIG_FILE: "/tmp/.terraformrc"
|
TF_CLI_CONFIG_FILE: "/tmp/.terraformrc"
|
||||||
TF_HTTP_ADDRESS: "{{ lookup('env', 'TF_HTTP_ADDRESS') }}"
|
TF_HTTP_ADDRESS: "{{ lookup('env', 'TF_HTTP_ADDRESS') }}"
|
||||||
@@ -51,38 +38,35 @@
|
|||||||
TF_VAR_proxmox_api_token_secret: "{{ lookup('env', 'TF_VAR_proxmox_api_token_secret') }}"
|
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') }}"
|
TF_VAR_proxmox_api_url: "{{ lookup('env', 'TF_VAR_proxmox_api_url') }}"
|
||||||
|
|
||||||
- name: Show Apply Output
|
- name: Add Master to memory
|
||||||
debug:
|
add_host:
|
||||||
var: tf_result.stdout_lines
|
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: Dynamically add hosts to inventory
|
- name: Add Workers to memory
|
||||||
add_host:
|
add_host:
|
||||||
name: "{{ item.name }}"
|
name: "{{ item.name }}"
|
||||||
groups:
|
groups: ["workers_group", "k8s_nodes"]
|
||||||
- k8s_new_nodes
|
|
||||||
- "{{ 'masters' if 'master' in item.name else 'workers' }}"
|
|
||||||
ansible_host: "{{ item.ip }}"
|
ansible_host: "{{ item.ip }}"
|
||||||
ansible_user: ubuntu
|
ansible_user: "ubuntu"
|
||||||
ansible_ssh_extra_args: "-o StrictHostKeyChecking=no"
|
ansible_ssh_extra_args: "-o StrictHostKeyChecking=no"
|
||||||
loop:
|
loop:
|
||||||
- { name: 'k8s-master', ip: '10.33.33.201' }
|
|
||||||
- { name: 'k8s-worker-1', ip: '10.33.33.202' }
|
- { name: 'k8s-worker-1', ip: '10.33.33.202' }
|
||||||
- { name: 'k8s-worker-2', ip: '10.33.33.203' }
|
- { name: 'k8s-worker-2', ip: '10.33.33.203' }
|
||||||
|
|
||||||
- name: Step 2 - Wait for SSH
|
- name: Stage 2 - Wait for SSH
|
||||||
hosts: k8s_new_nodes
|
hosts: k8s_nodes
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
tasks:
|
tasks:
|
||||||
- name: Wait for SSH to be ready
|
- name: Wait for connection
|
||||||
wait_for_connection:
|
wait_for_connection:
|
||||||
delay: 10
|
|
||||||
timeout: 300
|
timeout: 300
|
||||||
|
|
||||||
- name: Step 3 - K8s Setup
|
- name: Stage 3 - Install K8s
|
||||||
import_playbook: k8s_setup.yml
|
import_playbook: k8s_setup.yml
|
||||||
|
|
||||||
- name: Step 4 - change password
|
- name: Stage 4 - Final Config
|
||||||
import_playbook: change_password.yml
|
|
||||||
|
|
||||||
- name: Stage 5 - Post-install (Network & Storage)
|
|
||||||
import_playbook: k8s_post_install.yml
|
import_playbook: k8s_post_install.yml
|
||||||
Reference in New Issue
Block a user