Skip to content

Commit

Permalink
roles: improve ability to check for un/installed packages
Browse files Browse the repository at this point in the history
The `rpm_ostree_install*` and `rpm_ostree_uninstall*` roles had some
limitations when first created.  Namely, only being able to be used
once per playbook and being unable to check for a binary that did not
match the package name.

This changes the roles to use the `allow_duplicates` boolean, so that
they may be used multiple times in the same playbook.  The `*verify`
roles have also been changed to allow for checking for a different
binary name than what is used by the package.  For example, the `ntp`
package installs an `ntpd` binary, whereas the `httpd` package installs
an `httpd` binary.
  • Loading branch information
miabbott committed Oct 5, 2017
1 parent 8e38f72 commit 20d0a82
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions roles/rpm_ostree_install/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
allow_duplicates: true
2 changes: 2 additions & 0 deletions roles/rpm_ostree_install_verify/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
allow_duplicates: true
13 changes: 9 additions & 4 deletions roles/rpm_ostree_install_verify/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
#
# Parameter:
# package - name of a single package
# binary - name of binary to check for (optional)
#
# Requirements:
# Package must install a binary that is the same as the package name
# i.e. rpm-ostree install wget installs a binary named wget
# This role must be run after the reboot following rpm-ostree install of a package
#

Expand All @@ -20,6 +19,12 @@
msg: "No packages specified"
when: package is undefined

# The 'binary' fact can be set to something other than the package name
# if needed
- name: Setup binary fact
set_fact:
bin: "{{ binary if binary is defined else package }}"

- name: Get rpm-ostree status --json output
command: rpm-ostree status --json
register: installed
Expand All @@ -43,8 +48,8 @@
msg: "{{ package }} not in rpm-ostree status output"
when: "'{{ package }}' not in installed_pkgs"

- name: Check for {{ package }} binary
command: command -v {{ package }}
- name: Check for {{ bin }} binary
command: command -v {{ bin }}

- name: Check {{ package }} in rpmdb
command: rpm -q {{ package }}
2 changes: 2 additions & 0 deletions roles/rpm_ostree_uninstall/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
allow_duplicates: true
2 changes: 2 additions & 0 deletions roles/rpm_ostree_uninstall_verify/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
allow_duplicates: true
13 changes: 9 additions & 4 deletions roles/rpm_ostree_uninstall_verify/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
#
# Parameter:
# package - the name of a single package
# binary - the name of a binary (optional)
#
# Requirements:
# Package must install a binary that is the same as the package name
# i.e. rpm-ostree uninstall wget installs a binary named wget
# This role must be run after the reboot following rpm-ostree install of a package
#

Expand All @@ -20,6 +19,12 @@
msg: "No packages specified"
when: package is undefined

# The 'binary' fact can be set to something other than the package name
# if needed
- name: Setup binary fact
set_fact:
bin: "{{ binary if binary is defined else package }}"

- name: Get rpm-ostree status --json output
command: rpm-ostree status --json
register: installed
Expand Down Expand Up @@ -51,8 +56,8 @@
msg: "{{ package }} in rpm-ostree status output"
when: "'{{ package }}' in installed_pkgs"

- name: Fail if binary for {{ package }} is installed
command: command -v {{ package }}
- name: Fail if binary for {{ bin }} is installed
command: command -v {{ bin }}
register: binary
failed_when: binary.rc != 1

Expand Down

0 comments on commit 20d0a82

Please sign in to comment.