Jim Rigsbee
2020-02-13 1e2288d704cc7b308efca749072d6f9df86fa986
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
- 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