```c
[root@mac-vm-temp ~]# ansible-playbook install.yml --syntax-check
ERROR! 'when' is not a valid attribute for a Play
The error appears to be in '/root/install.yml': line 1, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: install tools for compiling native addons from npm
^ here
yml内容:`---
- name: install tools
yum: name=open state=present
~ `
```c
把when条件删除后又报错
```c
[root@mac-vm-temp ~]# ansible-playbook install.yml --syntax-check
ERROR! 'yum' is not a valid attribute for a Play
The error appears to be in '/root/install.yml': line 1, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: install tools for compiling native addons from npm
^ here
怀疑是系统版本或ansible版本版本过低,所以yum模块无法使用,为了验证yum模块的问题,不适用playbook,直接用命令执行
[root@mac-vm-temp ~]# ansible all -m yum -a "name=nginx "
10.0.0.1| SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"msg": "",
"rc": 0,
"results": [
"1:nginx-1.20.1-10.el7.x86_64 providing nginx is already installed"
]
}
基本确认不是yum模块问题导致的,所以还是语法上有问题。
---
- hosts: tan
tasks:
- name: install tools
yum:
name: nginx
state: present
修改后,正常了。
[root@mac-vm-temp ~]# ansible-playbook nginx.yml --syntax-check
playbook: nginx.yml