Skip to content

Commit

Permalink
ansible: fix needed to run debian8 bootstrap in check mode (#2499)
Browse files Browse the repository at this point in the history
Running playbooks using the `bootstrap` role on machines running debian8
failed when in check mode:

```
$ ansible-playbook --check playbooks/create-github-bot.yml

TASK [bootstrap : check for apt-transport-https] ****************************************************************************************************************************************
skipping: [infra-rackspace-debian8-x64-1]

TASK [bootstrap : install apt-transport-https] ******************************************************************************************************************************************
fatal: [infra-rackspace-debian8-x64-1]: FAILED! => {"msg": "The conditional check 'has_apt_transport.rc == 1' failed. The error was: error while evaluating conditional (has_apt_transport.rc == 1): 'dict object' has no attribute 'rc'\n\nThe error appears to be in '/..../build/ansible/roles/bootstrap/tasks/partials/debian8.yml': line 12, 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: install apt-transport-https\n  ^ here\n"}
```

The `install apt-transport-https` task failed due to the fact that the
preceding `check for apt-transport-https` did not define the
`has_apt_transport` result because it got skipped.

Ansible skips `raw` tasks by default as a precaution when run in check
mode, in case it has a side effect.

Further discussions made us want to use ansible' `stat` module instead
primarily because it is more self descriptive compared to the `raw`
trick we had before.
  • Loading branch information
phillipj committed Dec 21, 2020
1 parent 42128d5 commit 2ddeda6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ansible/roles/bootstrap/tasks/partials/debian8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#

- name: check for apt-transport-https
raw: stat /usr/lib/apt/methods/https
stat:
path: /usr/lib/apt/methods/https
register: has_apt_transport
failed_when: has_apt_transport.rc > 1

- name: install apt-transport-https
when: has_apt_transport.rc == 1
when: has_apt_transport.stat.exists == False
raw: apt-get install -y apt-transport-https

- name: install dbus
Expand Down

0 comments on commit 2ddeda6

Please sign in to comment.