geerlingguy / ansible-role-docker_arm

Ansible Role - Docker for ARM and Pi
MIT License
98 stars 29 forks source link

Dryrun failing because of missing check_mode: no option in validation task #18

Closed callmeconnor closed 3 years ago

callmeconnor commented 3 years ago

Hi, just "--check"runned a tiny installation playbook calling your and noticed an error right at the 1nd task preventing successfull execution.

Expected behaviour:

ansible-playbook docker_install.yml --check
 [WARNING]: provided hosts list is empty, only localhost is available [...]

PLAY [Docker playbook] **************************************************************************
TASK [Gathering Facts] **************************************************************************
ok: [localhost]

TASK [geerlingguy.docker_arm : Check if Docker is already present.] *****************************
skipping: [localhost]
[...]

Actual behaviour:

ansible-playbook docker_install.yml --check
[WARNING]: provided hosts list is empty, only localhost is available [...]

PLAY [Docker playbook] **************************************************************************
TASK [Gathering Facts] **************************************************************************
ok: [localhost]

TASK [geerlingguy.docker_arm : Download Docker install convenience script.] *********************
fatal: [localhost]: 
FAILED! => {"msg": "The conditional check 'docker_command_result.rc == 1' failed. The error was: error while evaluating conditional (docker_command_result.rc == 1): 'dict object' has no attribute 'rc'\n\nThe error appears to have been in '/home/pi/.ansible/roles/geerlingguy.docker_arm/tasks/main.yml': line 8, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Download Docker install convenience script.\n  ^ here\n"}
        to retry, use: --limit @/home/pi/docker_install.retry

PLAY RECAP **************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1

I'm quite familiar with this behaviour, that commands, in this case in the Task: "geerlingguy.docker_arm : Check if Docker is already present." is skipped in a check run. AFAIK the command "which docker" is still the most convenient way to go here, in case a simple validation task is done.

So, as in many other occasions I simply added the option "check_mode: no" to the task wich produces the expected dryrun behaviour which now works like a charm :) . Would you like to add that here also? Hope I get githubs PR workflow figured out quickly, will add this then ;)

stale[bot] commented 3 years ago

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] commented 3 years ago

This issue is no longer marked for closure.

geerlingguy commented 3 years ago

I'd like to make sure the role works in check mode, so feel free to file a PR. Thanks!

callmeconnor commented 3 years ago

OK, polishing it up now... will reply here once linting is OK. Sadly, I missed that your project lint's as it should, but initially didn't care too much...

callmeconnor commented 3 years ago

OK, git groundwork done. Noticed you removed linting again, so also not relevant for my pullrequest anymore, I guess...

Glorious one liner pull request 19 is still existing ;) . Ready for you to review and merge: https://github.com/geerlingguy/ansible-role-docker_arm/pull/19

callmeconnor commented 3 years ago

hmm, not too deep into it, but:

Molecule default > converge
WARNING  An error occurred during the test sequence action: 'converge'. Cleaning up.

I may be missing something, Molecule may be right and I caused something not to comply any more...

callmeconnor commented 3 years ago

Proof of work OK, did a check run, current output see below - tasks after "Check if Docker is already present" work as expected:

ansible-playbook raspi-docker.yml --check --connection=local
 [WARNING]: Found both group and host with same name: localhost

Executing playbook raspi-docker.yml

- Base Config for pi -
Gathering Facts...
Sunday 11 April 2021  14:45:00 +0200 (0:00:00.529)       0:00:00.529 ********** 
  localhost ok
Check if Docker is already present....
Sunday 11 April 2021  14:45:06 +0200 (0:00:05.915)       0:00:06.445 ********** 
  localhost ok | stdout: /usr/bin/docker
Download Docker install convenience script....
Sunday 11 April 2021  14:45:08 +0200 (0:00:01.880)       0:00:08.325 ********** 
Run Docker install convenience script....
Sunday 11 April 2021  14:45:08 +0200 (0:00:00.282)       0:00:08.608 ********** 
Make sure Docker CE is the version specified....
Sunday 11 April 2021  14:45:09 +0200 (0:00:00.283)       0:00:08.892 ********** 
  localhost done | stdout: Reading package lists...
Building dependency tree...
Reading state information...
Recommended packages:
  cgroupfs-mount | cgroup-lite libltdl7
The following packages will be DOWNGRADED:
  docker-ce
0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
Inst docker-ce [5:20.10.5~3-0~raspbian-buster] (5:19.03.12~3-0~raspbian-buster Docker CE:buster [armhf])
Conf docker-ce (5:19.03.12~3-0~raspbian-buster Docker CE:buster [armhf])
 | stderr: W: --force-yes is deprecated, use one of the options starting with --allow instead.

Ensure containerd service dir exists....
Sunday 11 April 2021  14:45:19 +0200 (0:00:10.145)       0:00:19.037 ********** 
Add shim to ensure Docker can start in all environments....
Sunday 11 April 2021  14:45:19 +0200 (0:00:00.308)       0:00:19.346 ********** 
Reload systemd daemon if template is changed....
Sunday 11 April 2021  14:45:19 +0200 (0:00:00.324)       0:00:19.671 ********** 
Ensure Docker is started....
Sunday 11 April 2021  14:45:20 +0200 (0:00:00.313)       0:00:19.984 ********** 
  localhost ok
Install Docker Compose using Pip....
Sunday 11 April 2021  14:45:24 +0200 (0:00:03.843)       0:00:23.828 ********** 
Ensure docker users are added to the docker group....
Sunday 11 April 2021  14:45:24 +0200 (0:00:00.293)       0:00:24.122 ********** 
  localhost ok

- Play recap -
  localhost                  : ok=5    changed=1    unreachable=0    failed=0   
Sunday 11 April 2021  14:45:26 +0200 (0:00:02.506)       0:00:26.629 ********** 
=============================================================================== 
ansible-role-docker_arm : Make sure Docker CE is the version specified. ----------- 10.15s
Gathering Facts -------------------------------------------------------------------- 5.92s
ansible-role-docker_arm : Ensure Docker is started. -------------------------------- 3.84s
ansible-role-docker_arm : Ensure docker users are added to the docker group. ------- 2.51s
ansible-role-docker_arm : Check if Docker is already present. ---------------------- 1.88s
ansible-role-docker_arm : Add shim to ensure Docker can start in all environments. --- 0.32s
ansible-role-docker_arm : Reload systemd daemon if template is changed. ------------ 0.31s
ansible-role-docker_arm : Ensure containerd service dir exists. -------------------- 0.31s
ansible-role-docker_arm : Install Docker Compose using Pip. ------------------------ 0.29s
ansible-role-docker_arm : Run Docker install convenience script. ------------------- 0.28s
ansible-role-docker_arm : Download Docker install convenience script. -------------- 0.28s

P.S.: maybe "Make sure Docker CE is the version specified" could better work with dpkg instead of APT for a speedy result... or APT should get a flag set NOT to update caches instead... but that would be another issue.

geerlingguy commented 3 years ago

Fixed via #19