Variables 可变变量列表范围
在Ansible中添加变量列表时,如何获得类似值的范围?例如,“000-100”-在Ansible hosts文件中,可以这样列出“hostname-[a:v].com”。在变量列表中,此过程是否类似 我的用例是在oVirt中一次性提供许多VM,而不必逐行列出Variables 可变变量列表范围,variables,ansible,ovirt,Variables,Ansible,Ovirt,在Ansible中添加变量列表时,如何获得类似值的范围?例如,“000-100”-在Ansible hosts文件中,可以这样列出“hostname-[a:v].com”。在变量列表中,此过程是否类似 我的用例是在oVirt中一次性提供许多VM,而不必逐行列出 --- - name: Create VM based on template hosts: ovirt-engine become: yes become_method: sudo vars: - temp: '{
---
- name: Create VM based on template
hosts: ovirt-engine
become: yes
become_method: sudo
vars:
- temp: '{{temp_fedora25}}'
- iname:
- db-aa
- db-ab
- db-ac
tasks:
- name: Giving Birth to lil Baby VM's
ovirt:
user: '{{ovirt_usr}}'
password: '{{ovirt_pass}}'
url: '{{engine_url}}'
instance_name: "{{item}}"
instance_nic: ovirtmgmt
resource_type: template
image: '{{temp}}'
zone: superblade-a
disk_alloc: preallocated
with_items: "{{iname}}"
您可以使用查找:
您可以在vars部分跳过
set_fact
并定义my_seq
,但如果您大量使用my_seq
,则每次都会在内部生成列表。使用set\u事实
列表生成一次。关于Konstantin的正确答案,我将根据我的案例添加完整的解决方案
我的目标是能够将序列值作为注册变量重用,以便将实例名传递给主机名。到目前为止,这是可行的,但我确信它可以通过嵌套变量来简化
---
- name: Create VM based on template
hosts: ovirt-engine
become: yes
become_method: sudo
vars:
- temp: '{{temp_fedora25}}'
- host_pre: db
- host_seq: a%c
- host_cnt: 3
- host_srt: 0x61
tasks:
- name: Giving Birth to lil Baby VM's
ovirt:
user: '{{ovirt_usr}}'
password: '{{ovirt_pass}}'
url: '{{engine_url}}'
instance_name: "{{item}}"
instance_nic: ovirtmgmt
resource_type: template
image: '{{temp}}'
zone: superblade-a
disk_alloc: preallocated
with_sequence: start="{{host_srt}}" count="{{host_cnt}}" format="{{host_pre}}-{{host_seq}}"
是的,就在文档中…效果很好,当然我的案例中有一些调整。我想知道这些值是否可以作为注册变量重用?我用我的完整解决方案添加了另一个答案,只是为了更全面。添加了
set\u fact
的示例。Super…起到了作用。我必须放大我的剧本来测试这些变量的传递。
---
- name: Create VM based on template
hosts: ovirt-engine
become: yes
become_method: sudo
vars:
- temp: '{{temp_fedora25}}'
- host_pre: db
- host_seq: a%c
- host_cnt: 3
- host_srt: 0x61
tasks:
- name: Giving Birth to lil Baby VM's
ovirt:
user: '{{ovirt_usr}}'
password: '{{ovirt_pass}}'
url: '{{engine_url}}'
instance_name: "{{item}}"
instance_nic: ovirtmgmt
resource_type: template
image: '{{temp}}'
zone: superblade-a
disk_alloc: preallocated
with_sequence: start="{{host_srt}}" count="{{host_cnt}}" format="{{host_pre}}-{{host_seq}}"