ansiblezerotier

How do I write a list of dicts in yaml?


How can I achieve a list of dicts in yaml for Ansible? I'm trying to access an API for ZeroTier and update my network

The API Documentation says

ipAssignmentPools Array of objects (IPRange) Nullable Range of IP addresses for the auto assign pool

Below is what I want to achieve

{
    "ipAssignmentPools": [
        {
            "ipRangeEnd": "172.17.0.100",
            "ipRangeStart": "172.17.0.1"
        },
        {
            "ipRangeEnd": "172.18.0.254",
            "ipRangeStart": "172.18.0.1"
        }
    ]

}

My code:

ipAssignmentPools: 
  ipRangeStart:
    - 172.16.0.1
  ipRangeEnd:
    - 172.16.0.254

The result

{
    "ipAssignmentPools": {
        "ipRangeEnd": [
            "172.16.0.254"
        ],
        "ipRangeStart": [
            "172.16.0.1"
        ]
    }
}

How do I transform my expected json to a yaml structure?


Solution

  • yaml is a superset of json. You can use any json to yaml convertor like https://www.json2yaml.com/

    ---
    ipAssignmentPools:
      - ipRangeEnd: 172.17.0.100
        ipRangeStart: 172.17.0.1
      - ipRangeEnd: 172.18.0.254
        ipRangeStart: 172.18.0.1