POSSE: Lydra-Yunohost issue #98: Support ansible check mode
This is my POSSE copy of a Lydra Ansible-Yunohost issue, Support ansible check mode #98.
Request
It would be helpful if these roles would support ansible's “check mode” which is like a dry-run.
Implemented; tested; merge request
The only thing required to support check mode, it seems from my testing, is to set check_mode: false
in data-gathering steps.
I have fixed this in my own git lab fork, and tested it. I have generated a remote merge-request using the standard git request-pull command like this:
$ git request-pull -p HEAD^ https://lab.trax.im/fork/froggit/lydra/yunohost/ansible-yunohost.git support-ansible-check-mode
and here it is:
The following changes since commit 8554279b42db06fb47942cfb3ebf2c08cf71da49:
Merge branch '84-build-create-ansible-galaxy-build-1-1-4' into 'main' (2023-03-14 15:13:14 +0000)
are available in the Git repository at:
https://lab.trax.im/fork/froggit/lydra/yunohost/ansible-yunohost.git support-ansible-check-mode
for you to fetch changes up to 1e63f6c1e1938c93f4bc1ff9a3c0d61f869d0895:
support ansible check mode (2023-04-26 18:59:33 +0100)
----------------------------------------------------------------
Julian Foad (1):
support ansible check mode
roles/ynh_apps/tasks/apps.yml | 1 +
roles/ynh_config/tasks/smtp_relay.yml | 1 +
roles/ynh_setup/tasks/domains.yml | 1 +
roles/ynh_setup/tasks/users.yml | 1 +
4 files changed, 4 insertions(+)
diff --git a/roles/ynh_apps/tasks/apps.yml b/roles/ynh_apps/tasks/apps.yml
index 240a6df..a2f69f6 100644
--- a/roles/ynh_apps/tasks/apps.yml
+++ b/roles/ynh_apps/tasks/apps.yml
@@ -22,6 +22,7 @@
ansible.builtin.command: yunohost app map --output-as json
register: ynh_installed_apps_raw
changed_when: False
+ check_mode: False
tags: apps
- name: Format json of apps
diff --git a/roles/ynh_config/tasks/smtp_relay.yml b/roles/ynh_config/tasks/smtp_relay.yml
index a3f68b3..3ea8ca9 100644
--- a/roles/ynh_config/tasks/smtp_relay.yml
+++ b/roles/ynh_config/tasks/smtp_relay.yml
@@ -23,6 +23,7 @@
"yunohost settings get smtp.relay.{{ item.key }}"
register: _ynh_smtp_current_values
changed_when: false
+ check_mode: false
tags:
- yunohost
- smtp
diff --git a/roles/ynh_setup/tasks/domains.yml b/roles/ynh_setup/tasks/domains.yml
index 02a2368..e8a4d2d 100644
--- a/roles/ynh_setup/tasks/domains.yml
+++ b/roles/ynh_setup/tasks/domains.yml
@@ -22,6 +22,7 @@
ansible.builtin.command: yunohost domain list --output-as json
register: ynh_installed_domains_raw
changed_when: False
+ check_mode: False
tags:
- yunohost
- domains
diff --git a/roles/ynh_setup/tasks/users.yml b/roles/ynh_setup/tasks/users.yml
index 84cbc56..19b1c78 100644
--- a/roles/ynh_setup/tasks/users.yml
+++ b/roles/ynh_setup/tasks/users.yml
@@ -22,6 +22,7 @@
ansible.builtin.command: yunohost user list --output-as json
register: ynh_registered_users_raw
changed_when: False
+ check_mode: False
tags:
- yunohost
- users
You can apply the merge in your local repo, if you accept it, like this:
git pull https://lab.trax.im/fork/froggit/lydra/yunohost/ansible-yunohost.git support-ansible-check-mode
I hope you find this useful. Please let me know if you prefer anything different.
The failure mode of trying to use “check mode” looks like this:
$ ansible-playbook setup-yunohost.yml -C
[...]
TASK [lydra.yunohost.ynh_setup : Create extra domains] *****************************************************************
included: ~/.ansible/collections/ansible_collections/lydra/yunohost/roles/ynh_setup/tasks/domains.yml for example.org
TASK [lydra.yunohost.ynh_setup : Format json of domains] *****************************************************************
fatal: [example.org]: FAILED! =>
msg: |-
the field 'args' has an invalid value ({'ynh_installed_domains': '{{ ynh_installed_domains_raw.stdout | from_json }}'}), and could not be converted to an dict.The error was: Expecting value: line 1 column 1 (char 0)
The error appears to be in '~/.ansible/collections/ansible_collections/lydra/yunohost/roles/ynh_setup/tasks/domains.yml': line 29, column 3,
[...]
The failure is similar for each of the other places addressed in the patch.
Note how the step “List currently installed domains” was missing there. That is because “shell” steps do not normally run in check mode.
With the fix, the corresponding part of the output is like this:
TASK [lydra.yunohost.ynh_setup : Create extra domains] **********************************************************************
included: ~/.ansible/collections/ansible_collections/lydra/yunohost/roles/ynh_setup/tasks/domains.yml for example.org
TASK [lydra.yunohost.ynh_setup : List currently installed domains] **********************************************************************
ok: [example.org] => changed=false
TASK [lydra.yunohost.ynh_setup : Format json of domains] **********************************************************************
ok: [example.org] => changed=false
[...]
and the check-mode run completes successfully.
Follow/Feedback/Contact: RSS feed · Fedi follow this blog: @julian@wrily.foad.me.uk · use the Cactus Comments box above · matrix me · Fedi follow me · email me · julian.foad.me.uk Donate: via Liberapay All posts © Julian Foad and licensed CC-BY-ND except quotes, translations, or where stated otherwise