YAML Issue in Ansible 2.3.0 - ansible

I got this playbook to run on a VM running Ansible 2.3.1, with no errors, however, I am running into problems with the very first character in other versions 2.3.0 and older and I am NOT seeing where I am going wrong.
The format exactly follows the examples given in the documentation for cl-license, and this is pretty vanilla in that there is no logic or conditional statements or anything to this YAML.
---
- hosts: accton_as6712_32x
tasks:
- name: install_license_for_6712
cl_license:
src: "http://10.43.255.182/cumulus/license-4x5712-4x6712.txt"
- hosts: accton_as4610_54
tasks:
- name: install_license_for_4610
cl_license:
src: "http://10.43.255.182/cumulus/license-2x4600.txt"
- hosts: mlnx_x86_MSN2410B
tasks:
- name: install_license_for_2410
cl_license:
src: "http://10.43.255.182/cumulus/license-2x2410.txt"
- hosts: mlnx_x86_MSN2700
tasks:
- name: install_license_for_2700
cl_license:
src: "http://10.43.255.182/cumulus/license-mellanox-demo-2700.txt"
This is the error I get from Jenkins/Ansible:
The offending line appears to be:
---
- hosts: accton_as6712_32x
^ here
And if I use YAML Lint, I get this error:
(<unknown>): did not find expected '-' indicator while parsing a block collection at line 2 column 1
I am fairly new to Ansible and would love if somebody could point out where I am going wrong?

I'm not saying the cl-license module is the wrong way but have you considered using ZTP to install licenses on your Cumulus switches?
By the way, the indentation looks correct but make sure you have actual spaces and not tab characters in your file. Also, check for any odd trailing spaces.

Related

Ansible can't run when vars are used in include_tasks

I have two playbooks driver.yaml invoking another play after converting from template called main_driver.yml
Main playbook driver.yml
---
- name: Setup Services
hosts: all
gather_facts: no
vars_files:
- var_input_driver.yaml
tasks:
- name: Converting template to playbook
template:
src: template_for_driver.yaml.j2
dest: main_driver.yaml
delegate_to: localhost
- name: run roles
include_tasks: main_driver.yaml
Content of main_driver.yaml
---
- name: Setup Services
vars:
java_package: java-11-openjdk
dock_version: 18.09.0
- name: Setup services
include_role:
name: configure-java
Receiving error as below:
FAILED! => {"reason": "no module/action detected in task.\n\nThe error appears to be in 'main_driver.yaml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: Setup Services\n ^ here\n"}
vars is not a module name but a task option. You should fix your included file like so:
---
- name: Setup services
include_role:
name: configure-java
vars:
java_package: java-11-openjdk
dock_version: 18.09.0
An other possible way would be:
---
- name: Set variables
set_fact:
java_package: java-11-openjdk
dock_version: 18.09.0
- name: Setup services
include_role:
name: configure-java
couple of things:
main_driver.yaml seems to include itself (main_driver) - that probably won't work.
the task file used with "include_tasks" should be a "pure" task file, not a playbook. In other words, it should not contain a playbook header (hosts, name, etc), but simply a list of tasks.
Im struggling to understand the logic in your example, maybe double-check that the file contents are correct?

Unable to run get_url module with ansible playbook

I have started to learn Ansible watching online vids . But got stuck at the first step when creating and running a simple playbook.
When I run below playbook as below ->
$ ansible-playbook download.yml
Then output displayed is ->
ERROR! Syntax Error while loading YAML.
mapping values are not allowed in this context
The error appears to have been in '/etc/ansible/download.yml': line 3, column 11, but may
be elsewhere in the file depending on the exact syntax problem. The offending line appears to be:
-name: Test
get_url:
^ here
Below are the contents of my playbook download.yml ->
tasks:
-name: Test
get_url:
url: https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.ini
dest: /home/sunny/ec2.ini
mode: 700
What am I doing wrong here ?
Space behind the dash in name is missing. Instead of
-name: Test
the correct syntax is
- name: Test

Ansible YAML syntax error in simple playbook

