【问题标题】:List all ansible hosts from inventory file for a task列出任务的清单文件中的所有 ansible 主机
【发布时间】:2013-12-29 18:39:03
【问题描述】:

对于备份,我需要遍历清单文件中的所有主机,以确保备份目标存在。我的结构看起来像

/var/backups/
            example.com/
            sub.example.com/

所以我需要一个(内置)变量/方法来列出清单文件中的所有主机,而不仅仅是一个组。

对于组,它看起来像这样

- name: ensure backup directories are present
  action: file path=/var/backups/{{ item }} state=directory
          owner=backup group=backup mode=0700
  with_items: groups['group_name']
  tags:
    - backup

【问题讨论】:

    标签: ansible ansible-playbook ansible-inventory


    【解决方案1】:

    这就是解决方案:

    with_items: groups['all']
    

    【讨论】:

    • 不幸的是,“item”似乎是一个字符串而不是库存项目。例如,您将如何访问 item.inventory_hostname?
    • 也许您想访问主机变量?例如 hostvars[item]["ansible_os_family"]。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-13
    • 1970-01-01
    相关资源
    最近更新 更多