Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it work with check_mode #39

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions tasks/debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,29 @@
retries: 5
delay: 5

- name: Temp file for check mode
set_fact:
__temp_file_for_check_mode: "/tmp/galaxyproject_postgresql_get_installed_version_trick"

- name: Create temp file for check_mode
ansible.builtin.copy:
content: ""
dest: "{{ __temp_file_for_check_mode }}"
force: yes
mode: '0777'
check_mode: no

- name: Get installed version
command: dpkg-query -f ${Version;3} --show postgresql
shell: "dpkg-query -f '${Version;3}' --show postgresql"
when: postgresql_version is not defined
register: __postgresql_version_query_result
changed_when: false
check_mode: no
args:
# Using this in order to enforce the task to be executed in check mode
removes: "{{ __temp_file_for_check_mode }}"
Comment on lines 39 to +47
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we're shelling out to dpkg-query anyway, could we use something like the package facts module instead that might be natively check-safe? @natefoo ?

Copy link
Contributor Author

@diraol diraol Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it is ok even though it has the following requirements?

REQUIREMENTS

The below requirements are needed on the host that executes this module.

For ‘portage’ support it requires the qlist utility, which is part of ‘app-portage/portage-utils’.

For Debian-based systems python-apt package must be installed on targeted hosts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's not ideal.

Copy link
Contributor Author

@diraol diraol Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought so....

So should we move with this PR? Or any other suggestion?


- name: Set version fact
set_fact:
postgresql_version: "{{ __postgresql_version_query_result.stdout.split('+') | first }}"
postgresql_version: "{{ __postgresql_version_query_result.stdout.split('+') | first | string }}"
when: postgresql_version is not defined
2 changes: 1 addition & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
check_mode: true
changed_when: __postgresql_include_dir_result is not changed # yeah...
register: __postgresql_include_dir_result
when: postgresql_version is version('9.3', '>=')
when: postgresql_version is version("9.3", '>=')

- name: Set conf.d include in postgresql.conf
lineinfile:
Expand Down