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

Version check fails #115

Closed
tuxpeople opened this issue May 10, 2021 · 10 comments
Closed

Version check fails #115

tuxpeople opened this issue May 10, 2021 · 10 comments

Comments

@tuxpeople
Copy link

tuxpeople commented May 10, 2021

Summary

Version check fails

Issue Type

  • Bug Report

Controller Environment and Configuration

Error

TASK [xanmanning.k3s : Check that k3s_release_version >= 1.19.3] ***************************************************************************************************************************************************************************
fatal: [monitoring]: FAILED! =>
  msg: 'The conditional check ''(k3s_release_version | replace(''v'', '''')) is version_compare(k3s_min_version, ''>='')'' failed. The error was: Version comparison: ''<'' not supported between instances of ''str'' and ''int'''

Role version:

- downloading role 'k3s', owned by xanmanning
- downloading role from https://github.com/PyratLabs/ansible-role-k3s/archive/v2.8.5.tar.gz
- extracting xanmanning.k3s to /Users/tdeutsch/.ansible/roles/xanmanning.k3s
- xanmanning.k3s (v2.8.5) was installed successfully

Ansible version:

$ ansible --version
ansible 2.10.8
  config file = /Users/tdeutsch/git/ansible-sky/ansible.cfg
  configured module search path = ['/Users/tdeutsch/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.9.4 (default, Apr  5 2021, 01:50:46) [Clang 12.0.0 (clang-1200.0.32.29)]

Issue-Dump (no idea why this shows another error):

# Begin ANSIBLE VERSION
ansible 2.10.8
  config file = None
  configured module search path = ['/Users/tdeutsch/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.9.4 (default, Apr  5 2021, 01:50:46) [Clang 12.0.0 (clang-1200.0.32.29)]
# End ANSIBLE VERSION

# Begin ANSIBLE CONFIG
ANSIBLE_NOCOWS(env: ANSIBLE_NOCOWS) = True
# End ANSIBLE CONFIG

# Begin ANSIBLE ROLES
# /Users/tdeutsch/.ansible/roles
- elliotweiser.osx-command-line-tools, 2.3.0
- atosatto.minio, v1.1.0
- ansible-wpa_supplicant-role, (unknown version)
- geerlingguy.nfs, 2.0.0
- geerlingguy.ansible, 2.1.0
- jnv.unattended-upgrades, v1.11.0
- oasis_roles.rhsm, 2.0.0
- frzk.chrony, master
- linux-system-roles.firewall, 0.1.1
- geerlingguy.nodejs, 5.1.1
- geerlingguy.docker, 3.1.2
- oasis_roles.firewalld, master
- geerlingguy.munin, 1.3.1
- geerlingguy.awx, 2.0.0
- geerlingguy.repo-epel, 3.0.0
- ansible-config-interfaces, (unknown version)
- arillso.restic, 0.3.0
- ansible-kvm, (unknown version)
- geerlingguy.backup, 1.2.2
- agaffney.synology_dsm, master
- oasis_roles.satellite, master
- geerlingguy.munin-node, 1.3.0
- geerlingguy.pip, 2.0.0
- ansible-role-lm-sensors, (unknown version)
- geerlingguy.homebrew, 3.1.0
- feffi.macos-defaults, (unknown version)
- oasis_roles.hostname, master
- geerlingguy.git, 3.0.0
- geerlingguy.security, 2.0.1
- feffi.macos-softwareupdate, (unknown version)
- dj-wasabi.telegraf, 0.13.2
- xanmanning.k3s, v2.8.5
- linux-system-roles.cockpit, 0.3.1
# End ANSIBLE ROLES

# Begin PLAY HOSTS
["monitoring"]
# End PLAY HOSTS

# Begin K3S ROLE CONFIG
## monitoring
k3s_install_hard_links: true
k3s_build_cluster: false
k3s_check_cgroup_option: {"cmd": ["grep", "-E", "^cpuset\\s+.*\\s+1$", "/proc/cgroups"], "stdout": "cpuset\t7\t1\t1", "stderr": "", "rc": 0, "start": "2021-05-10 11:31:50.357822", "end": "2021-05-10 11:31:50.360109", "delta": "0:00:00.002287", "changed": false, "stdout_lines": ["cpuset\t7\t1\t1"], "stderr_lines": [], "failed": false, "failed_when_result": false}

# End K3S ROLE CONFIG

# Begin K3S RUNTIME CONFIG
## monitoring
# End K3S RUNTIME CONFIG

Steps to Reproduce

- hosts: k3s_nodes
  roles:
    - { role: xanmanning.k3s, k3s_release_version: stable }

Other vars from group_vars:

k3s_install_hard_links: true
k3s_build_cluster: false

Expected Result

Installing latest k3s

Actual Result

TASK [xanmanning.k3s : Check that k3s_release_version >= 1.19.3] ***************************************************************************************************************************************************************************
fatal: [monitoring]: FAILED! =>
  msg: 'The conditional check ''(k3s_release_version | replace(''v'', '''')) is version_compare(k3s_min_version, ''>='')'' failed. The error was: Version comparison: ''<'' not supported between instances of ''str'' and ''int'''
@tuxpeople
Copy link
Author

hmm... I can reproduce it with 5 different Linuxes:

TASK [xanmanning.k3s : Check that k3s_release_version >= 1.19.3] ***************************************************************************************************************************************************************************
fatal: [monitoring]: FAILED! =>
  msg: 'The conditional check ''(k3s_release_version | replace(''v'', '''')) is version_compare(k3s_min_version, ''>='')'' failed. The error was: Version comparison: ''<'' not supported between instances of ''str'' and ''int'''
fatal: [monitoring1]: FAILED! =>
  msg: 'The conditional check ''(k3s_release_version | replace(''v'', '''')) is version_compare(k3s_min_version, ''>='')'' failed. The error was: Version comparison: ''<'' not supported between instances of ''str'' and ''int'''
fatal: [monitoring2]: FAILED! =>
  msg: 'The conditional check ''(k3s_release_version | replace(''v'', '''')) is version_compare(k3s_min_version, ''>='')'' failed. The error was: Version comparison: ''<'' not supported between instances of ''str'' and ''int'''
fatal: [monitoring3]: FAILED! =>
  msg: 'The conditional check ''(k3s_release_version | replace(''v'', '''')) is version_compare(k3s_min_version, ''>='')'' failed. The error was: Version comparison: ''<'' not supported between instances of ''str'' and ''int'''
fatal: [monitoring4]: FAILED! =>
  msg: 'The conditional check ''(k3s_release_version | replace(''v'', '''')) is version_compare(k3s_min_version, ''>='')'' failed. The error was: Version comparison: ''<'' not supported between instances of ''str'' and ''int'''
  • CentOS 7
  • CentOS 8
  • OpenSUSE Leap 15.2
  • Ubuntu 18.04 LTS (Bionic Beaver)
  • Ubuntu 20.04 LTS (Focal Fossa)

Therefore I think something is missing, probably on the Ansible Controller. Your requirements only listens Ansible itself. Is there any "special" python lib necessary? Or ist it maybe something in my ansible.cfg? It looks like this:

[defaults]
forks = 20

nocows = True

gathering = smart
fact_caching = jsonfile
fact_caching_connection = .cache/facts
fact_caching_timeout = 86400

retry_files_enabled = False
roles_path = ~/.ansible/roles:roles:/etc/ansible/roles

# Use the YAML callback plugin.
stdout_callback = yaml
# Don't use the stdout_callback when running ad-hoc commands. e.g: ansible -m setup <host>
bin_ansible_callbacks = False

# don't automatically convert "false" string to bool, use |bool filter if required.
conditional_bare_variables = False

[privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=False

[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
pipelining = true

@tuxpeople
Copy link
Author

tuxpeople commented May 15, 2021

I just came across this: ansible/ansible#70014 (comment)

I use Python 3. Are your tests running with Python 2?

If I use Python 2 on the Controller, it works:

TASK [xanmanning.k3s : Check that k3s_release_version >= 1.19.3] ***************************************************************************************************************************************************************************
ok: [monitoring] => changed=false
  msg: stable is supported by this role.

Tested like this:

python2 /usr/local/bin/ansible-playbook -i inventories/sky.list -l monitoring plays/k3snodes.yml

Doing so, I'm ending up here:

TASK [xanmanning.k3s : Ensure the k3s hashsum is downloaded] *******************************************************************************************************************************************************************************
fatal: [monitoring]: FAILED! => changed=false
  cache_control: no-cache
  connection: close
  content: Not Found
  content_length: '9'
  content_security_policy: default-src 'none'; base-uri 'self'; connect-src 'self'; form-action 'self'; img-src 'self' data:; script-src 'self'; style-src 'unsafe-inline'
  content_type: text/plain; charset=utf-8
  date: Sat, 15 May 2021 15:33:22 GMT
  elapsed: 0
  expect_ct: max-age=2592000, report-uri="https://api.github.com/_private/browser/errors"
  msg: 'Status code was 404 and not [200]: HTTP Error 404: Not Found'
  permissions_policy: interest-cohort=()
  redirected: false
  referrer_policy: no-referrer-when-downgrade
  server: GitHub.com
  status: 404
  strict_transport_security: max-age=31536000; includeSubdomains; preload
  url: https://github.com/k3s-io/k3s/releases/download/stable/sha256sum-amd64.txt
  vary: X-PJAX, Accept-Encoding, Accept, X-Requested-With
  x_content_type_options: nosniff
  x_frame_options: deny
  x_github_request_id: CF0E:1F78:17AC7E7:187606F:609FE9C2
  x_xss_protection: '0'

Which is also a version issue (looks like "stable" should be replaced by the actual version). And for me it looks like the role knows the actual release:

TASK [xanmanning.k3s : Ensure the release version is set as a fact] ************************************************************************************************************************************************************************
ok: [monitoring] => (item={u'latest': u'v1.20.6+k3s1', u'type': u'channel', u'name': u'stable', u'links': {u'self': u'https://update.k3s.io/v1-release/channels/stable'}, u'id': u'stable'})
skipping: [monitoring] => (item={u'links': {u'self': u'https://update.k3s.io/v1-release/channels/latest'}, u'latestRegexp': u'.*', u'excludeRegexp': u'^[^+]+-', u'name': u'latest', u'type': u'channel', u'id': u'latest', u'latest': u'v1.21.0+k3s1'})
skipping: [monitoring] => (item={u'name': u'testing', u'links': {u'self': u'https://update.k3s.io/v1-release/channels/testing'}, u'type': u'channel', u'id': u'testing', u'latestRegexp': u'-(alpha|beta|rc)', u'latest': u'v1.21.1-rc1+k3s1'})
skipping: [monitoring] => (item={u'links': {u'self': u'https://update.k3s.io/v1-release/channels/v1.16'}, u'latestRegexp': u'v1\\.16\\..*', u'excludeRegexp': u'^[^+]+-', u'name': u'v1.16', u'type': u'channel', u'id': u'v1.16', u'latest': u'v1.16.15+k3s1'})
skipping: [monitoring] => (item={u'name': u'v1.16-testing', u'links': {u'self': u'https://update.k3s.io/v1-release/channels/v1.16-testing'}, u'type': u'channel', u'id': u'v1.16-testing', u'latestRegexp': u'v1\\.16\\.[0-9]*-(alpha|beta|rc)', u'latest': u'v1.16.14-rc1+k3s1'})
skipping: [monitoring] => (item={u'links': {u'self': u'https://update.k3s.io/v1-release/channels/v1.17'}, u'latestRegexp': u'v1\\.17\\..*', u'excludeRegexp': u'^[^+]+-', u'name': u'v1.17', u'type': u'channel', u'id': u'v1.17', u'latest': u'v1.17.17+k3s1'})
skipping: [monitoring] => (item={u'name': u'v1.17-testing', u'links': {u'self': u'https://update.k3s.io/v1-release/channels/v1.17-testing'}, u'type': u'channel', u'id': u'v1.17-testing', u'latestRegexp': u'v1\\.17\\.[0-9]*-(alpha|beta|rc)', u'latest': u'v1.17.17-rc1+k3s1'})
skipping: [monitoring] => (item={u'links': {u'self': u'https://update.k3s.io/v1-release/channels/v1.18'}, u'latestRegexp': u'v1\\.18\\..*', u'excludeRegexp': u'^[^+]+-', u'name': u'v1.18', u'type': u'channel', u'id': u'v1.18', u'latest': u'v1.18.18+k3s1'})
skipping: [monitoring] => (item={u'name': u'v1.18-testing', u'links': {u'self': u'https://update.k3s.io/v1-release/channels/v1.18-testing'}, u'type': u'channel', u'id': u'v1.18-testing', u'latestRegexp': u'v1\\.18\\.[0-9]*-(alpha|beta|rc)', u'latest': u'v1.18.19-rc1+k3s1'})
skipping: [monitoring] => (item={u'links': {u'self': u'https://update.k3s.io/v1-release/channels/v1.19'}, u'latestRegexp': u'v1\\.19\\..*', u'excludeRegexp': u'^[^+]+-', u'name': u'v1.19', u'type': u'channel', u'id': u'v1.19', u'latest': u'v1.19.10+k3s1'})
skipping: [monitoring] => (item={u'links': {u'self': u'https://update.k3s.io/v1-release/channels/v1.20'}, u'latestRegexp': u'v1\\.20\\..*', u'excludeRegexp': u'^[^+]+-', u'name': u'v1.20', u'type': u'channel', u'id': u'v1.20', u'latest': u'v1.20.6+k3s1'})

What I tried now was removing the "stable" from the vars:

Old:

- hosts: k3s_nodes
  roles:
    - { role: xanmanning.k3s, k3s_release_version: stable }

New:

- hosts: k3s_nodes
  roles:
    - { role: xanmanning.k3s }

With the new one it works. But I understood the readme that I can set the version to "stable". Was I wrong?

@xanmanning
Copy link
Member

Interesting, my testing is all done in Python 3 (v3.9.5): https://github.com/PyratLabs/ansible-role-k3s/runs/2577182899?check_suite_focus=true#step:3:5

Yes, "Stable" should be usable - that is in fact the default (not in defaults, but the default channel that is selected when k3s_release_version is false)

@xanmanning
Copy link
Member

Added some debugs around the task:

- debug:
    var: k3s_release_version

- debug:
    msg: "{{ k3s_release_version | type_debug }}"

#- fail:

- name: "Check that k3s_release_version >= {{ k3s_min_version }}"
  ansible.builtin.assert:
    that:
      - (k3s_release_version | replace('v', '')) is version_compare(k3s_min_version, '>=')
    success_msg: "{{ k3s_release_version }} is supported by this role."
    fail_msg: "{{ k3s_release_version }} is not supported by this role, please use xanmanning.k3s v1.x."

- fail:

Molecule tests pass

Screenshot from 2021-05-15 17-54-52

Vagrant tests fail

Screenshot from 2021-05-15 17-55-32

Stinks of this issue again ansible/ansible#71824 - it meant that facts were not being redefined properly, in some versions you could change the fact version - in others you could not.

@xanmanning
Copy link
Member

xanmanning commented May 15, 2021

Found it.

This is broken (it used to work in earlier Ansible releases!):

Playbook

---

- hosts: k3s
  become: true
  roles:
    - { role: xanmanning.k3s, k3s_release_version: stable }

This works:

Inventory

---

k3s:
  vars:
    k3s_release_version: stable
    # And so on...

Playbook

---

- hosts: k3s
  become: true
  roles:
    - { role: xanmanning.k3s }

This work as well

Playbook

---

- hosts: k3s
  become: true
  vars:
    k3s_release_version: stable
  tasks:
    - name: Run K3S role
      include_role:
        name: xanmanning.k3s

This also works

Playbook

---

- hosts: k3s
  become: true
  vars:
    k3s_release_version: stable
  roles:
    - role: xanmanning.k3s

You can test this works by changing the variable to "latest" and you will get the v1.21 release rather than v1.20 (at time of writing)

@xanmanning
Copy link
Member

I'll update documentation to use the more "modern" style of defining this, but it looks like changing ways in which roles can be called by Ansible. I'm surprised that this isn't picked up by linting.

@tuxpeople
Copy link
Author

Thanks a lot for your effort!

I stumbled (by accident) on another weird issue. In my tests above, I used k3s_build_cluster: false to get multiple clusters. I ended up with this:

TASK [xanmanning.k3s : Ensure ansible_host is mapped to inventory_hostname] ****************************************************************************************************************************************************************
fatal: [monitoring]: FAILED! =>
  msg: |-
    The task includes an option with an undefined variable. The error was: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'k3s_control_node'

    The error appears to be in '/Users/tdeutsch/.ansible/roles/xanmanning.k3s/tasks/build/preconfigure-k3s.yml': line 64, column 3, but may
    be elsewhere in the file depending on the exact syntax problem.

    The offending line appears to be:


    - name: Ensure ansible_host is mapped to inventory_hostname
      ^ here
fatal: [monitoring1]: FAILED! =>
  msg: |-
    The task includes an option with an undefined variable. The error was: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'k3s_control_node'

    The error appears to be in '/Users/tdeutsch/.ansible/roles/xanmanning.k3s/tasks/build/preconfigure-k3s.yml': line 64, column 3, but may
    be elsewhere in the file depending on the exact syntax problem.

    The offending line appears to be:


    - name: Ensure ansible_host is mapped to inventory_hostname
      ^ here
fatal: [monitoring3]: FAILED! =>
  msg: |-
    The task includes an option with an undefined variable. The error was: 'ansible.vars.hostvars.HostVarsVars object' has no attribute 'k3s_control_node'

    The error appears to be in '/Users/tdeutsch/.ansible/roles/xanmanning.k3s/tasks/build/preconfigure-k3s.yml': line 64, column 3, but may
    be elsewhere in the file depending on the exact syntax problem.

    The offending line appears to be:


    - name: Ensure ansible_host is mapped to inventory_hostname
      ^ here

The weird thing is: as far as I tested, it only happens if you do multiple hosts at once with the same playbook and use k3s_build_cluster: false but only if at least one of the hosts get "lost" earlier in the run. In my case, one of the hosts hasn't cgroups enabled, so it failed the check for them. Therefore, not all hosts which started the run came to the Ensure ansible_host is mapped to inventory_hostname] check and it failed. If I remove the particular host from the run, it works. I have no idea why....

@xanmanning
Copy link
Member

Possibly fact caching / gathering ?

@tuxpeople
Copy link
Author

Maybe, yes. I'll figure it out.

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