- name: Step 000 Pre Infrastructure
|
hosts: localhost
|
connection: local
|
become: false
|
tags:
|
- step001
|
- pre_infrastructure
|
tasks:
|
- name: if windows_password is not defined, generate one
|
when: windows_password is not defined
|
block:
|
- name: Stat workdir/[...]_windows_password.txt file
|
stat:
|
path: "{{output_dir}}/{{ env_type }}_{{guid}}_windows_password.txt"
|
register: passwordfile
|
# This task needs to be "ansibled", we cannot assume tr exists
|
# This also doesn't work on MAC, that does have tr.
|
- name: Generate windows Administrator password if not already defined
|
command: openssl rand -base64 25
|
register: password_gen_r
|
when: not passwordfile.stat.exists
|
|
# TODO: use slurp
|
- name: Read windows password from workdir/[...]_windows_password.txt file
|
command: "cat '{{output_dir}}/{{ env_type }}_{{guid}}_windows_password.txt'"
|
register: password_get_r
|
changed_when: false
|
when: passwordfile.stat.exists
|
|
- name: set_fact windows_password (just generated)
|
set_fact:
|
generated_windows_password: "{{ password_gen_r.stdout }}"
|
windows_password: "{{ password_gen_r.stdout }}"
|
when: not passwordfile.stat.exists
|
|
- name: set_fact windows_password (previously generated)
|
set_fact:
|
generated_windows_password: "{{ password_get_r.stdout }}"
|
when: passwordfile.stat.exists
|
|
- name: Save windows_password or generated_windows_password into workdir/
|
copy:
|
content: "{{ windows_password | default(generated_windows_password) }}"
|
dest: "{{output_dir}}/{{ env_type }}_{{guid}}_windows_password.txt"
|
mode: 0600
|
|