Skip to content

Commit c74f2ea

Browse files
authored
refactor: replace unix commands with ansible modules (#77)
- Replace curl with get_url module in anvil_docker and tailscale roles - Replace rsync command with synchronize module in anvil_docker role - Add delegate_to for synchronize to ensure local file synchronization - Remove command-instead-of-module from ansible-lint skip list (no longer needed) This ensures better idempotency and follows ansible best practices.
1 parent 84b0789 commit c74f2ea

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

.ansible-lint

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ skip_list:
77
- no-handler # Tasks that run when changed should likely be handlers
88
- ignore-errors # Use failed_when and specify error conditions
99
- risky-shell-pipe # Shells that use pipes should set the pipefail option
10-
- command-instead-of-module # Using command rather than module
1110
- schema[meta] # Skip meta file schema validation to avoid CI-only errors
1211

1312
warn_list: []

ansible/roles/anvil_docker/tasks/main.yaml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@
88
cache_valid_time: 3600
99
become: true
1010

11-
- name: Download and install Docker
12-
ansible.builtin.shell: curl https://get.docker.com | sh
11+
- name: Download Docker installation script
12+
ansible.builtin.get_url:
13+
url: https://get.docker.com
14+
dest: /tmp/get-docker.sh
15+
mode: "0755"
16+
become: true
17+
18+
- name: Install Docker
19+
ansible.builtin.command: /bin/sh /tmp/get-docker.sh
1320
args:
1421
creates: /usr/bin/docker
1522
become: true
@@ -72,9 +79,13 @@
7279
become: true
7380

7481
- name: Migrate Docker data to new location
75-
ansible.builtin.command: rsync -axPS /var/lib/docker/ /mnt/ssd/docker/
82+
ansible.posix.synchronize:
83+
src: /var/lib/docker/
84+
dest: /mnt/ssd/docker/
85+
rsync_opts:
86+
- -axPS
7687
become: true
77-
changed_when: true
88+
delegate_to: "{{ inventory_hostname }}"
7889

7990
- name: Check new Docker data directory size
8091
ansible.builtin.command: du -csh /mnt/ssd/docker/

ansible/roles/tailscale/tasks/main.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# Simplified Tailscale installation using official script
22

3-
- name: Download and run Tailscale official installer
4-
ansible.builtin.shell: |
5-
curl -fsSL https://tailscale.com/install.sh | sh
3+
- name: Download Tailscale installation script
4+
ansible.builtin.get_url:
5+
url: https://tailscale.com/install.sh
6+
dest: /tmp/tailscale-install.sh
7+
mode: "0755"
8+
become: true
9+
10+
- name: Run Tailscale official installer
11+
ansible.builtin.command: /bin/sh /tmp/tailscale-install.sh
612
args:
713
creates: /usr/bin/tailscale
814
become: true

0 commit comments

Comments
 (0)