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. Ansible刚安装完后执行

    2024-07-17 21:54:02       47 阅读
  2. ansible提示 python 的问题及解决

    2024-07-17 21:54:02       27 阅读
  3. ansible--‘when‘ is not a valid attribute for a Play

    2024-07-17 21:54:02       25 阅读
  4. IDEA

    2024-07-17 21:54:02       57 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-17 21:54:02       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-17 21:54:02       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-17 21:54:02       57 阅读
  4. Python语言-面向对象

    2024-07-17 21:54:02       68 阅读

热门阅读

  1. [C/C++入门][for]24、菲波那契数列

    2024-07-17 21:54:02       25 阅读
  2. Linux C++ 060-设计模式之单例模式

    2024-07-17 21:54:02       21 阅读
  3. 使用axios实现vue web前端无痕刷新

    2024-07-17 21:54:02       23 阅读
  4. 调试和测试PER语言代码的最佳实践

    2024-07-17 21:54:02       20 阅读
  5. 不同行业的私域引流策略有何差异?

    2024-07-17 21:54:02       21 阅读
  6. 算法训练营day72

    2024-07-17 21:54:02       23 阅读
  7. 第二章:pod-运行于kubernetes中的容器

    2024-07-17 21:54:02       17 阅读
  8. 昇思25天学习打卡营第25天|SSD目标检测

    2024-07-17 21:54:02       20 阅读
  9. 怎么选择适合自己的酱香白酒?

    2024-07-17 21:54:02       19 阅读
  10. UDP协议

    UDP协议

    2024-07-17 21:54:02      22 阅读
  11. D365 Fraud Protection Account Protection部署方案

    2024-07-17 21:54:02       25 阅读
  12. 解决数据卷root权限问题的Docker科研向实践思路

    2024-07-17 21:54:02       24 阅读