gpt4 book ai didi

ansible - 错误! 'sudo' 不是 Play 的有效属性

转载 作者:行者123 更新时间:2023-12-03 15:02:26 26 4
gpt4 key购买 nike

我有一个 ansible 播放文件,它必须执行两个任务,首先在本地机器上获取磁盘使用情况,另一个任务是获取远程机器的磁盘使用情况并在远程机器上安装 apache2。

当我尝试运行该文件时,出现错误 “错误!‘sudo’不是播放的有效属性”
当我从 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 play 关键字 sudo是(很久以前)deprecated with warnings in version 2.0 and removed in version 2.2
actual supported play keywords .用:

become: true

关于ansible - 错误! 'sudo' 不是 Play 的有效属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60162859/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com