issues with variables

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

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.

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

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

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.

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
Thanks

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

For the future I would strongly recommend to you to start using linter.

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

Best,
Karol

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

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

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:

http://docs.ansible.com/ansible/intro_getting_started.html

Best,
Karol

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

Daley,

Please read documentation: https://docs.ansible.com/ansible/become.html

Best,
Karol