ansible playbook syntax error - ansible

Ansible playbook throwing a syntax error, however everything looks correct.
What can be the issue on the role?
ERROR:
The error appears to have been in '/home/Desktop/playbooks/xx.yml': line 6, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
roles:
- role: chronos_task
^ here
CODE
---
- hosts: localhost
connection: local
gather_facts: no
roles:
- role: chronos_task
no_log: true
chronos_url: 'http://{{ chronos_host }}:{{ chronos_port }}'
chronos_tasks:
- type: iso8601

What can be the issue on the role?
The issue might be that the chronos_task role is not present in roles' path.
This is the exact error message you get in such a situation.

Related

Error! conflicting action statements: project_path, state (ansible)

Trying to execute this code but having the said errors encountered above
code
---
- hosts: localhost
connection: local
collections:
- community.general.terraform
tasks:
- name: Execute Terraform Template
project_path: '/Users/<username>/Desktop/<repository>/<file>'
state: present
force_init: true
The offending line appears to be:
tasks:
- name: Execute Terraform Template
^ here
been trying to figure this one out.. I am using a macOS, installed Ansible locally already.
Thank you in advance!!
Trying to execute the code above but unable to succeed.
You have an indentation problem in your script.
Should work like this:
- name: Run Terraform
gather_facts: No
hosts: localhost
tasks:
- name: Execute Terraform Template
terraform:
project_path: '/Users/<username>/Desktop/<repository>/<file>'
state: present
force_init: true

Ansible collection not detected when running playbook on AWX

I use modules from the collection netapp.ontap in my ansible playbook which works perfectly fine when run using ansible-playbook command.
However, when run from AWX, it fails to detect the collection and immediately throws an errors that it cannot detect the ansible module/collection.
I even tried to re-install the collection from the playbook itself but with no luck.
The ansible collection is confirmed to be installed as it already works fine when run outside AWX.
The host is running ansible 2.10.4.
Here is my playbook:
---
- hosts: all
gather_facts: yes
collections:
- netapp.ontap
tasks:
- name: Install Netapp Collection from Ansible Galaxy
shell: ansible-galaxy collection install netapp.ontap
- name: Run Task
import_tasks: tasks/hil.yml
Task:
- name: 'Gather SVMs'
netapp.ontap.na_ontap_info:
state: info
hostname: "{{ netapp_hostname }}"
username: "{{ netapp_username }}"
password: "{{ netapp_hv_password }}"
gather_subset:
- vserver_info
Error from AWX:
SSH password:
Vault password:
ERROR! couldn't resolve module/action 'netapp.ontap.na_ontap_info'. This often indicates a misspelling, missing collection, or incorrect module path.
The error appears to be in '/tmp/awx_421_gey54bdw/project/tasks/hil.yml': line 6, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: 'Gather SVMs'
^ here
This one looks easy to fix. It seems that there is a value started
with a quote, and the YAML parser is expecting to see the line ended
with the same kind of quote. For instance:
when: "ok" in result.stdout
Could be written as:
when: '"ok" in result.stdout'
Or equivalently:
when: "'ok' in result.stdout"
Update:
I created a collections/requirements.yml file, with the below details but now AWX fails the task itself.
collections/requirements.yml
collections:
name: https://github.com/ansible-collections/netapp.git
type: git
Error:
"/var/lib/awx/venv/awx/lib/python3.6/site-packages/awx/main/tasks.py",
line 1279, in run self.pre_run_hook(self.instance, private_data_dir) File
"/var/lib/awx/venv/awx/lib/python3.6/site-packages/awx/main/tasks.py",
line 1862, in pre_run_hook sync_task.run(local_project_sync.id) File
"/var/lib/awx/venv/awx/lib/python3.6/site-packages/awx/main/tasks.py",
line 698, in _wrapped return f(self, *args, **kwargs) File
"/var/lib/awx/venv/awx/lib/python3.6/site-packages/awx/main/tasks.py",
line 1444, in run raise AwxTaskError.TaskError(self.instance, rc)
Exception: project_update 435 (failed) encountered an error (rc=2), please
see task stdout for details.

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?

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

Ansible playbook syntax error with tasks:

I just started experimenting with ansible and I am trying to write my first simple playbook.
But I am getting a syntax error with the task keywork,
---
name: add ansible user
hosts: all
become: true
become_method: sudo
become_user:root
tasks:
- user:
name: ansible
groups: ansible
When I run this get the following:
utility:~/scripts/ansible# ansible-playbook --check add-ansible-user.yml
ERROR! Syntax Error while loading YAML.
The error appears to have been in '/root/scripts/ansible/add-ansible-user.yml': line 8, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
^ here
From searching I belive the best bet is that I have an indent problem, but nomatter how I have tried to change it up, I cant get it too work.
- name: add ansible user
hosts: all
become: true
become_method: sudo
become_user: root
tasks:
- user:
name: ansible
groups: ansible
It's indeed the indentation problem. Please try the code written above.
Facing same issue, by making correct Indent spacing able to resolve it
As ref below
---
- name: my ansible
hosts: webserver
remote_user: root
become: true
tasks:
- name: intall httpd
yum:
name: httpd
state: latest
- name: run httpd
service:
name: httpd
state: started
- name: create content
copy:
content: “Congratulation on installing ansible”
dest: /var/www/html/index.html
The problem is here:
become_user:root
You need a space between : and root
become_user: root

Resources