# Generating a role's argument\_specs.yml based on defaults

**URL:** <https://forum.ansible.com/t/generating-a-roles-argument-specs-yml-based-on-defaults/2208>\
**Category:** Get Help\
**Tags:** role\
**Created:** [November 7, 2023, 4:52pm UTC](https://forum.ansible.com/t/generating-a-roles-argument-specs-yml-based-on-defaults/2208 "2023-11-07T16:52:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SaasyEngineer](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/saasyengineer/32/417_2.png) [@SaasyEngineer](https://forum.ansible.com/u/SaasyEngineer)\
**Post date:** [November 7, 2023, 4:52pm UTC](https://forum.ansible.com/t/generating-a-roles-argument-specs-yml-based-on-defaults/2208/1 "2023-11-07T16:52:28Z")

</div>

Hey all,

My team maintains about ~60 Ansible roles internally and for reasons I won’t get into, we are just now upgrading to Ansible 2.15 from 2.10. 🥲

This upgrade gives us the ability to leverage argument\_specs, which I think is going to be essential for our CI plans since it gives us a way to contract test our roles. The current plan is to go back and update all of our roles with said argument\_specs - which is definitely a lot of work.

My question - is anyone aware of a tool that can scrape an Ansible role’s default vars and generate at least a partial argument\_specs.yml? If not, i’m thinking we may develop something like this.

Thank You!

---

<div class="post-metadata">

**Author:** ![tanganellilore](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tanganellilore/32/178_2.png) [@tanganellilore](https://forum.ansible.com/u/tanganellilore)\
**Post date:** [November 8, 2023, 9:50pm UTC](https://forum.ansible.com/t/generating-a-roles-argument-specs-yml-based-on-defaults/2208/2 "2023-11-08T21:50:37Z")

</div>

Hi,

In my company we do something similar but for readme of the role.

We scarpe the role and we add variable with respective comment in a table of readme.  
For required variable we also scrape the yml file and we check the assert /fail module to understand what is mandatory.

I thinking to add/migrate also our roles to argument\_spec and also to use the “auto” asseriton but (there is a but ☹) this is very poor in terms of asseriton and control.

Code is internal and I can’t share it, but is very simple python that load default file and read lines with comment and for assert/fail load it as a pure yaml.

---

<div class="post-metadata">

**Author:** ![tanganellilore](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tanganellilore/32/178_2.png) [@tanganellilore](https://forum.ansible.com/u/tanganellilore)\
**Post date:** [November 10, 2023, 10:15pm UTC](https://forum.ansible.com/t/generating-a-roles-argument-specs-yml-based-on-defaults/2208/3 "2023-11-10T22:15:51Z")

</div>

Hi,  
I open a issue with PR on ansible side to start some “rework” on argument\_spec in a way to enfocer strict object. I think that in this way this features will be come very, very usefull.  
Follow it and 👍 if you think that will help you!!

---

<div class="post-metadata">

**Author:** ![rndmh3ro](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/rndmh3ro/32/269_2.png) [@rndmh3ro](https://forum.ansible.com/u/rndmh3ro)\
**Post date:** [December 4, 2023, 10:50am UTC](https://forum.ansible.com/t/generating-a-roles-argument-specs-yml-based-on-defaults/2208/4 "2023-12-04T10:50:47Z")

</div>

I’d be interested in this, too!  
I recently took over a [tool](https://github.com/telekom-mms/Automated-Ansible-Role-Documentation) to automatically create a roles’ readme from the meta-information and argument\_specs, so this would be a nice addition.

---

<div class="post-metadata">

**Author:** ![tanganellilore](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tanganellilore/32/178_2.png) [@tanganellilore](https://forum.ansible.com/u/tanganellilore)\
**Post date:** [January 5, 2024, 9:30pm UTC](https://forum.ansible.com/t/generating-a-roles-argument-specs-yml-based-on-defaults/2208/5 "2024-01-05T21:30:08Z")

</div>

Just Fyi some links:

> <https://github.com/ansible/ansible/issues/82186>
>
> \### Summary
> 
> Hi team,
> 
> I notice that the in the validate\_argument\_spec module,… when we validate a list, validation try to convert it in a list and in case of int or boolean (in python bool is intended as int with \`isinstance\` function) will be "casted" to string: https://github.com/ansible/ansible/blob/667526c22ff59bbe7bc790bf505b7f09cae3856f/lib/ansible/module\_utils/common/validation.py#L390-L410
> 
> This is intended?
> 
> Moreover there is a way to force the "strict" validation instead a validation that try to "convert" data?
> Something like \`allow\_conversion\` that i see in \`check\_type\_str\` but that is not used by \`validate\_argument\_spec\`.
> 
> Becuase in that way we can strict the value and/or use it in the module as parameters (or add it as keyof model), to have a strinct check .
> 
> Thanks
> 
> 
> 
> \### Issue Type
> 
> Bug Report
> 
> \### Component Name
> 
> validate\_argument\_spec
> 
> \### Ansible Version
> 
> \`\`\`console
> ansible \[core 2.15.1\]
> python version = 3.10.6
> jinja version = 3.1.2
> libyaml = True
> \`\`\`
> 
> 
> \### Configuration
> 
> \`\`\`console
> CACHE\_PLUGIN(/etc/ansible/ansible.cfg) = jsonfile
> CACHE\_PLUGIN\_CONNECTION(/etc/ansible/ansible.cfg) = /tmp/facts\_cache
> CACHE\_PLUGIN\_TIMEOUT(/etc/ansible/ansible.cfg) = 7200
> CONFIG\_FILE() = /etc/ansible/ansible.cfg
> DEFAULT\_GATHERING(/etc/ansible/ansible.cfg) = smart
> 
> CACHE:
> =====
> 
> jsonfile:
> \_\_\_\_\_\_\_\_
> \_timeout(/etc/ansible/ansible.cfg) = 7200
> \_uri(/etc/ansible/ansible.cfg) = /tmp/facts\_cache
> \`\`\`
> 
> 
> \### OS / Environment
> 
> Ubuntu 22.04
> 
> \### Steps to Reproduce
> 
> 
> \`\`\`yaml (paste below)
> \- name: Test
> hosts: localhost
> vars:
> params:
> add\_options: true
> tasks:
> - name: verify 
> ansible.builtin.validate\_argument\_spec:
> argument\_spec: '{{ required\_data }}'
> provided\_arguments: "{{ params }}"
> vars:
> required\_data:
> add\_options:
> type: list
> default: \[\]
> elements: str
> \`\`\`
> 
> 
> \### Expected Results
> 
> Task will fail because:
> 
> 1. Type of add\_options is boolean
> 2. If will be performet a convertion of single element in a list, i'm expect that element in list will be boolean, but is converted to string
> 
> 
> \### Actual Results
> 
> \`\`\`console
> Task will pass
> \`\`\`
> 
> 
> \### Code of Conduct
> 
> \- \[X\] I agree to follow the Ansible Code of Conduct

[Add allow conversion for validate\_argument\_spec by tanganellilore · Pull Request #82190 · ansible/ansible · GitHub](https://github.com/ansible/ansible/pull/82190) (colesd in favour of draft pr)  
[Add support for X\_strict types in argspec by sivel · Pull Request #81575 · ansible/ansible · GitHub](https://github.com/ansible/ansible/pull/81575)
