--- - name: Step 1 - Terraform Provisioning hosts: localhost connection: local gather_facts: false become: false vars: tf_dir: "{{ playbook_dir }}/../terraform" tasks: - name: Nuclear Cleanup (Full) shell: "rm -rf .terraform .terraform.lock.hcl terraform.tfstate*" args: chdir: "{{ tf_dir }}" - name: Terraform Init and Apply shell: | terraform init -reconfigure -upgrade -no-color && \ terraform apply -auto-approve -no-color -lock=false args: chdir: "{{ tf_dir }}" register: tf_out environment: # Убираем TF_CLI_CONFIG_FILE, чтобы идти напрямую в registry.terraform.io 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: Show Terraform Log debug: var: tf_out.stdout_lines - name: Dynamically add hosts add_host: name: "{{ item.name }}" groups: - k8s_new_nodes - "{{ 'masters' if 'master' in item.name else 'workers' }}" ansible_host: "{{ item.ip }}" ansible_user: ubuntu ansible_ssh_extra_args: "-o StrictHostKeyChecking=no" loop: - { name: 'k8s-master', ip: '10.33.33.201' } - { name: 'k8s-worker-1', ip: '10.33.33.202' } - { name: 'k8s-worker-2', ip: '10.33.33.203' } - name: Step 2 - Wait for SSH hosts: k8s_new_nodes gather_facts: false tasks: - name: Wait for SSH to be ready wait_for_connection: delay: 10 timeout: 300 - name: Step 3 - K8s Setup import_playbook: k8s_setup.yml