【问题标题】:ANSIBLE:: Could not resolve the syntax in the following yaml fileANSIBLE:: 无法解析以下 yaml 文件中的语法
【发布时间】:2017-02-08 13:34:02
【问题描述】:

我正在学习 ansible,这是我的 YAML 文件。

---# Outline to playbook translation
- hosts: node1
  user: test
  sudo: yes
  gather_facts: no
  tasks:
  - name: date time stamp at start
    raw: /usr/bin/date > /home/test/playbook_start.log
  - name:  install apache web server
    yum: pkg=httpd state=latest
  - name: start the service
    service: name=httd state=restarted
  - name: verify web service is running or not
    command: systemctl status httpd
    register: result
  - debug: var-result
  - name: install client SW telnet
    yum: pkg=telnet state=latest
  - name: install client pkg VIM
    yum: pkg=vim state=latest

我在运行时收到此错误

 ERROR! Syntax Error while loading YAML.


The error appears to have been in '/home/test/Outline/webserver.yml': line 2, column 8, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---# Outline to playbook translation
- hosts: node1
       ^ here

【问题讨论】:

    标签: ansible yaml


    【解决方案1】:

    试试这个文件:

    ---
    # Outline to playbook translation
    - hosts: node1
      user: test
      sudo: yes
      gather_facts: no
      tasks:
      - name: date time stamp at start
        raw: /usr/bin/date > /home/test/playbook_start.log
      - name:  install apache web server
        yum: pkg=httpd state=latest
      - name: start the service
        service: name=httd state=restarted
      - name: verify web service is running or not
        command: systemctl status httpd
        register: result
      - debug: var=result
      - name: install client SW telnet
        yum: pkg=telnet state=latest
      - name: install client pkg VIM
        yum: pkg=vim state=latest
    

    【讨论】:

    • 你说得对,我从回复中删除了这一行(并修复了我个人资料中的文字)。
    【解决方案2】:

    语法错误是因为您没有在文件的第一行从前面的标记中separate the comment指令结束标记---):

    注释必须用空格字符与其他标记分开。

    尝试:

    --- # Outline to playbook translation
    

    【讨论】:

      【解决方案3】:

      要么删除“# Outline to playbook translation”,要么将其放在下一行,或者在 --- 后留一个空格

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-01-28
        • 1970-01-01
        • 2019-01-04
        • 1970-01-01
        • 1970-01-01
        • 2021-08-23
        • 2017-01-14
        • 1970-01-01
        相关资源
        最近更新 更多