ansible:使用add_host或group_by创建具有多个组的临时清单 [英] ansible: create temporary inventory with multiple groups with add_host or group_by

查看:113
本文介绍了ansible:使用add_host或group_by创建具有多个组的临时清单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用add_host或group_by模块进行配置任务期间,是否有任何方法可以创建内存清单:

Is there any way to create an in memory inventory during provisioning tasks with add_host or group_by modules such:

[SET]
1.1.1.1
[SET:vars]

ip_address={{ inventory_hostname }}

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

推荐答案

Yes. You can do something like this (if you provide more information in your question, we can provide more specificity ourselves):

- 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 组的一部分.在机架空间

This will dynamically add 1.1.1.1 to the inventory as part of the SET group and 1.1.1.2 to the inventory as part of the SET1 group. there are a couple of good example of doing this during provision steps for 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'

这篇关于ansible:使用add_host或group_by创建具有多个组的临时清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