У меня есть ansible файл воспроизведения, который должен выполнять две задачи: сначала на локальном компьютере получить информацию об использовании диска, а другой задачей - получить информацию об использовании диска на удаленном компьютере и установить apache2 на удаленном компьютере.
Когда я пытаюсь запустить файл, я получаю сообщение об ошибке "ОШИБКА! 'Sudo' не является допустимым атрибутом для Play" Когда я удаляю раздел sudo и apt из файла yml работает нормально.
Я использую ansible 2.9.4. Ниже приведены два файла playbook:
Файл работает без ошибок,
---
-
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