I'm trying to create passwords variables with lookup('password')
and trying to respect this specific policy: foOBar1_FoO2Bar_3BarFoo
(for exemple)
regex: 7 characters from "digits,ascii_lowercase,ascii_uppercase
" repeated 2 two, separated by '_'
character
I wrote this:
---
- hosts: localhost
gather_facts: no
vars:
password_length: "7"
password_spec_str: "digits,ascii_lowercase,ascii_uppercase"
tasks:
- name: "Generate 2 randoms passwords"
set_fact:
FirstPass: "{{ lookup('password', '/dev/null length=' ~ password_length ~ ' chars=' ~ password_spec_str ) + '_' + lookup('password', '/dev/null length=' ~ password_length ~ ' chars=' ~ password_spec_str ) + '_' + lookup('password', '/dev/null length=' ~ password_length ~ ' chars=' ~ password_spec_str ) }}"
SecondPass: "{{ lookup('password', '/dev/null length=' ~ password_length ~ ' chars=' ~ password_spec_str ) + '_' + lookup('password', '/dev/null length=' ~ password_length ~ ' chars=' ~ password_spec_str ) + '_' + lookup('password', '/dev/null length=' ~ password_length ~ ' chars=' ~ password_spec_str ) }}"
...
Results :
PLAY [localhost] ***************************************************************************************************************************************************************************************************************************************
TASK [Generate 2 randoms passwords] ********************************************************************************************************************************************************************************************************************
mardi 26 juillet 2022 16:26:05 +0200 (0:00:00.020) 0:00:00.020 *********
ok: [localhost] => changed=false
ansible_facts:
FirstPass: WqUjDBf_NDPX5zQ_YRnhaAP
SecondPass: RGBkrIM_t9zS8tB_iCFrp3E
PLAY RECAP *********************************************************************************************************************************************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Playbook run took 0 days, 0 hours, 0 minutes, 0 seconds
So the result suits me perfectly, but not the way to write that..
Does anyone have another idea to 'beautify' this set_fact ?
Thanks !