2016-12-17 112 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'