# check if the previous fields input is given by the user

**URL:** <https://forum.ansible.com/t/check-if-the-previous-fields-input-is-given-by-the-user/24013>\
**Category:** Ansible Developer\
**Created:** [March 20, 2017, 9:22am UTC](https://forum.ansible.com/t/check-if-the-previous-fields-input-is-given-by-the-user/24013 "2017-03-20T09:22:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abdul\_Hafeezuddin\_Mo](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@Abdul\_Hafeezuddin\_Mo](https://forum.ansible.com/u/Abdul_Hafeezuddin_Mo)\
**Post date:** [March 20, 2017, 9:22am UTC](https://forum.ansible.com/t/check-if-the-previous-fields-input-is-given-by-the-user/24013/1 "2017-03-20T09:22:31Z")

</div>

Hi,  
I’m writing a custom module. I wanted to set some fields to “required”: True, depending upon the previous field i.e if user specified previous field then next field should be set to required:True  
please see this below example and help me!

```auto
def main():

  fields = {
        "name": {"required": True, "type": "str" },
        "description": {"required": False, "type": "str"},
        "storage": {"type": "str" },
        "capacity": { # Here it should become "required": True if and only if user specifies
 storage[in play.yml] else it should be "required":False},
    }

    module = AnsibleModule(argument_spec=fields)
    module.exit_json(changed=False, meta=module.params)

```

```auto

```

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [March 20, 2017, 4:31pm UTC](https://forum.ansible.com/t/check-if-the-previous-fields-input-is-given-by-the-user/24013/2 "2017-03-20T16:31:04Z")

</div>

I think you’d have to make a specific check for this in your code and Fail if neither storage or capacity were supplied.

Jon
