ISSUE TYPE
- Bug Report
ANSIBLE VERSION
CONFIGURATION
$ cat ~/.ansible.cfg
[defaults]
host_key_checking=False
retry_files_enabled=False
OS / ENVIRONMENT
N/A
SUMMARY
Error «‘debug’ is not a valid attribute for a Play» for the sample from the documentation.
STEPS TO REPRODUCE
Create sample playbook like in the http://docs.ansible.com/ansible/playbooks_loops.html#looping-over-the-inventory:
- debug: msg={{ item }}
with_items: "{{ groups['all'] }}"
Run it.
$ ansible-playbook -v -i ./hosts/inventory sample.yml
EXPECTED RESULTS
Message output.
ACTUAL RESULTS
ERROR! 'debug' is not a valid attribute for a Play
The error appears to have been in '/home/lexus/src/ps/stash/sso/sso_install_7.6/sso_install/sso_apps_status.yml': line 1, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- debug: msg={{ item }}
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
How to reproduce, troubleshoot, and fix the “not a valid attribute for a Play” error.
September 20, 2021
Today we’re going to talk about Ansible troubleshooting and specifically about the “not a valid attribute for a Play” error.
I’m Luca Berton and welcome to today’s episode of Ansible Pilot.
The Best Resources For Ansible
Video Course
- Learn Ansible Automation in 250+examples & practical lessons: Learn Ansible with some real-life examples of how to use the most common modules and Ansible Playbook
Printed Book
- Ansible For VMware by Examples: A Step-by-Step Guide to Automating Your VMware Infrastructure
eBooks
- Ansible by Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
- Ansible For Windows By Examples: 50+ Automation Examples For Windows System Administrator And DevOps
- Ansible For Linux by Examples: 100+ Automation Examples For Linux System Administrator and DevOps
- Ansible Linux Filesystem By Examples: 40+ Automation Examples on Linux File and Directory Operation for Modern IT Infrastructure
- Ansible For Containers and Kubernetes By Examples: 20+ Automation Examples To Automate Containers, Kubernetes and OpenShift
- Ansible For Security by Examples: 100+ Automation Examples to Automate Security and Verify Compliance for IT Modern Infrastructure
- Ansible Tips and Tricks: 10+ Ansible Examples to Save Time and Automate More Tasks
- Ansible Linux Users & Groups By Examples: 20+ Automation Examples on Linux Users and Groups Operation for Modern IT Infrastructure
- Ansible For PostgreSQL by Examples: 10+ Examples To Automate Your PostgreSQL database
- Ansible For Amazon Web Services AWS By Examples: 10+ Examples To Automate Your AWS Modern Infrastructure
demo
The best way of talking about Ansible troubleshooting is to jump in a live demo to show you practically the not a valid attribute for a Play
error and how to solve it!
error code
- invalid_play_attribute_error.yml
---
- name: file module demo
hosts: all
vars:
myfile: "~/example.txt"
task:
- name: Creating an empty
ansible.builtin.file:
path: "{{ myfile }}"
state: touch
error execution
- output
$ ansible-playbook -i demo/inventory troubleshooting/invalid_play_attribute_fix.yml
ERROR! 'task' is not a valid attribute for a Play
The error appears to be in 'ansible-pilot/troubleshooting/invalid_play_attribute_error.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- -
- name: file module demo
^ here
fix code
- invalid_play_attribute_fix.yml
---
- name: file module demo
hosts: all
vars:
myfile: "~/example.txt"
tasks:
- name: Creating an empty
ansible.builtin.file:
path: "{{ myfile }}"
state: touch
fix execution
- output
$ ansible-playbook -i demo/inventory troubleshooting/invalid_play_attribute_fix.yml
PLAY [file module demo] *********************************************************************
TASK [Gathering Facts] **********************************************************************
ok: [demo.example.com]
TASK [Creating an empty file] ***************************************************************
changed: [demo.example.com]
PLAY RECAP **********************************************************************************
demo.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
code with ❤️ in GitHub
Recap
Now you know better how to troubleshoot the not a valid attribute for a Play error Error.
Subscribe to the YouTube channel, Medium, Website, Twitter, and Substack to not miss the next episode of the Ansible Pilot.
Academy
Learn the Ansible automation technology with some real-life examples in my
My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
Donate
Want to keep this project going? Please donate
У меня есть ANSI файл воспроизведения, который должен выполнить две задачи: сначала на локальном компьютере получить информацию об использовании диска, а другой задачей — получить информацию об использовании диска на удаленном компьютере и установить apache2 на удаленном компьютере.
Когда я пытаюсь запустить файл, я получаю сообщение об ошибке «ОШИБКА! ‘Sudo’ не является допустимым атрибутом для воспроизведения» Когда я удаляю раздел 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 ответа
Лучший ответ
- 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
Используйте стать: да, он будет запускать ваши задачи от имени пользователя root.
Стать директивами
3
shreyash
11 Фев 2020 в 07:47