ansible playbook in json format not working

41 views
Skip to first unread message

Narahari 'n' Savitha

unread,
Jun 26, 2019, 6:08:25 PM6/26/19
to Ansible Project
Hello Folkds:

Thank you in advance for your time and attention.

I wrote a playbook in the json format.

[
  {
    "name": "Test the json mode"
    "hosts": "cool_columbus",
    "tasks": [
      {
        "name": "First task"
        "shell": {
          "chdir": "/tmp",
          "free_form": "ls -l",
        }
      }
    ]
  }
]

when I run it with the command

 ansible-playbook test_playbook.json
ERROR! Syntax Error while loading YAML.
  expected ',' or '}', but got '<scalar>'

The error appears to have been in '/home/pidansible/test_playbook.json': line 4, column 5, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


What am I doing wrong and how to run this ?

Please help.

-N 

Michael Mullay

unread,
Jun 26, 2019, 7:18:22 PM6/26/19
to ansible...@googlegroups.com, Narahari 'n' Savitha

Playbooks must be in yaml. Inventories can be in json (at least dynamic inventories require it), but not the playbooks themselves.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/701970c3-3726-4261-aa2f-56ba64370acc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

James Cassell

unread,
Jun 26, 2019, 7:20:41 PM6/26/19
to Ansible List

On Wed, Jun 26, 2019, at 6:08 PM, Narahari 'n' Savitha wrote:
> Hello Folkds:
>
> Thank you in advance for your time and attention.
>
> I wrote a playbook in the json format.
>
> > [
> > {
> > "name": "Test the json mode"

Missing a comma.

> > "hosts": "cool_columbus",
> > "tasks": [
> > {
> > "name": "First task"

Missing comma.

> > "shell": {
> > "chdir": "/tmp",
> > "free_form": "ls -l",
> > }
> > }
> > ]
> > }
> > ]
>
> when I run it with the command
>
> >> ansible-playbook test_playbook.jsonERROR! Syntax Error while loading YAML. expected ',' or '}', but got '<scalar>'
> >> The error appears to have been in '/home/pidansible/test_playbook.json': line 4, column 5, but maybe elsewhere in the file depending on the exact syntax problem.
> >> The offending line appears to be:
>
>
> What am I doing wrong and how to run this ?
>
> Please help.
>
> -N

V/r,
James Cassell

Narahari 'n' Savitha

unread,
Jun 27, 2019, 12:32:23 AM6/27/19
to Ansible Project
Thank You James for pointing out the mistakes.

I fixed them and now the json playbook works.

Narahari 'n' Savitha

unread,
Jun 27, 2019, 12:33:26 AM6/27/19
to Ansible Project
James pointed out the mistakes in the json and now it works.
I am able to use json as valid format for playboks.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible...@googlegroups.com.

Narahari 'n' Savitha

unread,
Jun 27, 2019, 12:36:33 AM6/27/19
to Ansible Project


On Wednesday, June 26, 2019 at 6:08:25 PM UTC-4, Narahari 'n' Savitha wrote:
Hello Folkds:

Thank you in advance for your time and attention.

I wrote a playbook in the json format.

[
  {
    "name": "Test the json mode"==> put ,
    "hosts": "cool_columbus",
    "tasks": [
      {
        "name": "First task" ==> put ,

        "shell": {
          "chdir": "/tmp",
          "free_form": "ls -l",
        }
      }
    ]
  }
]

Angel Rengifo Cancino

unread,
Jun 27, 2019, 2:49:12 PM6/27/19
to ansible...@googlegroups.com
Just for curiosity, why are you using json instead of yaml?

To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.

Brian Coca

unread,
Jun 28, 2019, 1:04:52 PM6/28/19
to Ansible Project
JSON is a subset of YAML, so anything you see in YAML can be done in
JSON, .. the real question is SHOULD YOU?
--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages