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

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

问题描述

有没有办法在使用 add_host 或 group_by 模块的配置任务期间创建内存清单,例如:

[SET]1.1.1.1[设置:变量]ip_address={{inventory_hostname }}[设置1]1.1.1.2[设置:变量]ip_address={{inventory_hostname }}

解决方案

.您可以执行以下操作(如果您在问题中提供更多信息,我们可以自己提供更具体的信息):

- add_host:主机名:1.1.1.1组:SET- 添加主机:主机名:1.1.1.2组:SET1

这会将 1.1.1.1 作为 SET 组的一部分动态添加到清单中,并将 1.1.1.2 作为 SET1 组的一部分添加到清单中.在 rackspace

任务:

 - name:提供一组实例本地操作:模块:rax名称:{{ rax_name }}"风味:{{ rax_flavor }}"图像:{{ rax_image }}"计数:{{ rax_count }}"组:{{组}}"等待:是的注册:rax- 名称:将我们创建的实例(通过公共 IP)添加到组 'raxhosts'本地操作:模块:add_host主机名:{{ item.name }}"ansible_host: "{{ item.rax_accessipv4 }}"ansible_ssh_pass: "{{ item.rax_adminpass }}"组:raxhostswith_items: "{{ rax.success }}"时间:rax.action == '创建'

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

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

tasks:

  - 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天全站免登陆