Ansible:`RequirementParseError`将变量提供给`pip:name = pkg version =“{{v}}”`

时间:2016-01-21 02:29:11

标签: ansible ansible-playbook

当我担任这个角色时:

# playbooks/roles/ansible/tasks/main.yml
- name: Install Ansible
  pip:
    state: present
    name: ansible
    version: "{{ ansible_version }}"

# playbooks/roles/ansible/defaults/main.yml
ansible_version: 1.9.4

运行ansible-playbook版本1.9.4或2.0.0.2时出现此错误:

TASK: [ansible | Install Ansible] *********************************************
failed: [localhost] => {"cmd": "/usr/local/bin/pip install ansible=={'major': 1, 'full': '1.9.4', 'string': '1.9.4\\n  configured module search path = None', 'minor': 9, 'revision': 4}", "failed": true}
msg:
:stderr: Invalid requirement: 'ansible=={major:'
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 73, in __init__
    req = pkg_resources.Requirement.parse(req)
  File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 3036, in parse
    req, = parse_requirements(s)
  File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2980, in parse_requirements
    "version spec")
  File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/pkg_resources/__init__.py", line 2945, in scan_list
    raise RequirementParseError(msg, line, "at", line[p:])
RequirementParseError: Expected version spec in ansible=={major: at =={major:

这是剧本:

- name: Install Sensu
  serial: "100%"
  hosts: all
  sudo: yes

  roles:
    - role: "ansible-pull"
      server_type: "sensu"
      ansible_version: "2"

ansible-pull角色取决于ansible中的meta/main.yml角色。

在这种情况下,我是否错误地注入了变量?在依赖ansible-pull卷中设置变量是否存在问题,而不是直接在ansible角色中设置?

1 个答案:

答案 0 :(得分:2)

事实证明ansible_version是由Ansible设定的神奇变量。

谁知道?

使用任意不同但未使用的变量名称可以解决问题。