Parse error when publishing to Galaxy

I just made my first Ansible collection but I’m getting this parse error when publishing it to Galaxy and I cannot figure out what is wrong with my DOCUMENTATION string.

ERROR! module stemid.powerdns.powerdns_record missing documentation (or could not parse documentation): stemid.powerdns.powerdns_record did not contain a DOCUMENTATION attribute
(/tmp/tmph46fhlgo/ansible_collections/stemid/powerdns/plugins/modules/powerdns_record.py). Unable to parse documentation in python file \'/tmp/tmph46fhlgo/ansible_collections/stemid/powerdns/plugins/modules/powerdns_record.py\': while parsing a block mapping\n  in
"<unicode string>", line 7, column 5\ndid not find expected key\n  in "<unicode string>", line 7, column 43. while parsing a block mapping\n  in "<unicode string>", line 7, column 5\ndid not find expected key\n  in "<unicode string>", line 7, column 43\n'

You can see the DOCUMENTATION block in question here on gitlab.com: plugins/modules/powerdns_record.py · main · Stefan Midjich / ansible-collection-powerdns · GitLab

Welcome to the forum, @stemid!

Did you run ansible-test sanity --docker -v first? I would assume that doesn’t pass either. It usually gives you better indications (not all of the tests, but its yamllint test will likely give you a more precise location).

The error is in RETURN, which is invalid YAML. The trailing comma in line 140 is the first error which makes it invalid.

Your RETURN documentation is invalid, in a spot (line 6, column 43) that lines up pretty well with the error:

record:
  description: A dictionary representing the PowerDNS record.
  type: dict
  returned: always
  sample:
    "name": "host01.internal.example.com.",
    "type": "A",
    "ttl": 86400,
    "records": [
        {
            "content": "192.168.1.234",
            "disabled": false
        }
    ],
    "comments": []

You can’t mix flow-style collection syntax into a block-style collection. The idiomatic way to write this would be:

record:
  description: A dictionary representing the PowerDNS record.
  type: dict
  returned: always
  sample:
    name: host01.internal.example.com.
    type: A
    ttl: 86400
    records:
      - content: 192.168.1.234
        disabled: false
    comments: []

Or, if you really want to do flow-style, add the missing delimiters:

record:
  description: A dictionary representing the PowerDNS record.
  type: dict
  returned: always
  sample: {
    "name": "host01.internal.example.com.",
    "type": "A",
    "ttl": 86400,
    "records": [
        {
            "content": "192.168.1.234",
            "disabled": false
        }
    ],
    "comments": []
  }

Thanks to both of you for teaching me about how to develop collections.

The issue was indeed in the RETURN statement.

I just took both DOCUMENTATION and RETURN out into a yaml file and ran yamllint on them until I was rid of all the errors. Now I have published a new file without errors.

There’s no need to run yamllint manually on files that contain copy’n’pasted parts of modules, when you can simply run ansible-test sanity --docker -v (with --test yamllint if you only want that test) :slight_smile: