【发布时间】:2018-07-30 17:27:10
【问题描述】:
我刚刚说过在 Linux 环境下使用 ansible,我真的无法理解 playbook yml 中的语法
例如,我正在编写简单的剧本来安装/卸载软件包。
yum 模块第 5 行的空间很小
工作手册
---
- hosts: test,dev
tasks:
- name: install/uninstall package httpd
yum: name=httpd state=removed
结果
[root@rhel7m100 krishnp]# ansible-playbook package-httpd-installation.yml --check
PLAY [test,dev] **********************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************
ok: [rhel7c1]
ok: [rhel6c2]
ok: [rhel6c1]
TASK [install/uninstall package httpd] ***********************************************************************************************
ok: [rhel6c2]
ok: [rhel6c1]
ok: [rhel7c1]
PLAY RECAP ***************************************************************************************************************************
rhel6c1 : ok=2 changed=0 unreachable=0 failed=0
rhel6c2 : ok=2 changed=0 unreachable=0 failed=0
rhel7c1 : ok=2 changed=0 unreachable=0 failed=0
错误的剧本
---
- hosts: test,dev
tasks:
- name: install/uninstall package httpd
yum: name=httpd state=removed ---> the only difference is the small
space in from of yum command
结果
[root@rhel7m100 krishnp]# ansible-playbook package-httpd-installation.yml --check
ERROR! Syntax Error while loading YAML.
The error appears to have been in '/krishnp/package-httpd-installation.yml': line 5, column 9, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: install/uninstall package httpd
yum: name=httpd state=removed
^ here
enter code hereexception type: <class 'yaml.scanner.ScannerError'>
exception: mapping values are not allowed in this context
in "<unicode string>", line 5, column 9
小空间会给 playbook 运行带来麻烦真的很重要吗?
【问题讨论】:
-
YAML sintax 的主要功能之一是使其易于阅读,标识非常重要,如果您不尊重它,您的剧本就会出现问题......另一个重要建议是使用空格,而不是制表符。
标签: ansible