From 381ae8bcf3723724aa88caa712efe426485b3aa0 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Mon, 4 Sep 2023 19:59:57 +0100 Subject: [PATCH 01/38] stuff --- .github/workflows/infra.yaml | 21 ++++-- README.md | 2 +- infra/joplin/0000_proxmox_playbook.yaml | 85 +++++++++++++++++++++++++ infra/joplin/0001_docker_playbook.yaml | 25 ++++++++ inventory/proxmox.yaml | 9 ++- 5 files changed, 134 insertions(+), 8 deletions(-) create mode 100644 infra/joplin/0000_proxmox_playbook.yaml create mode 100644 infra/joplin/0001_docker_playbook.yaml diff --git a/.github/workflows/infra.yaml b/.github/workflows/infra.yaml index 6b1c861..ad3ec34 100644 --- a/.github/workflows/infra.yaml +++ b/.github/workflows/infra.yaml @@ -4,14 +4,15 @@ on: branches: - main paths: - - infra/**-playbook.yaml + - infra/**playbook.yaml - .github/workflows/infra.yaml push: branches: - main env: - DEPLOY: ${{ github.ref == 'refs/heads/main' && ((startsWith(github.event.head_commit.message, '[deploy-all]') && 'all') || ('some')) || 'none' }} + # DEPLOY: ${{ github.ref == 'refs/heads/main' && ((startsWith(github.event.head_commit.message, '[deploy-all]') && 'all') || ('some')) || 'none' }} + DEPLOY: all jobs: ansible-playbooks: @@ -35,8 +36,8 @@ jobs: - name: Check playbooks run: | - for file in $(find . -wholename "*/infra/*-playbook.yaml" -type f); do - ansible-playbook --inventory ./inventory --check "$file" + for file in $(find . -wholename "*/infra/*playbook.yaml" -type f); do + ansible-playbook --inventory ./inventory --syntax-check "$file" done - name: Get changed playbooks @@ -44,7 +45,7 @@ jobs: if: env.DEPLOY == 'some' uses: tj-actions/changed-files@v38 with: - files: infra/**/*-playbook.yaml + files: infra/**/*playbook.yaml - name: Get playbooks id: playbooks @@ -53,12 +54,19 @@ jobs: if [[ "${{ env.DEPLOY }}" == "some" ]]; then export TO_RUN="${{ steps.files.outputs.all_changed_files }}" else - export TO_RUN="$(find . -wholename './infra/*-playbook.yaml' -type f)" + export TO_RUN="$(find . -wholename './infra/*playbook.yaml' -type f)" fi export TO_RUN="$( echo -n $TO_RUN | tr ' ' '\n' | sort | tr '\n' ' ' )" # run things in order :) echo "will run playbooks: $TO_RUN" echo "to_run=$TO_RUN" >> "$GITHUB_OUTPUT" + - name: Setup environment + if: env.DEPLOY != 'none' && steps.playbooks.outputs.to_run != '' + run: | + mkdir -p -m 700 ~/.ssh + echo "${{ secrets.SSH_PRIVATE }}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + - name: Run playbooks if: env.DEPLOY != 'none' && steps.playbooks.outputs.to_run != '' env: @@ -66,4 +74,5 @@ jobs: PROXMOX_USER: ${{ secrets.PROXMOX_USER }} PROXMOX_TOKEN_ID: ${{ secrets.PROXMOX_TOKEN_ID }} PROXMOX_TOKEN_SECRET: ${{ secrets.PROXMOX_TOKEN_SECRET }} + SSH_PUBLIC: ${{ secrets.SSH_PUBLIC }} run: ansible-playbook --inventory ./inventory ${{ steps.playbooks.outputs.to_run }} diff --git a/README.md b/README.md index 6c43ecb..0397ccc 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,4 @@ This repository contains any automations used in deploying *.koval.net services. All 'managed' infrastructure is deployed and provisioned with [Ansible](https://www.ansible.com/). However, some 'unmanaged' (manually managed) resources also exist - primarily everything required for this repository to work (I don't want to make a dependency loop). -Ansible playbooks are ran in alphanumerical order and are expected idempotent. +Ansible playbooks are ran in alphanumerical order and are expected to be idempotent. diff --git a/infra/joplin/0000_proxmox_playbook.yaml b/infra/joplin/0000_proxmox_playbook.yaml new file mode 100644 index 0000000..dc7e89d --- /dev/null +++ b/infra/joplin/0000_proxmox_playbook.yaml @@ -0,0 +1,85 @@ +- name: Provision joplin Proxmox VM + hosts: localhost + vars: + api_user: "{{ lookup('ansible.builtin.env', 'PROXMOX_USER') }}" + api_host: "{{ lookup('ansible.builtin.env', 'PROXMOX_HOST' ) }}" + api_token_id: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN_ID') }}" + api_token_secret: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN_SECRET') }}" + ssh_public: "{{ lookup('ansible.builtin.env', 'SSH_PUBLIC') }}" + vmname: joplin + node: pve + module_defaults: + community.general.proxmox_kvm: + api_user: "{{ api_user }}" + api_host: "{{ api_host }}" + api_token_id: "{{ api_token_id }}" + api_token_secret: "{{ api_token_secret }}" + name: "{{ vmname }}" + node: "{{ node }}" + community.general.proxmox_nic: + api_user: "{{ api_user }}" + api_host: "{{ api_host }}" + api_token_id: "{{ api_token_id }}" + api_token_secret: "{{ api_token_secret }}" + name: "{{ vmname }}" + community.general.proxmox_disk: + api_user: "{{ api_user }}" + api_host: "{{ api_host }}" + api_token_id: "{{ api_token_id }}" + api_token_secret: "{{ api_token_secret }}" + name: "{{ vmname }}" + tasks: + - name: Create VM + community.general.proxmox_kvm: + clone: "{{ node }}-debian-12" + storage: nvme + - name: Wait for VM to exist + community.general.proxmox_kvm: + state: current + register: vm + retries: 30 + delay: 10 + until: vm.status is defined + - name: Add HOME NIC + community.general.proxmox_nic: + interface: net0 + firewall: false + bridge: HOME + - name: Add SRV NIC + community.general.proxmox_nic: + interface: net1 + firewall: false + bridge: SRV + - name: Resize disk + community.general.proxmox_disk: + disk: scsi0 + size: 64G + state: resized + - name: Update VM + community.general.proxmox_kvm: + update: true + ciuser: debian + sshkeys: "{{ ssh_public }}" + ipconfig: + ipconfig0: ip=dhcp,ip6=auto + ipconfig1: ip=dhcp,ip6=auto + agent: enabled=1 + tags: + - debian-12 + - managed + onboot: true + cores: 2 + memory: 2048 + - name: Retart VM # doesn't start if stopped + when: + - vm.status is defined + - vm.status == "running" + community.general.proxmox_kvm: + state: restarted + timeout: 60 + - name: Start VM # start if stopped + when: + - vm.status is defined + - vm.status != "running" + community.general.proxmox_kvm: + state: started diff --git a/infra/joplin/0001_docker_playbook.yaml b/infra/joplin/0001_docker_playbook.yaml new file mode 100644 index 0000000..2328c7d --- /dev/null +++ b/infra/joplin/0001_docker_playbook.yaml @@ -0,0 +1,25 @@ +- name: Setup Docker + hosts: joplin + gather_facts: false + tasks: + - name: Debug + ansible.builtin.debug: + msg: "{{ inventory_hostname }}" + - name: Wait for connection + ansible.builtin.wait_for: + host: "{{ inventory_hostname }}" + port: 22 + timeout: 300 + - name: Wut + ansible.builtin.shell: | + ping -c 5 {{ inventory_hostname }} + args: + executable: /bin/bash + delegate_to: localhost + - name: Test some stuff + ansible.builtin.shell: | + touch ~/hmm + echo test > ~/test + echo test2 >> ~/test + args: + executable: /bin/bash diff --git a/inventory/proxmox.yaml b/inventory/proxmox.yaml index 6b4033d..00ca438 100644 --- a/inventory/proxmox.yaml +++ b/inventory/proxmox.yaml @@ -7,6 +7,13 @@ proxmox: pve.mgmt.home.local.koval.net: pve2.mgmt.home.local.koval.net: managed: - hosts: + children: + joplin: + hosts: + joplin.srv.home.local.koval.net: + vars: + ansible_user: debian + ansible_ssh_private_key_file: ~/.ssh/id_rsa + ansible_ssh_common_args: -o StrictHostKeyChecking=accept-new # TODO: Improve this unmanaged: hosts: -- 2.40.1 From 152a5a606eb74fe81cc77fb6a6dcc563a0fd6563 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Wed, 6 Sep 2023 00:35:08 +0100 Subject: [PATCH 02/38] increase verbosity --- .github/workflows/infra.yaml | 2 +- .../{0001_docker_playbook.yaml => 0001_software_playbook.yaml} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename infra/joplin/{0001_docker_playbook.yaml => 0001_software_playbook.yaml} (96%) diff --git a/.github/workflows/infra.yaml b/.github/workflows/infra.yaml index ad3ec34..1b52681 100644 --- a/.github/workflows/infra.yaml +++ b/.github/workflows/infra.yaml @@ -75,4 +75,4 @@ jobs: PROXMOX_TOKEN_ID: ${{ secrets.PROXMOX_TOKEN_ID }} PROXMOX_TOKEN_SECRET: ${{ secrets.PROXMOX_TOKEN_SECRET }} SSH_PUBLIC: ${{ secrets.SSH_PUBLIC }} - run: ansible-playbook --inventory ./inventory ${{ steps.playbooks.outputs.to_run }} + run: ansible-playbook --inventory ./inventory ${{ steps.playbooks.outputs.to_run }} -vvv diff --git a/infra/joplin/0001_docker_playbook.yaml b/infra/joplin/0001_software_playbook.yaml similarity index 96% rename from infra/joplin/0001_docker_playbook.yaml rename to infra/joplin/0001_software_playbook.yaml index 2328c7d..d3e096f 100644 --- a/infra/joplin/0001_docker_playbook.yaml +++ b/infra/joplin/0001_software_playbook.yaml @@ -1,4 +1,4 @@ -- name: Setup Docker +- name: Setup Software hosts: joplin gather_facts: false tasks: -- 2.40.1 From f189b1fca37fc023c832f35a39aaa2131b9006a2 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Wed, 6 Sep 2023 00:42:08 +0100 Subject: [PATCH 03/38] move wut --- infra/joplin/0001_software_playbook.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/infra/joplin/0001_software_playbook.yaml b/infra/joplin/0001_software_playbook.yaml index d3e096f..d878649 100644 --- a/infra/joplin/0001_software_playbook.yaml +++ b/infra/joplin/0001_software_playbook.yaml @@ -5,17 +5,17 @@ - name: Debug ansible.builtin.debug: msg: "{{ inventory_hostname }}" - - name: Wait for connection - ansible.builtin.wait_for: - host: "{{ inventory_hostname }}" - port: 22 - timeout: 300 - name: Wut ansible.builtin.shell: | ping -c 5 {{ inventory_hostname }} args: executable: /bin/bash delegate_to: localhost + - name: Wait for connection + ansible.builtin.wait_for: + host: "{{ inventory_hostname }}" + port: 22 + timeout: 300 - name: Test some stuff ansible.builtin.shell: | touch ~/hmm -- 2.40.1 From 4a995ed62e40ff08823d657a7e5ac9b642eb89c5 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Wed, 6 Sep 2023 00:47:47 +0100 Subject: [PATCH 04/38] install ping --- infra/joplin/0001_software_playbook.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/infra/joplin/0001_software_playbook.yaml b/infra/joplin/0001_software_playbook.yaml index d878649..458aaeb 100644 --- a/infra/joplin/0001_software_playbook.yaml +++ b/infra/joplin/0001_software_playbook.yaml @@ -7,6 +7,8 @@ msg: "{{ inventory_hostname }}" - name: Wut ansible.builtin.shell: | + apt update + apt install -y iputils-ping ping -c 5 {{ inventory_hostname }} args: executable: /bin/bash -- 2.40.1 From f447e9e77ea64a92eaff408d45e16ee58376197b Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Wed, 6 Sep 2023 01:07:15 +0100 Subject: [PATCH 05/38] debug infra workflow --- .github/workflows/infra.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/infra.yaml b/.github/workflows/infra.yaml index 1b52681..66186b2 100644 --- a/.github/workflows/infra.yaml +++ b/.github/workflows/infra.yaml @@ -66,6 +66,8 @@ jobs: mkdir -p -m 700 ~/.ssh echo "${{ secrets.SSH_PRIVATE }}" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa + cat ~/.ssh/id_rsa | wc -c + cat ~/.ssh/id_rsa | wc -l - name: Run playbooks if: env.DEPLOY != 'none' && steps.playbooks.outputs.to_run != '' -- 2.40.1 From 46de0b3d0f3e712ce34a55f1a5d0c101deee6714 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Wed, 6 Sep 2023 01:10:26 +0100 Subject: [PATCH 06/38] Revert "debug infra workflow" This reverts commit f447e9e77ea64a92eaff408d45e16ee58376197b. --- .github/workflows/infra.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/infra.yaml b/.github/workflows/infra.yaml index 66186b2..1b52681 100644 --- a/.github/workflows/infra.yaml +++ b/.github/workflows/infra.yaml @@ -66,8 +66,6 @@ jobs: mkdir -p -m 700 ~/.ssh echo "${{ secrets.SSH_PRIVATE }}" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa - cat ~/.ssh/id_rsa | wc -c - cat ~/.ssh/id_rsa | wc -l - name: Run playbooks if: env.DEPLOY != 'none' && steps.playbooks.outputs.to_run != '' -- 2.40.1 From 54d26948bda4f2b910f8b9cd517261863772bf9f Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Wed, 6 Sep 2023 01:11:31 +0100 Subject: [PATCH 07/38] delete wait connection to localhost --- infra/joplin/0001_software_playbook.yaml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/infra/joplin/0001_software_playbook.yaml b/infra/joplin/0001_software_playbook.yaml index 458aaeb..8bee726 100644 --- a/infra/joplin/0001_software_playbook.yaml +++ b/infra/joplin/0001_software_playbook.yaml @@ -5,19 +5,12 @@ - name: Debug ansible.builtin.debug: msg: "{{ inventory_hostname }}" - - name: Wut - ansible.builtin.shell: | - apt update - apt install -y iputils-ping - ping -c 5 {{ inventory_hostname }} - args: - executable: /bin/bash - delegate_to: localhost - name: Wait for connection ansible.builtin.wait_for: host: "{{ inventory_hostname }}" port: 22 timeout: 300 + delegate_to: localhost - name: Test some stuff ansible.builtin.shell: | touch ~/hmm -- 2.40.1 From 75820107482949411c0fffed8427ffb105ae3ca4 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Wed, 6 Sep 2023 01:35:34 +0100 Subject: [PATCH 08/38] update hostname --- infra/joplin/0000_proxmox_playbook.yaml | 6 ++++-- inventory/proxmox.yaml | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/infra/joplin/0000_proxmox_playbook.yaml b/infra/joplin/0000_proxmox_playbook.yaml index dc7e89d..14da83e 100644 --- a/infra/joplin/0000_proxmox_playbook.yaml +++ b/infra/joplin/0000_proxmox_playbook.yaml @@ -1,12 +1,14 @@ - name: Provision joplin Proxmox VM - hosts: localhost + hosts: joplin + connection: ansible.builtin.local + gather_facts: false vars: api_user: "{{ lookup('ansible.builtin.env', 'PROXMOX_USER') }}" api_host: "{{ lookup('ansible.builtin.env', 'PROXMOX_HOST' ) }}" api_token_id: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN_ID') }}" api_token_secret: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN_SECRET') }}" ssh_public: "{{ lookup('ansible.builtin.env', 'SSH_PUBLIC') }}" - vmname: joplin + vmname: "{{ inventory_hostname | regex_replace('^([^\\.]+)\\..+$', '\\1') }}" node: pve module_defaults: community.general.proxmox_kvm: diff --git a/inventory/proxmox.yaml b/inventory/proxmox.yaml index 00ca438..f888c38 100644 --- a/inventory/proxmox.yaml +++ b/inventory/proxmox.yaml @@ -10,7 +10,7 @@ proxmox: children: joplin: hosts: - joplin.srv.home.local.koval.net: + joplin2.srv.home.local.koval.net: vars: ansible_user: debian ansible_ssh_private_key_file: ~/.ssh/id_rsa -- 2.40.1 From 1c59a98ec5ae54c7d58e996791a49bde5a2b0498 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Wed, 6 Sep 2023 23:01:30 +0100 Subject: [PATCH 09/38] testing --- .github/workflows/infra.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/infra.yaml b/.github/workflows/infra.yaml index 1b52681..4e732d8 100644 --- a/.github/workflows/infra.yaml +++ b/.github/workflows/infra.yaml @@ -33,6 +33,7 @@ jobs: run: | pip3 install -r requirements.txt ansible-galaxy collection install community.general + id - name: Check playbooks run: | -- 2.40.1 From 0dccf1902a88952c3ac406572aca894dbbef39ca Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Wed, 6 Sep 2023 23:06:36 +0100 Subject: [PATCH 10/38] more testing --- infra/joplin/0000_proxmox_playbook.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/joplin/0000_proxmox_playbook.yaml b/infra/joplin/0000_proxmox_playbook.yaml index 14da83e..2ae0c9f 100644 --- a/infra/joplin/0000_proxmox_playbook.yaml +++ b/infra/joplin/0000_proxmox_playbook.yaml @@ -1,5 +1,5 @@ - name: Provision joplin Proxmox VM - hosts: joplin + hosts: localhost connection: ansible.builtin.local gather_facts: false vars: -- 2.40.1 From 52c049217683151c0f7488c40deaa9356c898918 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Wed, 6 Sep 2023 23:11:04 +0100 Subject: [PATCH 11/38] maybe we don't need more python? --- .github/workflows/infra.yaml | 9 ++++----- infra/joplin/0000_proxmox_playbook.yaml | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/infra.yaml b/.github/workflows/infra.yaml index 4e732d8..e1ac1ee 100644 --- a/.github/workflows/infra.yaml +++ b/.github/workflows/infra.yaml @@ -24,16 +24,15 @@ jobs: with: fetch-depth: ${{ env.DEPLOY == 'some' && 2 || 1 }} - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: "3.11" + # - name: Setup Python + # uses: actions/setup-python@v4 + # with: + # python-version: "3.11" - name: Install dependencies run: | pip3 install -r requirements.txt ansible-galaxy collection install community.general - id - name: Check playbooks run: | diff --git a/infra/joplin/0000_proxmox_playbook.yaml b/infra/joplin/0000_proxmox_playbook.yaml index 2ae0c9f..e142fe4 100644 --- a/infra/joplin/0000_proxmox_playbook.yaml +++ b/infra/joplin/0000_proxmox_playbook.yaml @@ -1,5 +1,5 @@ - name: Provision joplin Proxmox VM - hosts: localhost + hosts: joplin connection: ansible.builtin.local gather_facts: false vars: -- 2.40.1 From e12565fdb67986ebe9bb45c2aca442febbcf2ef1 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Wed, 6 Sep 2023 23:39:19 +0100 Subject: [PATCH 12/38] gather facts? --- .github/workflows/infra.yaml | 8 ++++---- infra/joplin/0000_proxmox_playbook.yaml | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/infra.yaml b/.github/workflows/infra.yaml index e1ac1ee..1b52681 100644 --- a/.github/workflows/infra.yaml +++ b/.github/workflows/infra.yaml @@ -24,10 +24,10 @@ jobs: with: fetch-depth: ${{ env.DEPLOY == 'some' && 2 || 1 }} - # - name: Setup Python - # uses: actions/setup-python@v4 - # with: - # python-version: "3.11" + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: "3.11" - name: Install dependencies run: | diff --git a/infra/joplin/0000_proxmox_playbook.yaml b/infra/joplin/0000_proxmox_playbook.yaml index e142fe4..ddbbf3a 100644 --- a/infra/joplin/0000_proxmox_playbook.yaml +++ b/infra/joplin/0000_proxmox_playbook.yaml @@ -1,7 +1,6 @@ - name: Provision joplin Proxmox VM - hosts: joplin + hosts: joplin connection: ansible.builtin.local - gather_facts: false vars: api_user: "{{ lookup('ansible.builtin.env', 'PROXMOX_USER') }}" api_host: "{{ lookup('ansible.builtin.env', 'PROXMOX_HOST' ) }}" -- 2.40.1 From 19247a24673de8f99de065bbd753ca98c9876d40 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Wed, 6 Sep 2023 23:44:02 +0100 Subject: [PATCH 13/38] get python from apt --- .github/workflows/infra.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/infra.yaml b/.github/workflows/infra.yaml index 1b52681..74189b9 100644 --- a/.github/workflows/infra.yaml +++ b/.github/workflows/infra.yaml @@ -24,13 +24,9 @@ jobs: with: fetch-depth: ${{ env.DEPLOY == 'some' && 2 || 1 }} - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: "3.11" - - name: Install dependencies run: | + apt install -y python3-pip pip3 install -r requirements.txt ansible-galaxy collection install community.general -- 2.40.1 From 04881f9dfab99fe201b8dacdc71e3c382507d15f Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Wed, 6 Sep 2023 23:51:08 +0100 Subject: [PATCH 14/38] update apt --- .github/workflows/infra.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/infra.yaml b/.github/workflows/infra.yaml index 74189b9..9823a97 100644 --- a/.github/workflows/infra.yaml +++ b/.github/workflows/infra.yaml @@ -26,6 +26,7 @@ jobs: - name: Install dependencies run: | + apt update apt install -y python3-pip pip3 install -r requirements.txt ansible-galaxy collection install community.general -- 2.40.1 From 18e2ba2f75eac95a67deafa1f931da90d3074498 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Thu, 7 Sep 2023 00:00:36 +0100 Subject: [PATCH 15/38] hmmmm --- infra/joplin/0001_software_playbook.yaml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/infra/joplin/0001_software_playbook.yaml b/infra/joplin/0001_software_playbook.yaml index 8bee726..8a893d0 100644 --- a/infra/joplin/0001_software_playbook.yaml +++ b/infra/joplin/0001_software_playbook.yaml @@ -2,19 +2,21 @@ hosts: joplin gather_facts: false tasks: - - name: Debug - ansible.builtin.debug: - msg: "{{ inventory_hostname }}" - name: Wait for connection ansible.builtin.wait_for: host: "{{ inventory_hostname }}" port: 22 timeout: 300 delegate_to: localhost + - name: Wait for 10s + ansible.builtin.wait_for: + timeout: 10 + - name: Ping + ansible.builtin.shell: | + ping -c 5 {{ inventory_hostname }} + delegate_to: localhost - name: Test some stuff ansible.builtin.shell: | touch ~/hmm echo test > ~/test echo test2 >> ~/test - args: - executable: /bin/bash -- 2.40.1 From 9c2ce06cb0e0269f39fb701dae753610c13640b3 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Thu, 7 Sep 2023 00:05:11 +0100 Subject: [PATCH 16/38] delegate more --- infra/joplin/0001_software_playbook.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/infra/joplin/0001_software_playbook.yaml b/infra/joplin/0001_software_playbook.yaml index 8a893d0..d2c01c1 100644 --- a/infra/joplin/0001_software_playbook.yaml +++ b/infra/joplin/0001_software_playbook.yaml @@ -11,6 +11,7 @@ - name: Wait for 10s ansible.builtin.wait_for: timeout: 10 + delegate_to: localhost - name: Ping ansible.builtin.shell: | ping -c 5 {{ inventory_hostname }} -- 2.40.1 From b39d99b7817fc2cd2021f5eaaf6bef8c4269afaf Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Thu, 7 Sep 2023 00:11:49 +0100 Subject: [PATCH 17/38] install ping --- infra/joplin/0001_software_playbook.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/infra/joplin/0001_software_playbook.yaml b/infra/joplin/0001_software_playbook.yaml index d2c01c1..33a8078 100644 --- a/infra/joplin/0001_software_playbook.yaml +++ b/infra/joplin/0001_software_playbook.yaml @@ -14,6 +14,7 @@ delegate_to: localhost - name: Ping ansible.builtin.shell: | + apt update && apt install -y iputils-ping ping -c 5 {{ inventory_hostname }} delegate_to: localhost - name: Test some stuff -- 2.40.1 From 0edaee542f3ccba013ca952a081c26bd9c82ba66 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Fri, 8 Sep 2023 23:27:31 +0100 Subject: [PATCH 18/38] Better? + qemu-guest-agent --- infra/joplin/0001_software_playbook.yaml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/infra/joplin/0001_software_playbook.yaml b/infra/joplin/0001_software_playbook.yaml index 33a8078..eb6dd44 100644 --- a/infra/joplin/0001_software_playbook.yaml +++ b/infra/joplin/0001_software_playbook.yaml @@ -8,17 +8,14 @@ port: 22 timeout: 300 delegate_to: localhost - - name: Wait for 10s - ansible.builtin.wait_for: - timeout: 10 - delegate_to: localhost - - name: Ping - ansible.builtin.shell: | - apt update && apt install -y iputils-ping - ping -c 5 {{ inventory_hostname }} - delegate_to: localhost - name: Test some stuff ansible.builtin.shell: | + apt update + apt install -y qemu-guest-agent touch ~/hmm echo test > ~/test echo test2 >> ~/test + retries: 10 + delay: 6 + until: result is not failed + -- 2.40.1 From 599931fd9ab1c9973ba2f071ab93793071c7690b Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Fri, 8 Sep 2023 23:32:03 +0100 Subject: [PATCH 19/38] sudo --- infra/joplin/0001_software_playbook.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infra/joplin/0001_software_playbook.yaml b/infra/joplin/0001_software_playbook.yaml index eb6dd44..cacda29 100644 --- a/infra/joplin/0001_software_playbook.yaml +++ b/infra/joplin/0001_software_playbook.yaml @@ -10,8 +10,8 @@ delegate_to: localhost - name: Test some stuff ansible.builtin.shell: | - apt update - apt install -y qemu-guest-agent + sudo apt update + sudo apt install -y qemu-guest-agent touch ~/hmm echo test > ~/test echo test2 >> ~/test -- 2.40.1 From 2d8ad8f4535e069c5e7d9e5a77a03fbbf1703895 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Fri, 8 Sep 2023 23:34:08 +0100 Subject: [PATCH 20/38] now less verbosity --- .github/workflows/infra.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/infra.yaml b/.github/workflows/infra.yaml index 9823a97..53c21f2 100644 --- a/.github/workflows/infra.yaml +++ b/.github/workflows/infra.yaml @@ -72,4 +72,4 @@ jobs: PROXMOX_TOKEN_ID: ${{ secrets.PROXMOX_TOKEN_ID }} PROXMOX_TOKEN_SECRET: ${{ secrets.PROXMOX_TOKEN_SECRET }} SSH_PUBLIC: ${{ secrets.SSH_PUBLIC }} - run: ansible-playbook --inventory ./inventory ${{ steps.playbooks.outputs.to_run }} -vvv + run: ansible-playbook --inventory ./inventory ${{ steps.playbooks.outputs.to_run }} -- 2.40.1 From 8406db7eafb7d7ed7e630a0b71b72bf91b88e209 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Fri, 8 Sep 2023 23:38:17 +0100 Subject: [PATCH 21/38] change until: --- infra/joplin/0001_software_playbook.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infra/joplin/0001_software_playbook.yaml b/infra/joplin/0001_software_playbook.yaml index cacda29..84710de 100644 --- a/infra/joplin/0001_software_playbook.yaml +++ b/infra/joplin/0001_software_playbook.yaml @@ -15,7 +15,7 @@ touch ~/hmm echo test > ~/test echo test2 >> ~/test + register: stuff retries: 10 delay: 6 - until: result is not failed - + until: stuff.rc == 0 -- 2.40.1 From f891d1e6a872c61fc521080fc6c20d6eb72b425e Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Fri, 8 Sep 2023 23:58:04 +0100 Subject: [PATCH 22/38] improve stuff --- infra/joplin/0000_proxmox_playbook.yaml | 2 +- infra/joplin/0001_software_playbook.yaml | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/infra/joplin/0000_proxmox_playbook.yaml b/infra/joplin/0000_proxmox_playbook.yaml index ddbbf3a..3b7151f 100644 --- a/infra/joplin/0000_proxmox_playbook.yaml +++ b/infra/joplin/0000_proxmox_playbook.yaml @@ -63,7 +63,7 @@ sshkeys: "{{ ssh_public }}" ipconfig: ipconfig0: ip=dhcp,ip6=auto - ipconfig1: ip=dhcp,ip6=auto + ipconfig1: ip=dhcp agent: enabled=1 tags: - debian-12 diff --git a/infra/joplin/0001_software_playbook.yaml b/infra/joplin/0001_software_playbook.yaml index 84710de..654448d 100644 --- a/infra/joplin/0001_software_playbook.yaml +++ b/infra/joplin/0001_software_playbook.yaml @@ -10,12 +10,21 @@ delegate_to: localhost - name: Test some stuff ansible.builtin.shell: | - sudo apt update - sudo apt install -y qemu-guest-agent touch ~/hmm echo test > ~/test echo test2 >> ~/test + mkdir ~/dir + touch ~/dir/testing register: stuff retries: 10 delay: 6 until: stuff.rc == 0 + - name: Install some stuff + ansible.builtin.apt: + update_cache: true + name: qemu-guest-agent + - name: Enable some stuff + ansible.builtin.systemd: + name: qemu-guest-agent + state: started + enabled: true -- 2.40.1 From 20bee24b199c51c0e6bbf12e6d1553da31997c17 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Sat, 9 Sep 2023 00:00:30 +0100 Subject: [PATCH 23/38] facts are bad --- infra/joplin/0000_proxmox_playbook.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/infra/joplin/0000_proxmox_playbook.yaml b/infra/joplin/0000_proxmox_playbook.yaml index 3b7151f..eb1c5ce 100644 --- a/infra/joplin/0000_proxmox_playbook.yaml +++ b/infra/joplin/0000_proxmox_playbook.yaml @@ -1,6 +1,7 @@ - name: Provision joplin Proxmox VM hosts: joplin connection: ansible.builtin.local + gather_facts: false vars: api_user: "{{ lookup('ansible.builtin.env', 'PROXMOX_USER') }}" api_host: "{{ lookup('ansible.builtin.env', 'PROXMOX_HOST' ) }}" -- 2.40.1 From fce7d91115118993f948efd7adb192fc8ad6a9ca Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Sun, 10 Sep 2023 23:12:18 +0100 Subject: [PATCH 24/38] debug create --- infra/joplin/0000_proxmox_playbook.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/infra/joplin/0000_proxmox_playbook.yaml b/infra/joplin/0000_proxmox_playbook.yaml index eb1c5ce..c8a1fc4 100644 --- a/infra/joplin/0000_proxmox_playbook.yaml +++ b/infra/joplin/0000_proxmox_playbook.yaml @@ -35,6 +35,10 @@ community.general.proxmox_kvm: clone: "{{ node }}-debian-12" storage: nvme + register: create + - name: Debug + ansible.builtin.debug: + var: create - name: Wait for VM to exist community.general.proxmox_kvm: state: current -- 2.40.1 From ab54c18b1b16f517827537d185d246f9d447faa5 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Sun, 10 Sep 2023 23:33:43 +0100 Subject: [PATCH 25/38] handlers --- infra/joplin/0000_proxmox_playbook.yaml | 33 ++++++++++++++++--------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/infra/joplin/0000_proxmox_playbook.yaml b/infra/joplin/0000_proxmox_playbook.yaml index c8a1fc4..80ee4a8 100644 --- a/infra/joplin/0000_proxmox_playbook.yaml +++ b/infra/joplin/0000_proxmox_playbook.yaml @@ -36,16 +36,11 @@ clone: "{{ node }}-debian-12" storage: nvme register: create + notify: + - Initial boot - name: Debug ansible.builtin.debug: var: create - - name: Wait for VM to exist - community.general.proxmox_kvm: - state: current - register: vm - retries: 30 - delay: 10 - until: vm.status is defined - name: Add HOME NIC community.general.proxmox_nic: interface: net0 @@ -78,14 +73,30 @@ memory: 2048 - name: Retart VM # doesn't start if stopped when: - - vm.status is defined - - vm.status == "running" + - create.status is defined + - create.status == "running" community.general.proxmox_kvm: state: restarted timeout: 60 - name: Start VM # start if stopped when: - - vm.status is defined - - vm.status != "running" + - create.status is defined + - create.status != "running" community.general.proxmox_kvm: state: started + handlers: + - name: Initial boot + block: + - name: Start + community.general.proxmox_kvm: + state: started + register: start + retries: 30 + delay: 10 + until: start.status is defined + - name: Wait + ansible.builtin.wait_for: + timeout: 180 + - name: Poweroff + community.general.proxmox_kvm: + state: stopped -- 2.40.1 From 29906fc4621aa4250b1beabdee0a2fbed628293d Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Sun, 10 Sep 2023 23:42:26 +0100 Subject: [PATCH 26/38] no handlers --- infra/joplin/0000_proxmox_playbook.yaml | 34 ++++++++++++------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/infra/joplin/0000_proxmox_playbook.yaml b/infra/joplin/0000_proxmox_playbook.yaml index 80ee4a8..f74b982 100644 --- a/infra/joplin/0000_proxmox_playbook.yaml +++ b/infra/joplin/0000_proxmox_playbook.yaml @@ -36,8 +36,22 @@ clone: "{{ node }}-debian-12" storage: nvme register: create - notify: - - Initial boot + - name: Initial boot + when: create.changed is true + block: + - name: Start + community.general.proxmox_kvm: + state: started + register: start + retries: 30 + delay: 10 + until: start.status is defined + - name: Wait + ansible.builtin.wait_for: + timeout: 180 + - name: Poweroff + community.general.proxmox_kvm: + state: stopped - name: Debug ansible.builtin.debug: var: create @@ -84,19 +98,3 @@ - create.status != "running" community.general.proxmox_kvm: state: started - handlers: - - name: Initial boot - block: - - name: Start - community.general.proxmox_kvm: - state: started - register: start - retries: 30 - delay: 10 - until: start.status is defined - - name: Wait - ansible.builtin.wait_for: - timeout: 180 - - name: Poweroff - community.general.proxmox_kvm: - state: stopped -- 2.40.1 From 763958634ef98c7edd6a2685ef37838bd5d085f5 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Sun, 10 Sep 2023 23:54:34 +0100 Subject: [PATCH 27/38] fix proxmox playbook --- infra/joplin/0000_proxmox_playbook.yaml | 61 +++++++++++++++---------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/infra/joplin/0000_proxmox_playbook.yaml b/infra/joplin/0000_proxmox_playbook.yaml index f74b982..15ccf42 100644 --- a/infra/joplin/0000_proxmox_playbook.yaml +++ b/infra/joplin/0000_proxmox_playbook.yaml @@ -31,30 +31,21 @@ api_token_secret: "{{ api_token_secret }}" name: "{{ vmname }}" tasks: + # Initial setup - name: Create VM community.general.proxmox_kvm: clone: "{{ node }}-debian-12" storage: nvme register: create - - name: Initial boot - when: create.changed is true - block: - - name: Start - community.general.proxmox_kvm: - state: started - register: start - retries: 30 - delay: 10 - until: start.status is defined - - name: Wait - ansible.builtin.wait_for: - timeout: 180 - - name: Poweroff - community.general.proxmox_kvm: - state: stopped - - name: Debug - ansible.builtin.debug: - var: create + - name: Wait for status + community.general.proxmox_kvm: + state: current + register: vm + retries: 30 + delay: 10 + until: vm.status is defined + + # Networking - name: Add HOME NIC community.general.proxmox_nic: interface: net0 @@ -65,6 +56,27 @@ interface: net1 firewall: false bridge: SRV + + # Initial boot + # For some reason debian cloud images don't use + # cloud-init for networking on first boot (cloud-init files + # are regenerated AFTER networking starts). But we need the + # hostname to be registered with DHCP later on so ¯\_(ツ)_/¯ + - name: Initial boot + when: create.changed is true + block: + - name: Start + community.general.proxmox_kvm: + state: started + register: start + - name: Wait # Initial apt update, apt upgrade, cloud-init + ansible.builtin.wait_for: + timeout: 180 + - name: Poweroff + community.general.proxmox_kvm: + state: stopped + + # VM Configuration - name: Resize disk community.general.proxmox_disk: disk: scsi0 @@ -85,16 +97,19 @@ onboot: true cores: 2 memory: 2048 + + # We have now enabled qemu guest agent, but have not installed it + # Rebooting will timeout if started - name: Retart VM # doesn't start if stopped when: - - create.status is defined - - create.status == "running" + - vm.status is defined + - vm.status == "running" community.general.proxmox_kvm: state: restarted timeout: 60 - name: Start VM # start if stopped when: - - create.status is defined - - create.status != "running" + - vm.status is defined + - vm.status != "running" community.general.proxmox_kvm: state: started -- 2.40.1 From 870e4e94765e12be80394fcc57eee58f16b03ece Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Sun, 10 Sep 2023 23:57:43 +0100 Subject: [PATCH 28/38] improve 0001 --- infra/joplin/0001_software_playbook.yaml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/infra/joplin/0001_software_playbook.yaml b/infra/joplin/0001_software_playbook.yaml index 654448d..6d940c3 100644 --- a/infra/joplin/0001_software_playbook.yaml +++ b/infra/joplin/0001_software_playbook.yaml @@ -3,11 +3,16 @@ gather_facts: false tasks: - name: Wait for connection - ansible.builtin.wait_for: - host: "{{ inventory_hostname }}" - port: 22 - timeout: 300 - delegate_to: localhost + ansible.builtin.ping: + register: wait_conn + retries: 30 + delay: 10 + until: wait_conn.ping is defined + # ansible.builtin.wait_for: + # host: "{{ inventory_hostname }}" + # port: 22 + # timeout: 300 + # delegate_to: localhost - name: Test some stuff ansible.builtin.shell: | touch ~/hmm @@ -15,10 +20,6 @@ echo test2 >> ~/test mkdir ~/dir touch ~/dir/testing - register: stuff - retries: 10 - delay: 6 - until: stuff.rc == 0 - name: Install some stuff ansible.builtin.apt: update_cache: true -- 2.40.1 From 8b128060e3a09fbe138cf2eb4680328fff93021e Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Mon, 11 Sep 2023 00:07:56 +0100 Subject: [PATCH 29/38] improve playbooks --- infra/joplin/0000_proxmox_playbook.yaml | 16 +--------------- infra/joplin/0001_software_playbook.yaml | 1 + 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/infra/joplin/0000_proxmox_playbook.yaml b/infra/joplin/0000_proxmox_playbook.yaml index 15ccf42..4a46364 100644 --- a/infra/joplin/0000_proxmox_playbook.yaml +++ b/infra/joplin/0000_proxmox_playbook.yaml @@ -72,9 +72,6 @@ - name: Wait # Initial apt update, apt upgrade, cloud-init ansible.builtin.wait_for: timeout: 180 - - name: Poweroff - community.general.proxmox_kvm: - state: stopped # VM Configuration - name: Resize disk @@ -98,18 +95,7 @@ cores: 2 memory: 2048 - # We have now enabled qemu guest agent, but have not installed it - # Rebooting will timeout if started - - name: Retart VM # doesn't start if stopped - when: - - vm.status is defined - - vm.status == "running" + - name: Retart VM community.general.proxmox_kvm: state: restarted timeout: 60 - - name: Start VM # start if stopped - when: - - vm.status is defined - - vm.status != "running" - community.general.proxmox_kvm: - state: started diff --git a/infra/joplin/0001_software_playbook.yaml b/infra/joplin/0001_software_playbook.yaml index 6d940c3..4cd9611 100644 --- a/infra/joplin/0001_software_playbook.yaml +++ b/infra/joplin/0001_software_playbook.yaml @@ -4,6 +4,7 @@ tasks: - name: Wait for connection ansible.builtin.ping: + ignore_unreachable: true register: wait_conn retries: 30 delay: 10 -- 2.40.1 From bc59bd5fdb68d6aab8795e809dfe084cb280a0f4 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Mon, 11 Sep 2023 00:16:16 +0100 Subject: [PATCH 30/38] wut --- infra/joplin/0001_software_playbook.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/infra/joplin/0001_software_playbook.yaml b/infra/joplin/0001_software_playbook.yaml index 4cd9611..221379c 100644 --- a/infra/joplin/0001_software_playbook.yaml +++ b/infra/joplin/0001_software_playbook.yaml @@ -14,6 +14,9 @@ # port: 22 # timeout: 300 # delegate_to: localhost + - name: Debug + ansible.builtin.debug: + var: wait_conn - name: Test some stuff ansible.builtin.shell: | touch ~/hmm -- 2.40.1 From 5b0bae48652cd8155f7748cc80bf120c2b83bf6d Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Mon, 11 Sep 2023 00:23:37 +0100 Subject: [PATCH 31/38] maybe fix wait for conn --- infra/joplin/0001_software_playbook.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/infra/joplin/0001_software_playbook.yaml b/infra/joplin/0001_software_playbook.yaml index 221379c..3913252 100644 --- a/infra/joplin/0001_software_playbook.yaml +++ b/infra/joplin/0001_software_playbook.yaml @@ -9,6 +9,7 @@ retries: 30 delay: 10 until: wait_conn.ping is defined + failed_when: wait_conn.ping is not defined # ansible.builtin.wait_for: # host: "{{ inventory_hostname }}" # port: 22 -- 2.40.1 From 92fbca47db6051e9ed0c0d99af037d7c0306f956 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Mon, 11 Sep 2023 00:34:59 +0100 Subject: [PATCH 32/38] fix wait for conn --- infra/joplin/0001_software_playbook.yaml | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/infra/joplin/0001_software_playbook.yaml b/infra/joplin/0001_software_playbook.yaml index 3913252..a3e1006 100644 --- a/infra/joplin/0001_software_playbook.yaml +++ b/infra/joplin/0001_software_playbook.yaml @@ -3,21 +3,8 @@ gather_facts: false tasks: - name: Wait for connection - ansible.builtin.ping: - ignore_unreachable: true - register: wait_conn - retries: 30 - delay: 10 - until: wait_conn.ping is defined - failed_when: wait_conn.ping is not defined - # ansible.builtin.wait_for: - # host: "{{ inventory_hostname }}" - # port: 22 - # timeout: 300 - # delegate_to: localhost - - name: Debug - ansible.builtin.debug: - var: wait_conn + ansible.builtin.wait_for_connection: + timeout: 300 - name: Test some stuff ansible.builtin.shell: | touch ~/hmm -- 2.40.1 From 41a0c9393eac2fa2cf9c2eaff80cb6106090e62e Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Mon, 11 Sep 2023 00:43:36 +0100 Subject: [PATCH 33/38] escalate to root for 0001 --- infra/joplin/0000_proxmox_playbook.yaml | 2 +- infra/joplin/0001_software_playbook.yaml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/infra/joplin/0000_proxmox_playbook.yaml b/infra/joplin/0000_proxmox_playbook.yaml index 4a46364..a415705 100644 --- a/infra/joplin/0000_proxmox_playbook.yaml +++ b/infra/joplin/0000_proxmox_playbook.yaml @@ -71,7 +71,7 @@ register: start - name: Wait # Initial apt update, apt upgrade, cloud-init ansible.builtin.wait_for: - timeout: 180 + timeout: 90 # VM Configuration - name: Resize disk diff --git a/infra/joplin/0001_software_playbook.yaml b/infra/joplin/0001_software_playbook.yaml index a3e1006..fa5dd05 100644 --- a/infra/joplin/0001_software_playbook.yaml +++ b/infra/joplin/0001_software_playbook.yaml @@ -16,8 +16,10 @@ ansible.builtin.apt: update_cache: true name: qemu-guest-agent + become: true - name: Enable some stuff ansible.builtin.systemd: name: qemu-guest-agent state: started enabled: true + become: true -- 2.40.1 From 6dfab582c4eded6f6f24a0639eb20ede5b361232 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Mon, 11 Sep 2023 00:49:27 +0100 Subject: [PATCH 34/38] wait for 3 min afterall --- infra/joplin/0000_proxmox_playbook.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infra/joplin/0000_proxmox_playbook.yaml b/infra/joplin/0000_proxmox_playbook.yaml index a415705..95bc871 100644 --- a/infra/joplin/0000_proxmox_playbook.yaml +++ b/infra/joplin/0000_proxmox_playbook.yaml @@ -69,9 +69,9 @@ community.general.proxmox_kvm: state: started register: start - - name: Wait # Initial apt update, apt upgrade, cloud-init + - name: Wait 3 min # Initial apt update, apt upgrade, cloud-init ansible.builtin.wait_for: - timeout: 90 + timeout: 180 # VM Configuration - name: Resize disk -- 2.40.1 From 6b2a8202826a39d01291ffbaf79b02c3b279bd47 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Mon, 11 Sep 2023 01:05:55 +0100 Subject: [PATCH 35/38] increase apt timeout --- infra/joplin/0001_software_playbook.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/infra/joplin/0001_software_playbook.yaml b/infra/joplin/0001_software_playbook.yaml index fa5dd05..217af44 100644 --- a/infra/joplin/0001_software_playbook.yaml +++ b/infra/joplin/0001_software_playbook.yaml @@ -15,6 +15,7 @@ - name: Install some stuff ansible.builtin.apt: update_cache: true + lock_timeout: 120 name: qemu-guest-agent become: true - name: Enable some stuff -- 2.40.1 From ac3494efc5fa02ec1a02dd7808e19f489d741f67 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Mon, 11 Sep 2023 01:19:31 +0100 Subject: [PATCH 36/38] fix order of tasks --- infra/joplin/0000_proxmox_playbook.yaml | 32 ++++++++++++------------ infra/joplin/0001_software_playbook.yaml | 1 - 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/infra/joplin/0000_proxmox_playbook.yaml b/infra/joplin/0000_proxmox_playbook.yaml index 95bc871..ac4fa50 100644 --- a/infra/joplin/0000_proxmox_playbook.yaml +++ b/infra/joplin/0000_proxmox_playbook.yaml @@ -57,22 +57,6 @@ firewall: false bridge: SRV - # Initial boot - # For some reason debian cloud images don't use - # cloud-init for networking on first boot (cloud-init files - # are regenerated AFTER networking starts). But we need the - # hostname to be registered with DHCP later on so ¯\_(ツ)_/¯ - - name: Initial boot - when: create.changed is true - block: - - name: Start - community.general.proxmox_kvm: - state: started - register: start - - name: Wait 3 min # Initial apt update, apt upgrade, cloud-init - ansible.builtin.wait_for: - timeout: 180 - # VM Configuration - name: Resize disk community.general.proxmox_disk: @@ -95,6 +79,22 @@ cores: 2 memory: 2048 + # Initial boot + # For some reason debian cloud images don't use + # cloud-init for networking on first boot (cloud-init files + # are regenerated AFTER networking starts). But we need the + # hostname to be registered with DHCP later on so ¯\_(ツ)_/¯ + - name: Initial boot + when: create.changed is true + block: + - name: Start + community.general.proxmox_kvm: + state: started + register: start + - name: Wait 3 min # Initial apt update, apt upgrade, cloud-init + ansible.builtin.wait_for: + timeout: 180 + - name: Retart VM community.general.proxmox_kvm: state: restarted diff --git a/infra/joplin/0001_software_playbook.yaml b/infra/joplin/0001_software_playbook.yaml index 217af44..fa5dd05 100644 --- a/infra/joplin/0001_software_playbook.yaml +++ b/infra/joplin/0001_software_playbook.yaml @@ -15,7 +15,6 @@ - name: Install some stuff ansible.builtin.apt: update_cache: true - lock_timeout: 120 name: qemu-guest-agent become: true - name: Enable some stuff -- 2.40.1 From dfcfe941cfce45a849d2549ff0d203224f0b299e Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Mon, 11 Sep 2023 01:27:02 +0100 Subject: [PATCH 37/38] actually fix order of things --- infra/joplin/0000_proxmox_playbook.yaml | 34 +++++++++++++------------ 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/infra/joplin/0000_proxmox_playbook.yaml b/infra/joplin/0000_proxmox_playbook.yaml index ac4fa50..6b9a11e 100644 --- a/infra/joplin/0000_proxmox_playbook.yaml +++ b/infra/joplin/0000_proxmox_playbook.yaml @@ -45,7 +45,7 @@ delay: 10 until: vm.status is defined - # Networking + # Networking and initial config - name: Add HOME NIC community.general.proxmox_nic: interface: net0 @@ -56,14 +56,7 @@ interface: net1 firewall: false bridge: SRV - - # VM Configuration - - name: Resize disk - community.general.proxmox_disk: - disk: scsi0 - size: 64G - state: resized - - name: Update VM + - name: Configure cloud-init community.general.proxmox_kvm: update: true ciuser: debian @@ -71,13 +64,6 @@ ipconfig: ipconfig0: ip=dhcp,ip6=auto ipconfig1: ip=dhcp - agent: enabled=1 - tags: - - debian-12 - - managed - onboot: true - cores: 2 - memory: 2048 # Initial boot # For some reason debian cloud images don't use @@ -95,6 +81,22 @@ ansible.builtin.wait_for: timeout: 180 + # VM Configuration + - name: Resize disk + community.general.proxmox_disk: + disk: scsi0 + size: 64G + state: resized + - name: Update VM + community.general.proxmox_kvm: + agent: enabled=1 + tags: + - debian-12 + - managed + onboot: true + cores: 2 + memory: 2048 + - name: Retart VM community.general.proxmox_kvm: state: restarted -- 2.40.1 From 72a790c038c33eb570a756f41dbe6641b0991d40 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Mon, 11 Sep 2023 01:40:29 +0100 Subject: [PATCH 38/38] don't suffocate the vm --- infra/joplin/0000_proxmox_playbook.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/infra/joplin/0000_proxmox_playbook.yaml b/infra/joplin/0000_proxmox_playbook.yaml index 6b9a11e..6a0be63 100644 --- a/infra/joplin/0000_proxmox_playbook.yaml +++ b/infra/joplin/0000_proxmox_playbook.yaml @@ -89,6 +89,7 @@ state: resized - name: Update VM community.general.proxmox_kvm: + update: true agent: enabled=1 tags: - debian-12 -- 2.40.1