ОШИБКА! 'sudo' не является допустимым атрибутом для Play - PullRequest
1 голос
/ 11 февраля 2020

У меня есть 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

Ответы [ 2 ]

3 голосов
/ 11 февраля 2020

Ansible ключевое слово воспроизведения sudo было (долго go) устарело с предупреждениями в версии 2.0 и удалено в версии 2.2

См. фактическая поддерживаемая игра ключевые слова . Использование:

become: true
3 голосов
/ 11 февраля 2020
-  hosts: RemoteMachine1
   name: play2
   become: 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

use make: да, он будет запускать ваши задачи как пользователь root.

Стать директивами

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...