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

omit follows improper beheviour for run_once #223

Closed
palansher opened this issue Feb 21, 2025 · 5 comments · Fixed by #224
Closed

omit follows improper beheviour for run_once #223

palansher opened this issue Feb 21, 2025 · 5 comments · Fixed by #224
Labels
bug Something isn't working

Comments

@palansher
Copy link

Hello!

Thank you for inspiration by this role!

This code:

 - name: Install packages from URL/path (Debian)
      ansible.builtin.apt:
        deb: '{{ _community_sops_install_system_package_deb_actual }}'
        allow_downgrade: '{{ true if _community_sops_install_allow_downgrade and sops_version != "latest" else omit }}'
      become: '{{ sops_become_on_install }}'
      delegate_to: '{{ "localhost" if sops_install_on_localhost else omit }}'
      run_once: '{{ sops_install_on_localhost or omit }}'
      when: _community_sops_install_system_package_deb_actual is string

follows to skip all hosts in play except first one, when sops_install_on_localhost=false

I found that it is due
run_once: '{{ sops_install_on_localhost or omit }}' reacts for omit strange way (as true)

This changed code is working as expected:

- name: Install packages from URL/path (Debian)
  when: _sops_install_system_package_deb_actual is string
  ansible.builtin.apt:
    deb: "{{ _sops_install_system_package_deb_actual }}"
    allow_downgrade: "{{ true if _sops_install_allow_downgrade and sops_install_version != 'latest' else omit }}"
  become: true
  delegate_to: "{{ 'localhost' if sops_install_on_localhost else omit }}"
  run_once: "{{ (sops_install_on_localhost | d(false, true)) | ternary(true, false) }}"

Ubuntu 22.04.5 LTS

ansible [core 2.17.3]
  config file = /home/vp/code/swarm-ci/ansible.cfg
  configured module search path = ['/home/vp/ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/vp/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/vp/ansible/collections:/usr/share/ansible/collections
  executable location = /home/vp/.local/bin/ansible
  python version = 3.10.12 (main, Jan 17 2025, 14:35:34) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.0.3
  libyaml = True
@felixfontein felixfontein added the bug Something isn't working label Feb 21, 2025
@felixfontein
Copy link
Collaborator

Thanks for reporting this!

Can you give a concrete example how you're calling the community.sops.install role to trigger this problem? I cannot reproduce any problem.

@felixfontein
Copy link
Collaborator

@palansher ping!

@palansher
Copy link
Author

@felixfontein
Excuse me I missed your question.

Now I made my role, based on yours and I calls it:

- name: Install SOPS
      tags: sops
      ansible.builtin.include_role:
        name: sops_install
        apply:
          tags: sops

Before that I called your role same way:

- name: Install SOPS
      tags: sops
      ansible.builtin.include_role:
        name: community.sops.install
        apply:
          tags: sops

There was no problem with community.sops.install if I added:
sops_install_on_localhost=true (only one host involved)

But with sops_install_on_localhost=false there were 3 hosts in play, and two of them were skipped.
It is pity I kept no ansible logs that time.

@felixfontein
Copy link
Collaborator

Ah, now I see what your problem is. Looks like omit still doesn't work for run_once (ansible/ansible#80382 (comment)). {{ sops_install_on_localhost }} will also do the job, since sops_install_on_localhost should be a boolean. I guess I'll change to that...

@felixfontein
Copy link
Collaborator

#224 should fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants