Ansible 易变回路误差
我最近开始写剧本。以下是我的任务:Ansible 易变回路误差,ansible,ansible-2.x,ansible-inventory,ansible-template,Ansible,Ansible 2.x,Ansible Inventory,Ansible Template,我最近开始写剧本。以下是我的任务: - name: apache templates template: src: "{{ item.templatename }}" dest: /opt/apache/default/"{{ item.config }}" loop: - { templatename: 'apache_webconf.j2', config: 'web.conf' } - { templatename: 'apache_sites
- 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'>
错误!字段“loop”应该是字符串类型,但是传入的数据结构是字符串类型
我找到了解决方案。我们所要做的就是升级到ansible 2.5,因为只有该版本才支持循环关键字。另一种选择是将“循环”替换为“with_items”。我需要这样做,因为出于某种原因,我的机器无法将ansible升级到至少v2.5(其中支持循环关键字)。我的ansible是v2.4版,到目前为止,它与关键字“with_items”的作用相同。如果您在CentOS上使用ansible,我发现您需要安装epel版本才能通过2.4.x。这将允许您现在使用循环而不会抛出此错误
yum install epel-release
这对我也有用。