prometheus-community / ansible

Ansible Collection for Prometheus
https://prometheus-community.github.io/ansible/
Apache License 2.0
328 stars 116 forks source link

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

Open littlecxm opened 3 weeks ago

littlecxm commented 3 weeks ago

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