如何在Ansible Tower库存中将主机添加到组中? [英] How to add host to group in Ansible Tower inventory?

查看:289
本文介绍了如何在Ansible Tower库存中将主机添加到组中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用tower_grouptower_host模块将主机添加到组?

How can I add a host to a group using tower_group or tower_host modules?

以下代码创建一个主机和一个组,但是它们彼此无关:

The following code creates a host and a group, but they are unrelated to each other:

---
- hosts: localhost
  connection: local
  gather_facts: false

  tasks:
    - tower_inventory:
        name: My Inventory
        organization: Default
        state: present
        tower_config_file: "~/tower_cli.cfg"

    - tower_host:
        name: myhost
        inventory: My Inventory
        state: present
        tower_config_file: "~/tower_cli.cfg"

    - tower_group:
        name: mygroup
        inventory: My Inventory
        state: present
        tower_config_file: "~/tower_cli.cfg"

文档提及instance_filters参数(以逗号分隔的匹配主机的过滤器表达式列表."),但是未提供任何用法示例.

Docs mention instance_filters parameter ("Comma-separated list of filter expressions for matching hosts."), however do not provide any usage example.

tower_group任务中添加instance_filters: myhost无效.

推荐答案

我使用Ansible shell模块和tower-cli解决了它.我知道创建一个ansible模块要比它更好,但是要有一个快速的解决方案...

I solved it using Ansible shell module and tower-cli. I Know that create a ansible module is better than it, but to a fast solution...

- hosts: awx
  vars:
  tasks: 
   - name: Create Inventory
     tower_inventory:
       name: "Foo Inventory"
       description: "Our Foo Cloud Servers"
       organization: "Default"
       state: present
   - name: Create Group
     tower_group: 
       inventory: "Foo Inventory" 
       name:  Testes 
     register: fs_group 
   - name: Create Host
     tower_host:
       inventory: "Foo Inventory" 
       name: "host"  
     register: fs_host 
   - name: Associate host group 
     shell: tower-cli host associate  --host "{{fs_host.id}}" --group "> {{fs_group.id}}"

这篇关于如何在Ansible Tower库存中将主机添加到组中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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