Skip to content

Instantly share code, notes, and snippets.

@theory14
Created September 12, 2015 10:35
Show Gist options
  • Save theory14/1ea4075287a17fb9f66e to your computer and use it in GitHub Desktop.
Save theory14/1ea4075287a17fb9f66e to your computer and use it in GitHub Desktop.
Ansible role for updating FreeBSD machines with freebsd-update and pkg
---
- name: Check status of jailing
shell: "sysctl security.jail.jailed | cut -d: -f2 | tr -d ' '"
register: is_jail
when: "ansible_os_family == 'FreeBSD' "
- name: Fetch and Install Updates
command: "{{ item }}"
when: "ansible_os_family == 'FreeBSD' and is_jail.stdout == '0'"
ignore_errors: yes
with_items:
- "freebsd-update --not-running-from-cron fetch"
- "freebsd-update --not-running-from-cron install"
- name: pkg updates
command: " {{ item }} "
when: "ansible_os_family == 'FreeBSD'"
with_items:
- "pkg update -q"
- "pkg upgrade -y"
- "pkg clean -qy"
- name: Check for jails
shell: "jls | grep -v JID | wc -l | tr -d ' '"
register: has_jails
when: "ansible_os_family == 'FreeBSD'"
- name: Update base jail
command: 'ezjail-admin update -u'
when: "ansible_os_family == 'FreeBSD' and has_jails.stdout != '0' and is_jail.stdout == '0'"
@girgen
Copy link

girgen commented May 16, 2017

shell: sysctl -n security.jail.jailed

is more clever than | cut | tr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment