【问题标题】:How to use and format Dynamic Inventory - Ansible如何使用和格式化动态库存 - Ansible
【发布时间】:2019-03-24 15:39:57
【问题描述】:

尝试格式化有效的动态库存。这是怎么做到的?

这是一个脚本,它将获取 terraform 的状态文件并使其成为可用的库存。我需要知道 Ansible 中使用的动态清单的格式。
我尝试运行以下库存:ansible all -i test.json -m ping

{
    "_meta": {
        "hostvars": { }
    },

    "instances": {
        "hosts": ["10.66.70.33"]
    }
}

结果:

 [WARNING]:  * Failed to parse /etc/ansible/test.json with yaml plugin: Invalid "hosts" entry for "instances" group,
requires a dictionary, found "<type 'list'>" instead.

 [WARNING]:  * Failed to parse /etc/ansible/test.json with ini plugin: /etc/ansible/test.json:2: Expected
key=value host variable assignment, got: {

 [WARNING]: Unable to parse /etc/ansible/test.json as an inventory source

 [WARNING]: No inventory was parsed, only implicit localhost is available

{ | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname {: Temporary failure in name resolution", 
    "unreachable": true
}

【问题讨论】:

    标签: ansible ansible-inventory


    【解决方案1】:

    找到一种有效的格式:

    {
       "all": {
          "hosts": "10.66.70.33",
          "children": {
             "instances": {
                "hosts": {
                   "10.66.70.33":
                }
             }
          }
       }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多