如何使用tower_group
或tower_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 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}}"