在ansible中设置变量并将它们用作参数

Setting vars in ansible and using them as arguments

我想设置变量并稍后将它们用作参数。这是我的代码

---
- hosts: localhost
  connection: local

  vars:
      vcenter_hostname: hellothere.hey.com

      user: root

      pass: ohheytherehowareyou


  vars_prompt:

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

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

这段代码有什么问题,我该如何解决。任何帮助将不胜感激。

错误不言而喻:

'pass' is not a valid variable name

pass是特殊关键字,不能作为变量使用。
例如,使用 mypass: ohheytherehowareyou

P.S。另请注意,when: 不能用于 vars_prompt 部分。