我是 Ansible 新手,我需要通过 ovirt_vm 模块与 Ovirt Manager 交互。我的目的是多次关闭存储在 .yml 文件中的虚拟机列表。
这是我的剧本:
---
- name: Manage VMs on ovirt-Manager
hosts: MyHost
connection: local
vars_files:
- ovirt_vars.yml
#FQDN and credentials
- ovirt-vms.yml
#List of VMs
vars:
vm: "{{ VMs }}"
pre_tasks:
- name: Login to ovirt-M
ovirt_auth:
hostname: "{{ ovirt_fqdn }}"
username: "{{ ovirt_user }}"
password: "{{ ovirt_password }}"
tags:
- always
tasks:
- name: Show List of VMs from ovirt-vms.yml
debug:
msg: "{{ item }}"
with_items:
"{{ vm }}"
问题出在这个任务中
- name: Shutdown multiple VMs
ovirt_vm:
auth: "{{ ovirt_auth }}"
cluster: CL_OVIRT
state: stopped
name: "{{ vm |string }}" << HERE
如何将列表中的单个项目放入参数名称中?例如 VM01,VM02,...VM10
post_tasks:
- name: Logout from ovirt-M
ovirt_auth:
state: absent
ovirt_auth: "{{ ovirt_auth }}"
tags:
- always
非常感谢你的帮助!