【问题标题】:Error in launching ansible playbook with roles使用角色启动 ansible playbook 时出错
【发布时间】:2019-11-20 22:37:28
【问题描述】:

尝试做剧本:

- hosts: win
  gather_facts: no
  roles: 
    - update_win

update_win mail.yml:

- name: Create Auto_deploy_temp folder on remoter host
  win_file:
    path: {{ disk }}\Auto_deploy_temp
    state: directory

和组变量文件win.yml中的变量:

disk: 'c:'

但要出去:

ERROR! Syntax Error while loading YAML.
  did not find expected key

The error appears to be in '/etc/ansible/roles/update_win/tasks/main.yml': line 3, column 19, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  win_file:
  path: {{ disk }}\Auto_deploy_temp
                  ^ 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 }}"

can u help me with this issue?

P.S.:之前我已经发布了一些类似的代码,但是路径表达式的开头没有变量,只有结尾

【问题讨论】:

    标签: ansible roles


    【解决方案1】:

    请提供路径:“{{磁盘}}\Auto_deploy_temp”

    更新
    创建一个新 var 作为 path_dir:\Auto_deploy_temp,然后使用
    路径:“{{磁盘}}{{path_dir}}”

    路径:“{{磁盘}}\\Auto_deploy_temp”

    【讨论】:

    • 还是一样的:错误!加载 YAML 时出现语法错误。发现未知转义字符错误似乎在“/etc/ansible/roles/update_win/tasks/main.yml”中:第 3 行,第 22 列,但可能在文件中的其他位置,具体取决于确切的语法问题。
    • 可能是 vars 有问题,而不是语法问题
    • 请尝试将 Auto_deploy_temp 存储为变量路径:Auto_deploy_temp,然后使用路径:“{{ disk }}\{{path}}”或尝试直接给出路径一次。路径:C:\Auto_deploy_temp
    • "{{ disk }}\{{ auto_deploy_folder }}" - 在这种情况下它不起作用,但是当我创建变量 auto_deploy_folder = \Auto_deploy_temp - 在那种情况下它是“{{ disk }}{{ auto_deploy_folder }}”,没关系。非常感谢!但是你能告诉我,代码的哪一部分有错误,为什么?是 vars 的错误还是什么?
    • 我觉得是引号的问题。或者可能是因为 (反斜杠) ansible 认为是转义字符。
    【解决方案2】:

    转义'\'

    win_file:
    path: {{ disk }}\\Auto_deploy_temp
    

    【讨论】:

      猜你喜欢
      • 2018-02-10
      • 1970-01-01
      • 1970-01-01
      • 2019-03-30
      • 1970-01-01
      • 1970-01-01
      • 2016-06-27
      • 2022-07-19
      • 2016-08-25
      相关资源
      最近更新 更多