Generating a role's argument_specs.yml based on defaults

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. :smiling_face_with_tear:

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!

5 Likes

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 :frowning_face:) 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.

3 Likes

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 :+1: if you think that will help you!!

3 Likes

I’d be interested in this, too!
I recently took over a tool to automatically create a roles’ readme from the meta-information and argument_specs, so this would be a nice addition.

1 Like

Just Fyi some links:

Add allow conversion for validate_argument_spec by tanganellilore · Pull Request #82190 · ansible/ansible · GitHub (colesd in favour of draft pr)
Add support for X_strict types in argspec by sivel · Pull Request #81575 · ansible/ansible · GitHub