Check password matches the condition in Ansible

Viewed 119

I am creating admin user account by prompting for user input through Ansible. This admin account

vars_prompt:
  - name: "Username"
    prompt:  "Enter the administrator username"
    private: no

  - name: "Password"
    prompt: "Enter the administrator password.Password must contain at least 8 total printable ASCII character(s)."
    private: yes

  - name: "Confirm_Password"
    prompt: Confirm Password
    private: yes

I want to check if the password length is greater or equal to 8 and it contains only ASCII chars.

I tried something like this:

- name : Password matches the splunk condition
  assert:
    that:
      - Password | length >= 8 and chars=ascii_letters
    success_msg: "Passed."
    fail_msg: "New password is too short!"
    quiet: true
  tags: password_check

But it isn't working.

1 Answers

Q: "Test if password length is greater or equal to 8 and it contains only ASCII chars."

A: The limitation to all ASCII characters is not practical. The regex below limits the string to 8 or more printable ASCII characters. See Regex for all PRINTABLE characters

    - assert:
        that: Password is match('^[ -~]{8,}$')
        fail_msg: "Password: {{ Password }} does not comply!"
        quiet: true
Related