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

APT repository setup fails on non-LSB system #26

Open
ahmarq opened this issue Feb 2, 2023 · 1 comment
Open

APT repository setup fails on non-LSB system #26

ahmarq opened this issue Feb 2, 2023 · 1 comment

Comments

@ahmarq
Copy link

ahmarq commented Feb 2, 2023

ISSUE TYPE
  • Bug Report
ANSIBLE VERSION
ansible [core 2.12.10]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/ahmarq/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/ahmarq/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
  jinja version = 2.11.3
  libyaml = True
CONFIGURATION
CACHE_PLUGIN(/home/ahmarq/monitoring-plays/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/ahmarq/monitoring-plays/ansible.cfg) = /tmp/gather
CACHE_PLUGIN_TIMEOUT(/home/ahmarq/monitoring-plays/ansible.cfg) = 86400
DEFAULT_FORKS(/home/ahmarq/monitoring-plays/ansible.cfg) = 32
DEFAULT_GATHERING(/home/ahmarq/monitoring-plays/ansible.cfg) = smart
DEFAULT_MANAGED_STR(/home/ahmarq/monitoring-plays/ansible.cfg) = Warning: File is managed by Ansible [https://github.com/adfinis-sygroup/ansible-roles]
DEFAULT_ROLES_PATH(/home/ahmarq/monitoring-plays/ansible.cfg) = ['/home/ahmarq/monitoring-plays/adfinis-roles']
DEFAULT_VAULT_PASSWORD_FILE(/home/ahmarq/monitoring-plays/ansible.cfg) = /home/ahmarq/monitoring-plays/vault-pass
RETRY_FILES_ENABLED(/home/ahmarq/monitoring-plays/ansible.cfg) = False
OS / ENVIRONMENT
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
SUMMARY

While executing a script to configure icinga apt repository, there was a error:

TASK [adfinis-sygroup.icinga2_agent : configure icinga apt repository] ********************************************************************************************************************************************
fatal: [example.host.com]: FAILED! => {"msg": "The conditional check '(ansible_lsb.id != 'Univention' or ansible_distribution_release != 'stretch')' failed. The error was: error while evaluating conditional ((ansible_lsb.id != 'Univention' or ansible_distribution_release != 'stretch')): 'dict object' has no attribute 'id'\n\nThe error appears to be in '/home/ahmarq/monitoring-plays/adfinis-roles/adfinis-sygroup.icinga2_agent/tasks/installation.yml': line 38, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: configure icinga apt repository\n  ^ here\n"}

Here is the line, which is located in the script:

- name: configure icinga apt repository
  apt_repository:
    repo: '{{ icinga2_agent_apt.repo }}'
    state: present
  when:
    - ansible_os_family == 'Debian'
    - (ansible_lsb.id != 'Univention' or ansible_distribution_release != 'stretch')
  notify: update package repository

The variable ansible_lsb.id does not exist on the affected system.

STEPS TO REPRODUCE

Apply role for a debian-based system.

EXPECTED RESULTS

I expect that the script will run successfully.

ACTUAL RESULTS

I executed the script and it didn't do it's job.

@martinwe-adfinis
Copy link

martinwe-adfinis commented Feb 2, 2023

Hey, thanks for reporting this issue!

Looks like the role blindly assumes an LSB system and ansible_lsb being populated. We should probably use Ansible's built-in OS detection mechanism instead (with ansible_facts.distribution or ansible_distribution).

Something like this could work:

     state: present
   when:
     - ansible_os_family == 'Debian'
-    - (ansible_lsb.id != 'Univention' or ansible_distribution_release != 'stretch')
+    - (ansible_distribution != 'Univention' or ansible_distribution_release != 'stretch')
   notify: update package repository

But we'd need to test this on Univention systems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants