ansible报错--‘when‘ is not a valid attribute for a Play


```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


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值