You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
872 B
26 lines
872 B
![]()
4 years ago
|
---
|
||
|
|
||
|
# Check if a password has already been created
|
||
|
- name: Check if password exists
|
||
|
stat: path={{ pass_file }}
|
||
|
register: current_pass
|
||
|
|
||
|
# When no pass exist, create a new one
|
||
|
- yum: name=pwgen
|
||
|
when: not current_pass.stat.exists and ansible_os_family == 'RedHat'
|
||
|
- apt: name=pwgen
|
||
|
when: not current_pass.stat.exists and ansible_os_family == 'Debian'
|
||
|
- shell: pwgen {% if complex | default(True) %}-y {% endif %}-s {{ pass_size | default(50) }} 1 | sed -e 's/[\"\`'"'"']//g'
|
||
|
register: rand_pass
|
||
|
when: not current_pass.stat.exists
|
||
|
# Now write this new pass
|
||
|
- copy: content={{ rand_pass.stdout | trim }} dest={{ pass_file }} mode=600
|
||
|
when: not current_pass.stat.exists
|
||
|
|
||
|
# When pass already exists, just read it
|
||
|
- name: Read the password
|
||
|
slurp: src={{ pass_file }}
|
||
|
register: rand_pass
|
||
|
- set_fact: rand_pass={{ rand_pass.content | b64decode | trim }}
|
||
|
|