【问题标题】:ERROR! Unexpected Exception, this is probably a bug: unhashable type: 'AnsibleMapping'错误!意外异常,这可能是一个错误:unhashable type: 'AnsibleMapping'
【发布时间】:2020-02-14 21:46:40
【问题描述】:

我一直在尝试使用 Ansible 进行模板的第一次试用,但我被以下异常阻止了。据我所知,我认为我已经很好地维护了缩进并且还验证了 yml 文件。我不知道从哪里开始,请帮助!下面是 yml 文件,后面是我在运行 playbook 后看到的异常。


---

- name: run these tasks on the host
  hosts:
    testhost:
    testhost1: "172.16.201.163"
  vars:
    ansible_port: 22
  tasks:

    - name: Templating
      template:
        dest: /etc/my_test.conf
        owner: root
        src: my_test.j2
      become: true

运行的输出

ERROR! Unexpected Exception, this is probably a bug: unhashable type: 'AnsibleMapping'
the full traceback was:

Traceback (most recent call last):
  File "/usr/local/bin/ansible-playbook", line 118, in <module>
    exit_code = cli.run()
  File "/usr/local/Cellar/ansible/2.7.9/libexec/lib/python3.7/site-packages/ansible/cli/playbook.py", line 122, in run
    results = pbex.run()
  File "/usr/local/Cellar/ansible/2.7.9/libexec/lib/python3.7/site-packages/ansible/executor/playbook_executor.py", line 106, in run
    all_vars = self._variable_manager.get_vars(play=play)
  File "/usr/local/Cellar/ansible/2.7.9/libexec/lib/python3.7/site-packages/ansible/vars/manager.py", line 185, in get_vars
    include_delegate_to=include_delegate_to,
  File "/usr/local/Cellar/ansible/2.7.9/libexec/lib/python3.7/site-packages/ansible/vars/manager.py", line 470, in _get_magic_variables
    variables['ansible_play_hosts_all'] = [x.name for x in self._inventory.get_hosts(pattern=pattern, ignore_restrictions=True)]
  File "/usr/local/Cellar/ansible/2.7.9/libexec/lib/python3.7/site-packages/ansible/inventory/manager.py", line 358, in get_hosts
    if pattern_hash not in self._hosts_patterns_cache:
TypeError: unhashable type: 'AnsibleMapping'

【问题讨论】:

  • Ansible 2.7.9 使用 Python3.7。你是怎么安装的?你能发布ansible --version的输出吗?
  • ansible --version ansible 2.7.9 配置文件 = /Users/xxxx/ansible/ansible.cfg 配置模块搜索路径 = ['/Users/xxxx/ansible/library'] ansible python 模块位置= /usr/local/Cellar/ansible/2.7.9/libexec/lib/python3.7/site-packages/ansible 可执行位置 = /usr/local/bin/ansible python 版本 = 3.7.2(默认,2019 年 2 月 12 日, 08:15:36) [Clang 10.0.0 (clang-1000.11.45.5)]
  • @VladimirBotka - 我不记得我是怎么安装的了。
  • @VladimirBotka:你能否为我提出一个行动计划,因为我一直在打这个,你会建议我重新安装 ansible 吗?

标签: ansible devops


【解决方案1】:

您发布的剧本至少有两个问题:

  1. hosts:dict,但不应该是
  2. testhost: 有一个 null

Reading the fine manual 表明hosts: 应该是一个字符串,或者list[str] 但可能不是dict。也许您想要完成的最好通过库存文件或动态库存插件/脚本来实现

【讨论】:

  • 谢谢,它就像一个魅力。我将我的“主机”隔离到一个清单文件中,并使用 playbook.yml 文件中的主机列表来引用清单中的主机,这个有效!我必须在所有远程节点上安装 libselinux-python 包才能“复制”工作,但原来的问题已经解决了。
猜你喜欢
  • 2023-02-06
  • 2018-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-17
  • 2015-03-16
  • 1970-01-01
相关资源
最近更新 更多