【发布时间】:2016-04-18 14:32:50
【问题描述】:
我有一个关于多行和 Ansible 剧本的问题:
我创建了一个非常大的线的剧本,我需要剪掉这条线以便更好地阅读。我该怎么做?
- name: 'Create VM Azure :-P '
shell: if ! grep {{ item }} /tmp/vm_{{ rgName }}; then azure vm create --vm-size {{ groups['item'][vmsize] }} --resource-group {{ rgName }} --name {{ item }} --location {{ location }} --admin-username {{ username }} --ssh-publickey-file {{ sshfile }} --storage-account-name {{ rgName | lower }} --os-type {{ groups['item'][type_os] }} --image-urn {{ image }} --data-disk-size {{ disksize }} --subnet-id {{ subnetid_key }} --nic-names {{ item }}; fi
with_items: groups['test']
我想按照以下方式进行,但是执行剧本时出现了一些错误
- name: 'Create VM Azure :-P '
shell: if ! grep {{ item }} /tmp/vm_{{ rgName }}; then
azure vm create --vm-size {{ groups['item'][vmsize] }}
--resource-group {{ rgName }} --name {{ item }}
--location {{ location }} --admin-username {{ username }}
--ssh-publickey-file {{ sshfile }} --storage-account-name {{ rgName | lower }}
--os-type {{ groups['item'][type_os] }} --image-urn {{ image }}
--data-disk-size {{ disksize }} --subnet-id {{ subnetid_key }}
--nic-names {{ item }}; fi
with_items: groups['test']
错误:
错误!加载 YAML 时出现语法错误。
错误似乎出现在“/home/pvillarruel/docker/azure-ansible/data/playbook.yml”中:第 79 行,第 1 列,但可能 根据确切的语法问题,位于文件中的其他位置。
违规行似乎是:
shell: if ! grep {{ item }} /tmp/vm_{{ rgName }}; then azure vm create --vm-size
{{ groups['item'][vmsize] }} --resource-group {{ rgName }} --name {{ item }}
^ 这里 我们可能是错的,但这个看起来可能是一个问题 缺少引号。总是引用模板表达式括号 开始一个值。例如:
with_items:
- {{ foo }}
应该写成:
with_items:
- "{{ foo }}"
谢谢
【问题讨论】:
标签: yaml ansible ansible-playbook multiline