Reputation: 993
Ansible Version: 2.2.1.0
hostfile:
[master]
54.65.104.4
[slaves]
52.69.71.248
tasks/main.yaml
- name: Checking if the node is already having spark master installed (master)
stat:
path: /etc/init.d/spark-master
register: spark-master
when: inventory_hostname in groups['master']
- name: Checking if the node is already having spark worker installed
stat:
path: /etc/init.d/spark-slave
register: spark-slave
when: inventory_hostname in groups['slaves']
# Downloading to the master
- include: download.yaml
when: (inventory_hostname in groups['master']) and ( spark-master.stat.exists == false)
# Downloading to the slaves
- include: download.yaml
when: (inventory_hostname in groups['slaves']) and ( spark-slave.stat.exists == False )
But when I execute the script I am receiving the following errors:
fatal: [52.69.71.248]: FAILED! => {"failed": true, "msg": "The conditional check '(inventory_hostname in groups['slaves']) and ( spark-slave.stat.exists == False )' failed. The error was: error while evaluating conditional ((inventory_hostname in groups['slaves']) and ( spark-slave.stat.exists == False )): 'slave' is undefined\n\nThe error appears to have been in '/opt/ansible-role-spark/tasks/download.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: Download Spark\n ^ here\n"}
Can anybody help me in figuring the mistake I am committing.
Upvotes: 0
Views: 4956
Reputation: 68269
The error in question is about:
Variable names should be letters, numbers, and underscores.
See docs.
But you have other design flaws in your playbook that are beyond this question.
Upvotes: 1
Reputation: 68489
Either quote the condition, like:
when: "(inventory_hostname in groups['master']) and ( spark-master.stat.exists == false)"
Or don't use parentheses.
Upvotes: 3