issues with variables

90 views
Skip to first unread message

Daley Okuwa

unread,
Jun 4, 2017, 7:30:28 AM6/4/17
to Ansible Project
Hello
i run a playbook and do get this error message 
:/etc/ansible$ ansible-playbook -u dokuwa1 --ask-pass playbook/apache.yml

ERROR! Syntax Error while loading YAML.


The error appears to have been in '/etc/ansible/playbook/apache.yml': line 3, column 2, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- hosts: all
 vars_files:
 ^ here


This is the playbook 

---
- hosts: all
 vars_files:
    - vars.yml
  sudo: yes

  tasks:
    - name:  install apache2
      apt: name={{item}} state=present update_cache=yes
      with_items:
        - libapache2-mod-wsgi
        - python-pip
        - python-virtualenv

    - name: start apache service
      service: name=apache2 state=started enabled=yes

    - name : verify apache service
      command: service apache2 status

    - name: verify apache listening port is 80
      wait_for: port=80 timeout=1

    - name: ensure mod_wsgi enabled
      apache2_module: state=present name=wsgi
      notify: restart apache2

    - name: copy files
      copy: src=/etc/ansible/playbook/ dest=/tmp mode=0755
      notify: restart apache2

    - name: delete a file
      file: path=/tmp/apache.yml state=absent

    - name: reinstate file that was deleted
      lineinfile: dest=/tmp/hostname.yml regexp=^hostname
                  line="ping 192.168.85.129"
  handlers:
     - name: restart apache2
       service: name=apache2 state=restarted


The issue is with the variable vars which is vars.yml which is in the same directory with apache.yml
 this is also the vars.yml file

 more playbook/vars.yml                            ---

auth:
  - { username: dokuwa1, password: xxxxxx }

Thanks



Kai Stian Olstad

unread,
Jun 4, 2017, 8:14:40 AM6/4/17
to ansible...@googlegroups.com
On 04. juni 2017 13:30, 'Daley Okuwa' via Ansible Project wrote:
> Hello
> i run a playbook and do get this error message
> :/etc/ansible$ ansible-playbook -u dokuwa1 --ask-pass playbook/apache.yml
>
> ERROR! Syntax Error while loading YAML.
>
>
> The error appears to have been in '/etc/ansible/playbook/apache.yml': line
> 3, column 2, but may
> be elsewhere in the file depending on the exact syntax problem.
>
> The offending line appears to be:
>
> - hosts: all
> vars_files:
> ^ here
>
>
> This is the playbook
>
> ---
> - hosts: all
> vars_files:
> - vars.yml
> sudo: yes

In yaml indentation is important and need to be consistent with number
of spaces.

Your var_files has only 1 space in front, it need to have 2 spaces so
it's consistent with the rest.

--
Kai Stian Olstad

Daley Okuwa

unread,
Jun 4, 2017, 8:43:48 AM6/4/17
to Ansible Project, ansible-pr...@olstad.com
Hello thanks

It is not retrieving this error 
but there is one thing i expect it not to ask me for my  username and password 
I thought that variable should take care of that 
what am i doing wrong 

Daley Okuwa

unread,
Jun 4, 2017, 11:01:19 AM6/4/17
to ansible...@googlegroups.com
Hello thanks

It is not retrieving this error 
but there is one thing i expect it not to ask me for my  username and password 
I thought that variable should take care of that 
what am i doing wrong 



From: Kai Stian Olstad <ansible-pr...@olstad.com>
To: ansible...@googlegroups.com
Sent: Sunday, 4 June 2017, 13:14
Subject: Re: [ansible-project] issues with variables

--
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-project+unsub...@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/91b73781-1740-771e-0a55-bdddddc4c841%40olstad.com.

For more options, visit https://groups.google.com/d/optout.


Trond Hindenes

unread,
Jun 4, 2017, 12:08:25 PM6/4/17
to Ansible Project, dokuw...@yahoo.co.uk
use an editor with yaml validation when writing you playbooks, that will take care of errors like this. VSCode has a yaml plugin for instance.

Daley Okuwa

unread,
Jun 4, 2017, 12:39:02 PM6/4/17
to tr...@hindenes.com, Ansible Project
Thanks
But is this the issue as it as I still have to key in my password 
I thought the variable would authenticate for me 
On Sun, 4 Jun 2017 at 17:14, Trond Hindenes
use an editor with yaml validation when writing you playbooks, that will take care of errors like this. VSCode has a yaml plugin for instance.

