ansible-experiments/package_updates/roles/freebsd-update/tasks/main.yml
Bryan Black 58ce5f14f2
fix for 'No updates are available to install' error
resolves common problem of false `No updates are available to install` errors after updating FreeBSD base OS files.

```yml
TASK [freebsd-update : Install FreeBSD updates] ****************************************************
fatal: [freebsd6]: FAILED! => {"changed": true, "cmd": ["freebsd-update", "install", "--not-running-from-cron"], "delta": "0:00:00.274477", "end": "2018-05-14 18:13:56.977638", "msg": "non-zero return code", "rc": 1, "start": "2018-05-14 18:13:56.703161", "stderr": "rm: filelist: No such file or directory", "stderr_lines": ["rm: filelist: No such file or directory"], "stdout": "src component not installed, skipped\nInstalling updates...", "stdout_lines": ["src component not installed, skipped", "Installing updates..."]}
changed: [freebsd5]

TASK [freebsd-update : debug] **********************************************************************
```
2018-05-14 11:29:22 -07:00

39 lines
1.3 KiB
YAML

---
- name: Fetch any new FreeBSD updates
command: freebsd-update fetch --not-running-from-cron
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
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