通过 Ansible 模块关闭 Ovirt 上的多个虚拟机
Shutdown multiple Virtual Machines on Ovirt by Ansible module
我是 Ansible 新手,我需要通过 ovirt_vm 模块与 Ovirt Manager 进行交互。
我的目的是多次关闭存储在 .yml 文件中的 VM 列表。
这是我的剧本:
---
- 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
非常感谢您的帮助!
如我的评论所述,只需使用您在之前的 debug
任务中使用的相同 loop 机制:
- name: Shutdown multiple VMs
ovirt_vm:
auth: "{{ ovirt_auth }}"
cluster: CL_OVIRT
state: stopped
name: "{{ item }}"
with_items: "{{ vm }}"
# alternatively, use the new loop syntax. See doc link above
# loop: "{{ vm }}"
我是 Ansible 新手,我需要通过 ovirt_vm 模块与 Ovirt Manager 进行交互。 我的目的是多次关闭存储在 .yml 文件中的 VM 列表。
这是我的剧本:
---
- 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
非常感谢您的帮助!
如我的评论所述,只需使用您在之前的 debug
任务中使用的相同 loop 机制:
- name: Shutdown multiple VMs
ovirt_vm:
auth: "{{ ovirt_auth }}"
cluster: CL_OVIRT
state: stopped
name: "{{ item }}"
with_items: "{{ vm }}"
# alternatively, use the new loop syntax. See doc link above
# loop: "{{ vm }}"