Assert in ansible playbook

33 views
Skip to first unread message

Shivani Arora

unread,
May 31, 2022, 10:27:07 AM5/31/22
to Ansible Project
Hi All,

I'm creating a playbook which validates user input.

Input string would be something like :  "cluster-test-1"

I want to assert that input has only lowercase, digits or hypen. (No other special character is allowed)

Please suggest how I can achieve this, so that the playbook exits if input validation is failed.

Thanks,
Shivani

Dick Visser

unread,
May 31, 2022, 2:06:29 PM5/31/22
to ansible...@googlegroups.com
How is the user input being supplied to the playbook?
> --
> You received this message because you are subscribed to the Google
> Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to ansible-proje...@googlegroups.com
> <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/05f9b75c-7d97-4f50-b595-2b55e7dfe270n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/05f9b75c-7d97-4f50-b595-2b55e7dfe270n%40googlegroups.com?utm_medium=email&utm_source=footer>.
OpenPGP_0x266713D4E6EF488D.asc
OpenPGP_signature

Abhijeet Kasurde

unread,
May 31, 2022, 11:07:31 PM5/31/22
to ansible...@googlegroups.com
I would do something like this -

 
---
- name: Prompt and validation demo
hosts: localhost
gather_facts: false
vars_prompt:

- name: release_version
prompt: "What is the release version (Allowed values a-z, 0-9, hyphen)?"
private: no
pre_tasks:
- name: Make sure version is ok
fail:
msg: >-
Release version is not formatted correctly.
when: not release_version is regex('^[a-z0-9\-]+$')
run_once: true

To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c7bc76a8-fef2-700f-4c8f-1b6242de9792%40gmail.com.


--
Thanks,
Abhijeet Kasurde
Reply all
Reply to author
Forward
0 new messages