fix: make Ansible reruns faster and idempotent
This commit is contained in:
@@ -45,9 +45,16 @@
|
||||
state: present
|
||||
lock_timeout: 600
|
||||
|
||||
- name: Check active swap
|
||||
command: swapon --noheadings
|
||||
register: active_swap
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Disable swap
|
||||
command: swapoff -a
|
||||
changed_when: true
|
||||
when: active_swap.stdout | trim | length > 0
|
||||
|
||||
- name: Remove swap from fstab
|
||||
lineinfile:
|
||||
@@ -100,9 +107,17 @@
|
||||
failed_when: false
|
||||
when: tailscale_auth_key | length > 0
|
||||
|
||||
- name: Parse tailscale connection state
|
||||
set_fact:
|
||||
tailscale_backend_state: "{{ (tailscale_status.stdout | from_json).BackendState | default('') }}"
|
||||
when:
|
||||
- tailscale_auth_key | length > 0
|
||||
- tailscale_status.rc == 0
|
||||
- tailscale_status.stdout | length > 0
|
||||
|
||||
- name: Connect node to tailnet
|
||||
command: tailscale up --authkey {{ tailscale_auth_key }} --hostname {{ inventory_hostname }} --ssh={{ tailscale_ssh | ternary('true', 'false') }} --accept-routes={{ tailscale_accept_routes | ternary('true', 'false') }}
|
||||
when:
|
||||
- tailscale_auth_key | length > 0
|
||||
- tailscale_status.rc != 0 or '"BackendState":"Running"' not in tailscale_status.stdout
|
||||
- tailscale_status.rc != 0 or (tailscale_backend_state | default('')) != 'Running'
|
||||
changed_when: true
|
||||
|
||||
Reference in New Issue
Block a user