Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible Module Development argument_spec Specification

Tags:

ansible

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']
    }
)
like image 344
FilBot3 Avatar asked Oct 18 '25 07:10

FilBot3


1 Answers

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.

like image 121
Konstantin Suvorov Avatar answered Oct 21 '25 05:10

Konstantin Suvorov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!