安斯布勒环路错误



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

- 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 在运行剧本时会抛出以下错误。

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 2.5,因为只有该版本支持循环关键字。

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

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

yum install epel-release

最新更新