LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-08-2019, 09:12 AM   #1
Mark_667
Member
 
Registered: Aug 2005
Location: Manchester, England
Distribution: Ubuntu 20.04
Posts: 383

Rep: Reputation: 30
Ansible did not find expected key


I'm trying to use Ansible to update Linux targets but an getting the below error:

Code:
ERROR! Syntax Error while loading YAML.

The error appears to have been in '/home/ec2-user/Playbooks/Apply_OS_Updates/tasks/main.yml': line 7, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

    name: "*"
      state: latest
      ^ here

exception type: <class 'yaml.parser.ParserError'>
exception: while parsing a block mapping
  in "<unicode string>", line 6, column 5
did not find expected key
  in "<unicode string>", line 7, column 7
The playbook is:
Code:
---
- name: update packages
  hosts: ansible-test-targets
  become: true
  yum:
    name: "*"
      state: latest
 
# check if we need a reboot
- name: check if reboot needed
  stat: path=/var/run/reboot-required
  register: file_reboot_required
 
# Stop here unless the node needs a reboot
- meta: end_play
    when: not file_reboot_required.stat.exists
 
- name: reboot node
  shell: sleep 2 && shutdown -r now "Reboot triggered by ansible"
  async: 1
  poll: 0
  ignore_errors: true
What's going on here?
 
Old 08-08-2019, 09:48 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
I think "state" must have the same indentation as "name".

[Opinion]
YAML parsing error messages are not often useful.
[/Opinion]
 
Old 08-08-2019, 10:08 AM   #3
Mark_667
Member
 
Registered: Aug 2005
Location: Manchester, England
Distribution: Ubuntu 20.04
Posts: 383

Original Poster
Rep: Reputation: 30
Thanks for the tip, I don't think I changed that from the example I got it from. After a couple other minor corrections It now gives me:

Quote:
ERROR! 'meta' is not a valid attribute for a Play
Code:
---
- name: update packages
  hosts: ansible-test-targets
  become: true

  tasks:
  - name: upgrade all packages
    yum: name='*' state=latest

# check if we need a reboot
  - name: check if reboot needed
    stat: path=/var/run/reboot-required
    register: file_reboot_required

# Stop here unless the node needs a reboot
- name: check reboot
  meta: end_play
  when: not file_reboot_required.stat.exists

- name: reboot node
  shell: sleep 2 && shutdown -r now "Reboot triggered by ansible"
  async: 1
  poll: 0
  ignore_errors: true

Last edited by Mark_667; 08-08-2019 at 11:15 AM. Reason: Fixed YAML syntax error
 
  


Reply

Tags
ansible, updates



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Ansible Guide: Manage Files using Ansible LXer Syndicated Linux News 0 04-26-2019 10:32 AM
LXer: Ansible Guide: Create Ansible Playbook for LEMP Stack LXer Syndicated Linux News 0 04-13-2019 05:03 AM
LXer: Ansible Tutorial: Introduction to simple Ansible commands LXer Syndicated Linux News 0 05-21-2018 10:28 AM
LXer: Ansible Tutorial: Intorduction to simple Ansible commands LXer Syndicated Linux News 0 01-14-2018 05:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration