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

SyntaxError: future feature annotations is not defined in ansible 10 #392

Open
littlecxm opened this issue Jun 28, 2024 · 1 comment
Open

Comments

@littlecxm
Copy link

prometheus_alert_rules cannot work on ansible 10

error output

{
  "ansible_facts": {},
  "changed": false,
  "failed_modules": {
    "ansible.legacy.setup": {
      "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3" },
      "exception": "Traceback (most recent call last):\r\n  File \"/tmp/ansible-tmp-1719571481.4934132-26015-144577512529724/AnsiballZ_setup.py\", line 107, in <module>\r\n    _ansiballz_main()\r\n  File \"/tmp/ansible-tmp-1719571481.4934132-26015-144577512529724/AnsiballZ_setup.py\", line 99, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/tmp/ansible-tmp-1719571481.4934132-26015-144577512529724/AnsiballZ_setup.py\", line 44, in invoke_module\r\n    from ansible.module_utils import basic\r\n  File \"<frozen importlib._bootstrap>\", line 971, in _find_and_load\r\n  File \"<frozen importlib._bootstrap>\", line 951, in _find_and_load_unlocked\r\n  File \"<frozen importlib._bootstrap>\", line 894, in _find_spec\r\n  File \"<frozen importlib._bootstrap_external>\", line 1157, in find_spec\r\n  File \"<frozen importlib._bootstrap_external>\", line 1131, in _get_spec\r\n  File \"<frozen importlib._bootstrap_external>\", line 1112, in _legacy_get_spec\r\n  File \"<frozen importlib._bootstrap>\", line 441, in spec_from_loader\r\n  File \"<frozen importlib._bootstrap_external>\", line 544, in spec_from_file_location\r\n  File \"/tmp/ansible_ansible.legacy.setup_payload_8i4sybqm/ansible_ansible.legacy.setup_payload.zip/ansible/module_utils/basic.py\", line 5\r\nSyntaxError: future feature annotations is not defined\r\n",
      "failed": true,
      "module_stderr": "Shared connection to [hidden] closed.\r\n",
      "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible-tmp-1719571481.4934132-26015-144577512529724/AnsiballZ_setup.py\", line 107, in <module>\r\n    _ansiballz_main()\r\n  File \"/tmp/ansible-tmp-1719571481.4934132-26015-144577512529724/AnsiballZ_setup.py\", line 99, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/tmp/ansible-tmp-1719571481.4934132-26015-144577512529724/AnsiballZ_setup.py\", line 44, in invoke_module\r\n    from ansible.module_utils import basic\r\n  File \"<frozen importlib._bootstrap>\", line 971, in _find_and_load\r\n  File \"<frozen importlib._bootstrap>\", line 951, in _find_and_load_unlocked\r\n  File \"<frozen importlib._bootstrap>\", line 894, in _find_spec\r\n  File \"<frozen importlib._bootstrap_external>\", line 1157, in find_spec\r\n  File \"<frozen importlib._bootstrap_external>\", line 1131, in _get_spec\r\n  File \"<frozen importlib._bootstrap_external>\", line 1112, in _legacy_get_spec\r\n  File \"<frozen importlib._bootstrap>\", line 441, in spec_from_loader\r\n  File \"<frozen importlib._bootstrap_external>\", line 544, in spec_from_file_location\r\n  File \"/tmp/ansible_ansible.legacy.setup_payload_8i4sybqm/ansible_ansible.legacy.setup_payload.zip/ansible/module_utils/basic.py\", line 5\r\nSyntaxError: future feature annotations is not defined\r\n",
      "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
      "rc": 1,
      "warnings": [
        "Platform linux on host [hidden] is using the discovered Python interpreter at /usr/bin/python3, but future installation of another Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible-core/2.17/reference_appendices/interpreter_discovery.html for more information."
      ]
    }
  },
  "msg": "The following modules failed to execute: ansible.legacy.setup\n"
}

my playbook file, just copy from demo

---
- name: Install/Config prometheus
  hosts: [hidden]
  become: true
  roles:
    - prometheus.prometheus.prometheus
  vars:
    # alert rules
    prometheus_alert_rules:
      - alert: InstanceDown
        expr: "up == 0"
        for: 5m
        labels:
          severity: critical
        annotations:
          description: "{% raw %}{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes.{% endraw %}"
          summary: "{% raw %}Instance {{ $labels.instance }} down{% endraw %}"

my local ansible config

[defaults]
collections_path=./.ansible/collections
inventory      =./.ansible/hostsfile
remote_tmp     = /tmp
interpreter_python = auto

and I downgrade ansible to 9 it works well

@docbyte86
Copy link

Wie refer to ansible/ansible#82068 it is regards the python version. Everything lower than 3.7 is not supported

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