ansible - 如何将主机添加到 Ansible Tower 库存中的组?

标签 ansible ansible-tower

如何使用 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 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/

相关文章:

ansible - Ansible AWX/Tower 可以使用来自外部源/Git 存储库的 group_vars 和 host_vars 吗?

ansible - 为单个组中的多个主机运行 playbook 的 sudo 密码

php - 通过具有幂等性的 Ansible 安装 PHP Pear 包

Ansible 塔 : How to pass job number into playbook?

python-3.x - Ansible - 使用 with_items 访问 shell 命令的输出

ansible - 复制模块 "content"仅适用于变量, "src"仅适用于文件,如何让它同时适用于两者?

ansible - 如何从包含 YAML 的字符串中读取 Ansible 变量?

loops - Ansible 和循环中的嵌套变量

module - "command"或 Ansible 中特定模块执行之间的差异

Ansible Tower 获取文件作业返回正常,但本地计算机上不存在文件