I have my first playbook and it fails. I assume it's a syntax error but as I'm not a coder I have no idea why YAML fails? Is it to do with spacing?
Here is what I have:
---
- name: Update all packages to the latest version
become: true
apt:
update_cache: yes
upgrade: dist
- name: Remove useless packages from the cache
apt:
autoclean: yes
- name: Remove dependencies that are no longer required
apt:
autoremove: yes
ERROR! Syntax Error while loading YAML.
The error appears to have been in '/home/pi/playbooks/update-apt.yml': line 3, column 11, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Update all packages to the latest version
become: true
^ here
Firstly: this is not a playbook, because it doesn't contain plays (which must contain hosts declaration), but tasks.
Secondly: your indentation is terribly broken -- it is critical in YAML to keep declarations aligned properly (that said, the error you see is not a YAML syntax error, but an Ansible error resulting from improper data defined in a correctly written YAML file).
If you want to run it locally, it should look more or less like this:
---
- hosts: localhost
connection: local
tasks:
- name: Update all packages to the latest version
become: true
apt:
update_cache: yes
upgrade: dist
autoclean: yes
autoremove: yes

Ansible - Unable to run certain JUNOS modules

I'm trying to run the Ansible modules junos_cli and junos_rollback and I get the following error:
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in '/home/quake/network-ansible/roles/junos-rollback/tasks/main.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
---
- name: I've made a huge mistake
^ here
This is the role in question:
---
- name: I've made a huge mistake
junos_rollback:
host={{ inventory_hostname }}
user=ansible
comment={{ comment }}
confirm={{ confirm }}
rollback={{ rollback }}
logfile={{ playbook_dir }}/library/logs/rollback.log
diffs_file={{ playbook_dir }}/configs/{{ inventory_hostname }}
Here is the Juniper page:
http://junos-ansible-modules.readthedocs.io/en/1.3.1/junos_rollback.html
Their example's syntax is a little odd. host uses a colon while the rest uses = signs. I've tried mixing both and only using one or the other. I keep getting errors.
I also confirmed that my junos-eznc version is higher than 1.2.2 (I have 2.0.1)
I've been able to use junos_cli before, I don't know if a version mismatch happened. On the official Ansible documentation, there is no mention of junos_cli or junos_rollback. Perhaps they're not supported anymore?
http://docs.ansible.com/ansible/list_of_network_modules.html#junos
Thanks,
junos_cli & junos_rollback are part of Galaxy and not core modules. You can find them at
https://galaxy.ansible.com/Juniper/junos/
Is the content posted here has whole content of your playbook? if yes, You need to define other items too in your playbook such as roles, connection, local. For example
refer https://github.com/Juniper/ansible-junos-stdlib#example-playbook
```
---
- name: rollback example
hosts: all
roles:
- Juniper.junos
connection: local
gather_facts: no
tasks:
- name: I've made a huge mistake
junos_rollback:
host = {{inventory_hostname}}
----
----
```
Where have you saved the content of juniper.junos modules?. Can you post the content of your playbook and the output of the tree command to see your file structure? That could help.
I had a similar problem where Ansible was not finding my modules and what I did was to copy the juniper.junos folder to my roles folder and then added a tasks folder within it to execute the main.yaml from there.
Something like this:
/Users/macuared/Ansible_projects/roles/Juniper.junos/tasks
---
- name: "TEST 1 - Gather Facts"
junos_get_facts:
host: "{{ inventory_hostname}}"
user: "uuuuu"
passwd: "yyyyyy"
savedir: "/Users/macuared/Ansible_projects/Ouput/Facts"
ignore_errors: True
register: junos
- name: Checking Device Version
debug: msg="{{ junos.facts.serialnumber }}"
Additionally, I would add "" to the string values in your YAML. Something like this:
---
- name: I've made a huge mistake
junos_rollback:
host="{{ inventory_hostname }}"
user=ansible
comment="{{ comment }}"
confirm={{ confirm }}
rollback={{ rollback }}
logfile="{{ playbook_dir }}/library/logs/rollback.log"
diffs_file="{{ playbook_dir }}/configs/{{ inventory_hostname }}"
Regarding this "I've tried mixing both and only using one or the other. I keep getting errors."
I've used just colon and mine works fine even when in the documentation suggests = signs. See junos_get_facts

Simple ansible playbook syntax error (YAML)

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

Resources