diff --git a/ansible/deploy_all.yml b/ansible/deploy_all.yml index 42c63b3..5bc88a3 100644 --- a/ansible/deploy_all.yml +++ b/ansible/deploy_all.yml @@ -6,10 +6,6 @@ become: false tasks: - - name: Test DNS resolution - shell: host terraform-mirror.yandexcloud.net || ping -c 1 8.8.8.8 - ignore_errors: true # Просто для информации в логах - - name: Create terraform mirror config copy: dest: "/tmp/.terraformrc" @@ -23,18 +19,26 @@ } } - - name: Clean old terraform - file: - path: "{{ playbook_dir }}/../terraform/.terraform" - state: absent - - - name: Terraform Init and Apply - shell: | - terraform init -reconfigure -upgrade -no-color && \ - terraform apply -auto-approve -no-color -lock=false + - name: Nuclear Cleanup + shell: "rm -rf .terraform .terraform.lock.hcl" args: chdir: "{{ playbook_dir }}/../terraform" - register: tf_output + + - 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 -lock=false + args: + chdir: "{{ playbook_dir }}/../terraform" + register: tf_result environment: TF_CLI_CONFIG_FILE: "/tmp/.terraformrc" TF_HTTP_ADDRESS: "{{ lookup('env', 'TF_HTTP_ADDRESS') }}" @@ -44,41 +48,29 @@ 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 Output + - name: Show Apply Output debug: - var: tf_output.stdout_lines + var: tf_result.stdout_lines - - name: Dynamically add hosts +- name: Step 2 - Dynamic Inventory & Setup + hosts: localhost + connection: local + tasks: + - name: Add hosts add_host: name: "{{ item }}" groups: k8s_new_nodes ansible_host: "{{ item }}" ansible_user: ubuntu - loop: - - 10.33.33.201 - - 10.33.33.202 - - 10.33.33.203 + loop: [10.33.33.201, 10.33.33.202, 10.33.33.203] -- name: Step 2 - Install Kubernetes +- name: Step 3 - K8s Setup hosts: k8s_new_nodes gather_facts: false tasks: - - name: Wait for SSH to be ready + - name: Wait for SSH wait_for: host: "{{ inventory_hostname }}" port: 22 - state: started timeout: 300 - delegate_to: localhost - become: false - - - name: Now gather facts - setup: - become: true - - - name: Install base packages - apt: - name: [curl, apt-transport-https, qemu-guest-agent] - state: present - update_cache: yes - become: true \ No newline at end of file + delegate_to: localhost \ No newline at end of file