我想针对不同的主机使用角色结构运行一个简单的Ansible脚本,其变量存储在不同的文件中。 假设我们已将host1和host2定义为主机。 例如,这将是主要角色文件(/home/dante/roles/project/main.yml):
--- #New network
- name: network
hosts: host1, host2
gather_facts: false
vars_files:
- /home/dante/roles/project/variables/network-1.yml
- /home/dante/roles/project/variables/network-2.yml
roles:
- project
位于/home/dante/roles/project/tasks/main.yml上的任务文件如下所示:
--- #task
- name: Create the networks
os_network:
cloud: "{{ item.cloud }}"
state: present
name: "{{ item.network }}"
with_items:
- "{{ networks }}"
tags: create_networks
第一个变量文件:
--- # /home/dante/roles/project/variables/network-1.yml
networks:
- { cloud: tenant1, network: network-1 }
- { cloud: tenant1, network: network-2 }
第二个变量文件:
--- # /home/dante/roles/project/variables/network-2.yml
networks:
- { cloud: tenant2, network: network-3 }
- { cloud: tenant2, network: network-4 }
是否有任何方法可以以迭代方式针对每个主机创建Openstack网络?例如,对于host1 =>仅应用network-1.yml中的变量文件,对于host 2 =>仅应用network2-2.yml中的变量?