如何使用 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}}"
关于ansible - 如何将主机添加到 Ansible Tower 库存中的组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51472573/