Skip to content

Commit

Permalink
Use stat instead of which to check pass presence
Browse files Browse the repository at this point in the history
  • Loading branch information
gotmax23 committed Oct 27, 2021
1 parent c25b66d commit 7cd40d0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
4 changes: 2 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ pass_version: latest
# [Makefile][2] in Pass's Git repository for all available parameters.
pass_make_params:
# You can remove this value to install Pass to the default location, /usr/bin.
# You are welcome to change it to any other value, as long as "$PREFIX/bin" is
# in your system's PATH.
# You are welcome to change it to any other value, though I recomend keeping
# the default to avoid conflicting with the system package manager.
PREFIX: /usr/local # Install pass to /usr/local/bin
14 changes: 4 additions & 10 deletions tasks/source_install.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
---
- name: Install which
ansible.builtin.package:
name: "{{ pass_which_package }}"

- name: Check if Pass is present
register: _pass_presence
changed_when: false
failed_when: false
ansible.builtin.command:
cmd: which pass
ansible.builtin.stat:
path: "{{ pass_src_bin_path }}"

- name: Download Pass source files
# This conditional instructs Ansible to only download source files when state
# is present or if state is absent *and Pass is currently installed*. The latter
# ensures that `pass_state == "present"` *and* `pass_state == "absent"` are idempotent.
when: (pass_state == "present") or
(pass_state == "absent" and _pass_presence.rc == 0)
(pass_state == "absent" and _pass_presence.stat.exists | bool)
block:
- name: Install build dependencies
ansible.builtin.package:
Expand Down Expand Up @@ -54,7 +48,7 @@
# This conditional is similar to the one above. The only difference is that
# when `pass_state == present`, this task will only run if the source files
# have changed.
when: (pass_make_target == "uninstall" and _pass_presence.rc == 0) or
when: (pass_make_target == "uninstall" and _pass_presence.stat.exists | bool) or
(pass_make_target == "install" and _pass_ua_tarball.changed | bool)
community.general.make:
chdir: "{{ pass_src_dir }}"
Expand Down
6 changes: 1 addition & 5 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pass_clipboard_package: "{{ _pass_clipboard_package[pass_clipboard_helper] | def

##########
# These Variables only apply when `pass_install_method=source`.
pass_src_bin_path: "{{ pass_make_params['PREFIX'] | default('/usr') }}/bin/pass"

_pass_make_target:
present: install
Expand All @@ -28,11 +29,6 @@ _pass_xz_package:
default: xz
pass_xz_package: "{{ _pass_xz_package[ansible_os_family] | default(_pass_xz_package['default']) }}"

_pass_which_package:
Debian: debianutils
default: which
pass_which_package: "{{ _pass_which_package[ansible_os_family] | default(_pass_which_package['default']) }}"

_pass_gpg_package:
default: gpg
Archlinux: gnupg
Expand Down

0 comments on commit 7cd40d0

Please sign in to comment.