Files
IaC/ansible/deploy_all.yml

74 lines
2.3 KiB
YAML

---
- name: Step 1 - Terraform Provisioning
hosts: localhost
connection: local
gather_facts: false
become: false
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: Clean old terraform
file:
path: "{{ playbook_dir }}/../terraform/.terraform"
state: absent
- name: Terraform Init
shell: terraform init -reconfigure -no-color
args:
chdir: "{{ playbook_dir }}/../terraform"
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
args:
chdir: "{{ playbook_dir }}/../terraform"
environment:
TF_CLI_CONFIG_FILE: "/tmp/.terraformrc"
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: Dynamically add hosts to inventory
add_host:
name: "{{ item }}"
groups: k8s_new_nodes
ansible_host: "{{ item }}"
ansible_user: ubuntu # Или тот пользователь, которого ты создал в Cloud-Init
loop:
- 10.33.33.201
- 10.33.33.202
- 10.33.33.203
- name: Step 2 - Install Kubernetes
hosts: k8s_new_nodes # <--- Теперь используем динамическую группу
gather_facts: true
become: true
tasks:
- name: Wait for SSH
wait_for_connection:
timeout: 300
- name: Test Connection
ping:
- name: Install base packages
apt:
name: [curl, apt-transport-https, qemu-guest-agent]
state: present
update_cache: yes