Reputation: 1624
I've just started ansible and have created a simple playbook to deploy nginx on a target server. The YAML playbook file (myplaybook.yml) looks like this:-
- name: Configure webserver with nginx
hosts: webservers
sudo: True
tasks:
- name: install nginx
- apt: name=nginx update_cache=yes
environment:
http_proxy: myproxy.com:8088
https_proxy: myproxy.com:8088
When I execute:-
$ ansible-playbook myplaybook.yml
I get:-
ERROR: Syntax Error while loading YAML script, nginx-ansible.yml Note: The error may actually appear before this position: line 7, column 23
- apt: name=nginx update_cache=yes
environment:
^
I don't see why this error occurs - the hosts file contains the [webservers] section OK - can anyone help?
Thanks!
Upvotes: 2
Views: 23531
Reputation: 20759
You've got a couple problems with your YAML. First, - name
and - apt
shouldn't both have the -
prefix. That's making Ansible think you have one task with a name of install nginx
but no module or anything else associated with it, then you have a second task with no name but invokes the apt module.
The second problem is indentation. You have an extra space in front of the word environment
that makes YAML think you're starting a new child element and not just adding attributes to the current task. So your entire task should look something like this (and remember that spacing is critical):
tasks:
- name: install nginx
apt: name=nginx update_cache=yes
environment:
http_proxy: myproxy.com:8088
https_proxy: myproxy.com:8088
Upvotes: 5