NOOB needs help with small ansible script.

93 views
Skip to first unread message

Raymond Nonya

unread,
Apr 23, 2017, 8:12:29 PM4/23/17
to Ansible Project
I am two days now into ansible and I love everything it can do. My problem is that ansible does not like my yaml :-). My below playbook keeps throwing errors when I run a --check on it. Basically I want the update rpm pulled down and put in /tmp. Then I want to check if a user account exists. If not I want it to stop and inform me that the user doesn't exist. I looked at the fail instructions and I followed it but I guess I am missing something. Thank you in advanced for your help. 


error
The offending line appears to be:

- fail:
msg: "User Splunk does not exist, stopping install"
^ here

playbook
- name: install splunk forwarder Binaries
  hosts: all
  gather_facts: True

  tasks:
     - name: download splunk forwarder RPM
       get_url:
       dest: /tmp/update-6.5.3-36937ad027d4-linux-2.6-x86_64.rpm
       mode: 777

       action: shell /usr/bin/getent passwd nix| /usr/bin/wc -l | tr -d ''
       register: user_exist
#       when: user_exist.stdout == 0

- fail:
msg: "User nix does not exist, stopping install"
when: user_exist.stdout == 0

Paul Markham

unread,
Apr 23, 2017, 8:48:07 PM4/23/17
to Ansible Project
Try indenting the msg line. YAML is very fussy about spacing and indentation.

Raymond Nonya

unread,
May 1, 2017, 2:20:55 PM5/1/17
to Ansible Project
Still having issues. I completely started over and no luck. Ansible still complains, it is complaining about action and every time I change something it complains about another stanza. 
Here is the error
ansible-playbook TEST -i hosts -C
ERROR! Syntax Error while loading YAML.


The error appears to have been in '/root/SPLUNK/TEST': line 5, column 10, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: Installs splunk
   action: shell wget -O /tmp/splunk.rpm http://example.com/file
         ^ here

Here is my YAML playbook
---
- hosts: all
  tasks:
- name: Installs splunk
   action: shell wget -O /tmp/splunk.rpm http://example.com/file

- name: change file ownership
  file: path=/tmp/splunk.rpm
   owner=root
   mode=0700

Kai Stian Olstad

unread,
May 1, 2017, 2:47:05 PM5/1/17
to ansible...@googlegroups.com
On 26. april 2017 21:55, Raymond Nonya wrote:
> Still having issues. I completely started over and no luck. Ansible still
> complains, it is complaining about action and every time I change something
> it complains about another stanza.
> Here is the error
> ansible-playbook TEST -i hosts -C
> ERROR! Syntax Error while loading YAML.

You have problem with indentation, I do recommend reading the docs,
start with this one,
https://docs.ansible.com/ansible/YAMLSyntax.html

And then read this one,
https://docs.ansible.com/ansible/playbooks_intro.html

Do look at the indentation that is 2 spaces in the examples.
In YAML, indentation is is essential.

--
Kai Stian Olstad
Message has been deleted
Message has been deleted

Paul Markham

unread,
May 2, 2017, 8:31:26 PM5/2/17
to Ansible Project, ansible-pr...@olstad.com

Your indentation is still all over the place. Try:
Reply all
Reply to author
Forward
0 new messages