On Sunday, June 4, 2017 at 5:01:19 PM UTC+2, Daley Okuwa wrote:
Hello thanks

It is not retrieving this error 
but there is one thing i expect it not to ask me for my  username and password 
I thought that variable should take care of that 
what am i doing wrong 



From: Kai Stian Olstad <ansible-pr...@olstad. com>
To: ansible...@googlegroups. com
Sent: Sunday, 4 June 2017, 13:14
Subject: Re: [ansible-project] issues with variables
On 04. juni 2017 13:30, 'Daley Okuwa' via Ansible Project wrote:
> Hello
> i run a playbook and do get this error message
> :/etc/ansible$ ansible-playbook -u dokuwa1 --ask-pass playbook/apache.yml
>
> ERROR! Syntax Error while loading YAML.
>
>
> The error appears to have been in '/etc/ansible/playbook/apache. yml': line
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.

Trond Hindenes

unread,
Jun 5, 2017, 8:48:56 AM6/5/17
to Ansible Project, tr...@hindenes.com, dokuw...@yahoo.co.uk
The issue is that your yaml file is malformed, so Ansible doesn't understand it. For just getting started/testing things out, the easiest is probably to put the password in your inventory file. I would recommend reading up on that here: http://docs.ansible.com/ansible/intro_inventory.html, especially the section "list-of-behavioral-inventory-parameters".

Daley Okuwa

unread,
Jun 5, 2017, 3:52:57 PM6/5/17
to ansible...@googlegroups.com
Hello

I still have issues with password 
i have added username and  password to the inventory file and have used yamllink to validate my yaml 
at the command line i have to request for password all the time 
ansible_connection=ssh
ansible_port=22
ansible_user=dokuwa1
ansible_ssh_pass=xxxx

My command is without password is 
ansible-playbook -playbook/apache.yml - it fails

and with username  password 

ansible-playbook -u dokuwa1 --ask-pass playbook/apache.yml - it does not fail


thanks



From: Trond Hindenes <tr...@hindenes.com>
To: Ansible Project <ansible...@googlegroups.com>
Cc: tr...@hindenes.com; dokuw...@yahoo.co.uk
Sent: Monday, 5 June 2017, 13:49
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.

For more options, visit https://groups.google.com/d/ optout.
--
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.

Karol Czeryna

unread,
Jun 5, 2017, 6:37:30 PM6/5/17
to ansible...@googlegroups.com, tr...@hindenes.com, dokuw...@yahoo.co.uk
For the future I would strongly recommend to you to start using linter.

Even http://www.yamllint.com/ is fine :)

Best,
Karol



Daley Okuwa

unread,
Jun 6, 2017, 3:16:20 PM6/6/17
to ansible...@googlegroups.com, tr...@hindenes.com

Hello

Yes it looks very good yamllint.com i have tried it 
but also still having issues with password and username 
i want a situation where it does not ask me for my username & password

From: Karol Czeryna <cze...@gmail.com>
To: ansible...@googlegroups.com
Cc: tr...@hindenes.com; dokuw...@yahoo.co.uk
Sent: Monday, 5 June 2017, 23:37
Best,
Karol



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.

For more options, visit https://groups.google.com/d/ optout.

--
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.
--
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.

Karol Czeryna

unread,
Jun 7, 2017, 8:42:32 AM6/7/17
to ansible...@googlegroups.com, tr...@hindenes.com
Use your public/private key then.

By default Ansible will try to use those keys that are in the “ssh-agent” but you can also provide a path for the key in the inventory / vars / etc.

Basically everything is well explained here: 




Best,
Karol



Daley Okuwa

unread,
Jun 8, 2017, 8:14:48 AM6/8/17
to ansible...@googlegroups.com
Karol,

Yes thanks
i was able to resolve the issue of  prompting password for my user  i had to go to ansible.cfg and change the ask-pass  value to false
but the only issue is that i could not do this for root as i need the password prompt to install some packages 
Is there any way out for root or sudo 
Thanks 



From: Karol Czeryna <cze...@gmail.com>
To: ansible...@googlegroups.com
Cc: "tr...@hindenes.com" <tr...@hindenes.com>
Sent: Wednesday, 7 June 2017, 13:42

Karol Czeryna

unread,
Jun 8, 2017, 9:10:38 AM6/8/17
to ansible...@googlegroups.com
Daley,


Best,
Karol



Reply all
Reply to author
Forward
0 new messages