尝试使用变量回显一些东西时的Ansible问题

时间:2016-10-19 12:39:30

标签: ansible

当我尝试生成带有回声的curl请求部分时,我有一个Ansible任务,稍后将在curl命令中使用。任务如下所示:

  - name: Generate requestcode
shell: echo  '{ title: '{{get_hostname.stdout}}', key: '{{ssh_pu_key.stdout}}' }'
debug: msg: { title: '{get_hostname.stdout}'}
register: curl_request

我尝试运行代码时遇到的错误如下:

ERROR! Syntax Error while loading YAML.


The error appears to have been in '/root/wifirush.yml': line 54, column 26, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  - name: Generate requestcode
    shell: echo  '{ title: '{{get_hostname.stdout}}', key: '{{ssh_pu_key.stdout}}' }'
                         ^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes.  Always quote template expression brackets when they
start a value. For instance:

    with_items:
      - {{ foo }}

Should be written as:

    with_items:
      - "{{ foo }}"

有任何建议如何使这项工作?

1 个答案:

答案 0 :(得分:2)

使用:

shell: echo  "{ title{{ ":" }} '{{get_hostname.stdout}}', key {{ ":" }} '{{ssh_pu_key.stdout}}' }"