Error apt is not a valid attribute for a play

I am trying to just run a playbook with: ansible-playbook roles/java/tasks/debian.yml -i /etc/ansible/hosts and the output is as follows: ERROR! 'apt_repository' is not a valid attribute for a P...

I am trying to just run a playbook with:
ansible-playbook roles/java/tasks/debian.yml -i /etc/ansible/hosts

and the output is as follows:

ERROR! 'apt_repository' is not a valid attribute for a Play

The error appears to have been in '/Users/awest1/Workspace/ansible-playbooks/roles/java/tasks/debian.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: Setup oracle java deb repo
  ^ here

The yml file that I am trying to play has this head:

- name: Setup oracle java deb repo
   apt_repository:
     repo: "ppa:webupd8team/java"
     update_cache: yes

I would appreciate any direction given.
Thanks

asked Jun 27, 2017 at 19:52

aphexlog's user avatar

0

You try to run tasks list as a playbook.

To make it work, write a simple playbook:

- hosts: all
  tasks:
    - include: roles/java/tasks/debian.yml

answered Jun 27, 2017 at 20:08

Konstantin Suvorov's user avatar

Your input

- name: Setup oracle java deb repo
   apt_repository:
     repo: "ppa:webupd8team/java"
     update_cache: yes

is invalid YAML.

This is correct (value for name is a scalar spread over multiple lines):

- name: Setup oracle java deb repo
   apt_repository
     repo "ppa:webupd8team/java"
     update_cache yes

And this is correct as well (proper indentation at 2 indents):

- name: Setup oracle java deb repo
  apt_repository:
    repo: "ppa:webupd8team/java"
    update_cache: yes

You probably want the later.

answered Jun 27, 2017 at 21:41

Anthon's user avatar

AnthonAnthon

65.7k29 gold badges179 silver badges236 bronze badges

1

How to reproduce, troubleshoot, and fix the “not a valid attribute for a Play” error.

September 20, 2021

Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons

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

BUY the Complete PDF BOOK to easily Copy and Paste the 250+ Ansible code

Donate

Want to keep this project going? Please donate

Comments

@brucegogo

@ansibot
ansibot

added

affects_2.6

This issue/PR affects Ansible v2.6

bug

This issue/PR relates to a bug.

module

This issue/PR relates to a module.

needs_triage

Needs a first human triage before being processed.

support:core

This issue/PR relates to code supported by the Ansible Engineering Team.

labels

Jun 8, 2018

@ansibot
ansibot

added
the

needs_info

This issue requires further information. Please answer any outstanding questions.

label

Jun 8, 2018

@ansibot
ansibot

removed
the

needs_info

This issue requires further information. Please answer any outstanding questions.

label

Jun 8, 2018

@ansible
ansible

locked as resolved and limited conversation to collaborators

Nov 20, 2018








by


asked

Feb 21, 2020



Learning ansible, trying at least one yaml to run to check. Using Google I wrote what is below to update the system via apt. But not running, I can not understand in what an error. Prompt to the beginner — where to dig? Thanks in advance

---
- hosts: all
sudo: yes
tasks:
- name: Update and upgrade apt packages
become: true
apt:
upgrade: yes
update_cache: yes
cache_valid_time: 86400

Ошибка:

ERROR! ‘apt’ is not a valid attribute for a Play

The error appears to have been in ‘/var/lib/awx/projects/_8__test/test.yaml’: line 5, column 3, but may

be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

tasks:

— name: Update and upgrade apt packages

^ here

2 Answers








by
Hocopor


answered

Feb 21, 2020



Obviously the problems in the margins.

- hosts: all
sudo: yes
tasks:
- name: Update and upgrade apt packages
become: true
apt: upgrade=yes update_cache=yes cache_valid_time=86400

Может как то так?








by
opium


answered

Feb 21, 2020



ETOGES Python, the whole syntax is based on indentation, and they have you dancing like a tree and fuck understand what you wrote

Понравилась статья? Поделить с друзьями:
  • Error applying virtual switch properties changes
  • Error applying update 7 errorcode kinstalldeviceopenerror
  • Error applying transforms verify that the specified transforms paths are valid
  • Error applying transforms verify that the specified transform paths are valid
  • Error application error incorrect username or password or account is temporarily blocked