2016-12-17 52 views
0

多个组临时库存有没有办法跟add_host或GROUP_BY模块,部署任务时创建一个在内存中盘点:ansible:创建与add_host或GROUP_BY

[SET] 
1.1.1.1 
[SET:vars] 

ip_address={{ inventory_hostname }} 

[SET1] 
1.1.1.2 
[SET:vars] 
ip_address={{ inventory_hostname }} 
+0

你所说的“部署任务”是什么意思? – techraf

回答

0

Yes。你可以做这样的事情(如果你提供你的问题的更多信息,我们可以提供更多的特异性自己):

- add_host: 
    hostname: 1.1.1.1 
    groups: SET 
- add_host: 
    hostname: 1.1.1.2 
    groups: SET1 

这将动态地添加1.1.1.1到库存为SET组和1.1的一部分。 1.2库存作为SET1组的一部分。有在规定步骤一对夫妇这样做的很好的例子为rackspace

任务:

- name: Provision a set of instances 
    local_action: 
     module: rax 
     name: "{{ rax_name }}" 
     flavor: "{{ rax_flavor }}" 
     image: "{{ rax_image }}" 
     count: "{{ rax_count }}" 
     group: "{{ group }}" 
     wait: yes 
    register: rax 
    - name: Add the instances we created (by public IP) to the group 'raxhosts' 
    local_action: 
     module: add_host 
     hostname: "{{ item.name }}" 
     ansible_host: "{{ item.rax_accessipv4 }}" 
     ansible_ssh_pass: "{{ item.rax_adminpass }}" 
     groups: raxhosts 
    with_items: "{{ rax.success }}" 
    when: rax.action == 'create'