FilBot3
FilBot3

Reputation: 3708

Ansible Module Development argument_spec Specification

While reading the Ansible Module Development, I did not see any references to what the argument_spec specification should be. I figured I would look into the code base and see if the argument_spec would be documented, but the GitHub ansible/ansible basic.py file doesn't have much in the way of a argument specification. What should be in there? The closest I can find is where an older document shows this bit of code from the Ansible 2.3 Dev Guide

module = AnsibleModule(
   argument_spec = dict(
       state     = dict(default='present', choices=['present', 'absent']),
       name      = dict(required=True),
       enabled   = dict(required=True, type='bool'),
       something = dict(aliases=['whatever'])
   )
)

Would I be correct in assuming that the full argument_spec specification is

module = AnsibleModule(
    argument_spec = {
        default  = 'default_value',
        type     = 'str',
        required = True,
        aliases  = ['dv', 'value'],
        choices  = ['default_value', 'strings', 'test']
    }
)

Upvotes: 4

Views: 7289

Answers (1)

Konstantin Suvorov
Konstantin Suvorov

Reputation: 68269

There is more or less complete description of argument spec in the documentation: https://docs.ansible.com/ansible/latest/dev_guide/developing_program_flow_modules.html#argument-spec.

At the time of writing available fields are: type, elements, default, fallback, choices, required, no_log, aliases, options, apply_defaults, removed_in_version.

Upvotes: 8

Related Questions