ansible-experiments/package_updates/roles/freebsd-update/tasks/main.yml
Bryan Black 3707750246
fix for #7
Fix for https://github.com/stationgroup/ansible-experiments/issues/7

I think `freebsd-update` return failed even when _"No updates needed"_ or _"No update are available"_. https://github.com/freebsd/pkg/issues/1470


```
  failed_when: False # --dry-run always returns failure
                     # https://github.com/freebsd/pkg/issues/1470
```
2018-05-15 10:20:13 -07:00

43 lines
1.6 KiB
YAML

---
- name: Fetch any new FreeBSD updates
command: freebsd-update fetch --not-running-from-cron
failed_when: False # --dry-run always returns failure
# https://github.com/freebsd/pkg/issues/1470
check_mode: no
when: ansible_distribution == 'FreeBSD'
register: result_update
changed_when: "'No updates needed' not in result_update.stdout"
- debug: var=result_update
when: result_update.changed
- name: Install FreeBSD updates
command: freebsd-update install --not-running-from-cron
failed_when: False # --dry-run always returns failure
# https://github.com/freebsd/pkg/issues/1470
when: ansible_distribution == 'FreeBSD' and result_update.changed and not ansible_check_mode
register: result_update_install
changed_when: "'No updates are available to install' not in result_update_install.stdout"
- debug: var=result_update_install
when: result_update_install.changed
- name: Upgrade FreeBSD packages - dry-run
command: pkg upgrade --dry-run
failed_when: False # --dry-run always returns failure
# https://github.com/freebsd/pkg/issues/1470
check_mode: no
when: ansible_distribution == 'FreeBSD' and ansible_check_mode
register: result_pkg
changed_when: "'Your packages are up to date' not in result_pkg.stdout"
- name: Upgrade FreeBSD packages
command: pkg upgrade --yes
when: ansible_distribution == 'FreeBSD' and not ansible_check_mode
register: result_pkg
changed_when: "'Your packages are up to date' not in result_pkg.stdout"
- debug: var=result_pkg
when: result_pkg.changed