Skip to content

Commit

Permalink
initial FreeBSD jail support completed
Browse files Browse the repository at this point in the history
  • Loading branch information
stafwag committed Mar 15, 2020
1 parent 84e1350 commit 9d6fffb
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 9 deletions.
68 changes: 66 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,28 @@ An ansible role to update all packages (multiplatform)
* Suse

## Role Variables
### OS related variables

None
The following variables are set by the role.

* **freebsd_running_jails**: List with the running FreeBSD jails.

### Playbook related variables

* **package_update**: "name space"
* **freebsd**: "freebsd config"
* **get_running_fails**: no | yes (default) set the freebsd_running_jails variable.
* **host**: no | yes (default) update the host system
* **jails**: Array of jails to update, **freebsd_running_jails** by default.


## Dependencies

None

## Example Playbook
## Example Playbooks

### Upgrade

```
---
Expand All @@ -33,6 +47,56 @@ None
- stafwag.package_update
```

### Update only the FreeBSD host systems.

```
---
- name: update packages
hosts: all
become: true
roles:
- role: stafwag.package_update
vars:
package_update:
freebsd:
get_running_fails: no
jails: []
```

### Update only the running jails on FreeBSD systems.

```
---
- name: update packages
hosts: all
become: true
roles:
- role: stafwag.package_update
vars:
package_update:
freebsd:
host: no
```

### Update a jail on a FreeBSD system.

```
---
- name: update packages
hosts: rataplan
become: true
roles:
- role: stafwag.package_update
vars:
package_update:
freebsd:
host: no
jails:
- stafmail
```


## License

MIT/BSD
Expand Down
30 changes: 28 additions & 2 deletions tasks/update/FreeBSD.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
- name: update host
include_tasks: FreeBSD/update_host.yml
- name: set _update_freebsd_host
set_fact:
_update_freebsd_host: '{{ package_update.freebsd.host | default(true) }}'

- name: set _get_running_jails
set_fact:
_get_running_jails: '{{ package_update.freebsd.get_running_fails | default(true) }}'

- name: get the running jails
include_tasks: FreeBSD/get_running_jails.yml
when:
- _get_running_jails

- name: set _update_freebsd_jails
set_fact:
_update_freebsd_jails: '{{ package_update.freebsd.jails | default( freebsd_running_jails) }}'

- name: add id 0 to the list to update the host system
set_fact:
_update_freebsd_jails: '{{ [ 0 ] + _update_freebsd_jails }}'
when:
- _update_freebsd_host

- name: update jails
include_tasks: FreeBSD/update.yml
loop: "{{ _update_freebsd_jails | default(omit) }}"
loop_control:
loop_var: jail_id
7 changes: 7 additions & 0 deletions tasks/update/FreeBSD/get_running_jails.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- name: execute jls
shell: jls | sed 1d | awk '{ print $3 }'
register: cmd_jail_id_list
changed_when: False
- name: set freebsd_running_jails
set_fact:
freebsd_running_jails: '{{ cmd_jail_id_list.stdout_lines }}'
22 changes: 22 additions & 0 deletions tasks/update/FreeBSD/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
- name: set my_pkg_cmd var for host
set_fact:
my_pkg_cmd: pkg
when:
- jail_id == 0
- name: set my_pkg_cmd for jail
set_fact:
my_pkg_cmd: 'pkg -j {{ jail_id }}'
when:
- jail_id != 0
- name: 'pkg update {{ jail_id }}'
command: '{{ my_pkg_cmd }} update'
register: pkg_update_y
changed_when: "pkg_update_y.rc != 0"
- name: 'verify if there are upgrades available {{ jail_id }}'
command: '{{ my_pkg_cmd }} upgrade -n'
register: pkg_upgrade_n
changed_when: "pkg_upgrade_n.rc != 0"
failed_when: "pkg_upgrade_n.rc > 1"
- name: 'upgrade {{ jail_id }}'
command: '{{ my_pkg_cmd }} upgrade -y'
when: "pkg_upgrade_n.rc != 0"
5 changes: 0 additions & 5 deletions tasks/update/FreeBSD/update_host.yml

This file was deleted.

0 comments on commit 9d6fffb

Please sign in to comment.