【问题标题】:Ansible loop errorAnsible 循环错误
【发布时间】:2018-04-05 20:14:45
【问题描述】:

我最近开始编写剧本。以下是我的任务:

- name: apache templates 
  template:
     src: "{{ item.templatename }}"
     dest: /opt/apache/default/"{{ item.config }}"
  loop:
    - { templatename: 'apache_webconf.j2', config: 'web.conf' }
    - { templatename: 'apache_sitesconf.j2',  config: 'sites.conf' }

我在这里想要实现的是 ansible 应该在目的地用 web.conf 替换模板。但是,ansible 在运行 playbook 时会抛出以下错误。

ERROR! The field 'loop' is supposed to be a string type, however the incoming data structure is a <class 'ansible.parsing.yaml.objects.AnsibleSequence'>

【问题讨论】:

    标签: ansible ansible-2.x ansible-inventory ansible-template


    【解决方案1】:

    我找到了解决方案。我们所要做的就是升级到 ansible 2.5,因为只有那个版本支持 loop 关键字。

    【讨论】:

      【解决方案2】:

      另一种选择是将“loop”替换为“with_items”。由于某种原因,我需要这样做,我的机器无法将 ansible 升级到至少 v2.5(支持循环关键字)。我的 ansible 是 v2.4,到目前为止与关键字“with_items”的工作方式相同。

      【讨论】:

        【解决方案3】:

        如果您在 CentOS 上使用 Ansible,我发现您需要安装 epel-release 才能通过 2.4.x。这应该允许您现在使用循环而不会引发此错误。

        yum install epel-release
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-09-14
          • 2015-10-12
          • 1970-01-01
          • 1970-01-01
          • 2015-12-10
          • 2017-06-25
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多