如何在Ansible Tower库存中添加主机到组?

问题描述 投票:2回答:1

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

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

---
- 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参数(“用于匹配主机的过滤器表达式的逗号分隔列表。”),但是不提供任何用法示例。

instance_filters: myhost添加到tower_group任务中没有任何效果。

ansible ansible-tower
1个回答
0
投票

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

- 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}}"
© www.soinside.com 2019 - 2024. All rights reserved.