首页 文章

使用动态库存文件(JSON)运行playbook

提问于
浏览
-1

我使用下面的动态库存文件(JSON)和Playbook YML . 我无法执行它 . 得到一个错误 . 需要你的输入 .

my_dynamic_inventory --list
{
    "_meta": {
        "hostvars": {
            Node_001": {
                "model_name":"router1",
                "ansible_user":"xxx",
                "ansible_password":"xxx",
                "ansible_port":"20",
                "ansible_host":"172.xx.xx.xx",
                "snmp_version":"2c",
                "snmp_community":"public",
                "snmp_port":"yyyy",
                "stack_node_num":"5"
                "ansible_network_os":"moduleA"
            }
        },
    },
    "all": {
        "hosts": ["Node_001"]
    }
}

YML文件:

---
- hosts: all
  gather_facts: off
  connection: local
  tasks:
    - name: create vlan entry
      necqx_vlan:
        vlan_id: 194
        name: VLAN1
        state: present
        model: router1

当我使用动态库存文件执行游戏时,我遇到错误

[警告]:*无法使用ini插件解析/ Path_to_dynamic_inventory / dynamic_inventory:/ Path_to_dynamic_inventory / dynamic_inventory:1:预期的key =值主机变量赋值,得到: - list文件“/usr/lib/python2.7/site- packages / ansible / plugins / inventory / ini.py“,第132行,解析self._parse(路径,数据)文件”/usr/lib/python2.7/site-packages/ansible/plugins/inventory/ini.py “,第210行,在_parse主机,端口,变量= self._parse_host_definition(行)文件”/usr/lib/python2.7/site-packages/ansible/plugins/inventory/ini.py“,第308行,在_parse_host_definition中self._raise_error(“预期密钥=值主机变量赋值,得到:%s”%(t))文件“/usr/lib/python2.7/site-packages/ansible/plugins/inventory/ini.py”,行137,在_raise_error中引发AnsibleError(“%s:%d:”%(self._filename,self.lineno)消息)[警告]:无法解析/ Path_to_dynamic_inventory / dynamic_inventory作为库存源[警告]:未解析库存,只有隐式localhost可用[W ARNING]:提供的主机列表为空,只有localhost可用 . 请注意,隐式localhost与'all'不匹配.... ... PLAY [all] **************************** ************************************************** ********************************跳过:没有主机匹配

1 回答

  • 0

    在生成的json中似乎存在一些拼写错误 . 像更多的错误消息,给出的是非常神秘的 . 我会在这样的情况下验证我的json . 尝试jsonlint cli或在线json验证器 .

    缺少逗号:

    "stack_node_num":"5"
    "ansible_network_os":"moduleA"
    

    缺少左括号:

    Node_001": {
    

相关问题