我刚刚在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
小空间会给剧本带来麻烦吗?
答案 0 :(得分:3)
小空间会给剧本带来麻烦吗?
是。 Playbook以YAML编写。 YAML对缩进非常严格,因为你通常会切换上下文&#34;不同的缩进。
答案 1 :(得分:1)
以下是使用YAML语法的一些基本规则。
.yml
的所有文件。