user3796292 user3796292 - 1 month ago 12x
YAML Question

Setting vars in ansible and using them as arguments

I want to set variables and use them as parameters later on. This is the code I have

- hosts: localhost
connection: local


user: root

pass: ohheytherehowareyou


- name: 'vm_task_action'
prompt: 'Enter vm action to execute (none, delete)'
default: 'none'
private: no

- name: 'guest_vm'
prompt: "Enter the guest vm you want to delete"
default: 'none'
private: no
when: vm_task_action == "delete"

- name: deleting VMs
vcenter_hostname: vcenter_hostname
username: user
password: pass
guest: "{{ guest_vm }}"
state: absent
force: yes
when: vm_task_action == 'delete'

What is wrong with this code and how do I fix it. Any help would be greatly appreciated.


The Error says for itself:

'pass' is not a valid variable name

pass is a special keyword, so it can't be used as variable.
Use mypass: ohheytherehowareyou, for example.

P.S. also note that when: can't be used in vars_prompt section.