【发布时间】:2020-02-11 06:03:56
【问题描述】:
我有一个 ansible 播放文件,它必须执行两个任务,首先在本地机器上获取磁盘使用情况,另一个任务是获取远程机器的磁盘使用情况并在远程机器上安装 apache2。
当我尝试运行文件时,我收到错误 “错误!'sudo' 不是 Play 的有效属性” 当我从 yml 文件中删除 sudo 和 apt 部分时,它运行良好。
我正在使用 ansible 2.9.4。以下是两个剧本文件:
文件运行没有任何错误,
---
-
connection: local
hosts: localhost
name: play1
tasks:
-
command: "df -h"
name: "Find the disk space available"
-
command: "ls -lrt"
name: "List all the files"
-
name: "List All the Files"
register: output
shell: "ls -lrt"
-
debug: var=output.stdout_lines
-
hosts: RemoteMachine1
name: play2
tasks:
- name: "Find the disk space"
command: "df -h"
register: result
- debug: var=result.stdout_lines
文件运行出错:
---
-
connection: local
hosts: localhost
name: play1
tasks:
-
command: "df -h"
name: "Find the disk space available"
-
command: "ls -lrt"
name: "List all the files"
-
name: "List All the Files"
register: output
shell: "ls -lrt"
-
debug: var=output.stdout_lines
-
hosts: RemoteMachine1
name: play2
sudo: yes
tasks:
- name: "Find the disk space"
command: "df -h"
register: result
- name: "Install Apache in the remote machine"
apt: name=apache2 state=latest
- debug: var=result.stdout_lines
完整的错误信息:
ERROR! 'sudo' is not a valid attribute for a Play
The error appears to be in '/home/Documents/ansible/play.yml': line 20, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
-
hosts: RemoteMachine1
^ here
【问题讨论】:
标签: ansible