| 1 |
- name: create a password file |
| 2 |
set_fact: |
| 3 |
newpass: "{{ lookup('password', output_dir + '/lookup/password length=8') }}" |
| 4 |
|
| 5 |
- name: stat the password file directory |
| 6 |
stat: path="{{output_dir}}/lookup" |
| 7 |
register: result |
| 8 |
|
| 9 |
- name: assert the directory's permissions |
| 10 |
assert: |
| 11 |
that: |
| 12 |
- result.stat.mode == '0700' |
| 13 |
|
| 14 |
- name: stat the password file |
| 15 |
stat: path="{{output_dir}}/lookup/password" |
| 16 |
register: result |
| 17 |
|
| 18 |
- name: assert the directory's permissions |
| 19 |
assert: |
| 20 |
that: |
| 21 |
- result.stat.mode == '0600' |
| 22 |
|
| 23 |
- name: get password length |
| 24 |
shell: wc -c {{output_dir}}/lookup/password | awk '{print $1}' |
| 25 |
register: wc_result |
| 26 |
|
| 27 |
- debug: var=wc_result.stdout |
| 28 |
|
| 29 |
- name: read password |
| 30 |
shell: cat {{output_dir}}/lookup/password |
| 31 |
register: cat_result |
| 32 |
|
| 33 |
- debug: var=cat_result.stdout |
| 34 |
|
| 35 |
- name: verify password |
| 36 |
assert: |
| 37 |
that: |
| 38 |
- "wc_result.stdout == '9'" |
| 39 |
- "cat_result.stdout == newpass" |
| 40 |
- "' salt=' not in cat_result.stdout" |
| 41 |
|
| 42 |
- name: fetch password from an existing file |
| 43 |
set_fact: |
| 44 |
pass2: "{{ lookup('password', output_dir + '/lookup/password length=8') }}" |
| 45 |
|
| 46 |
- name: read password (again) |
| 47 |
shell: cat {{output_dir}}/lookup/password |
| 48 |
register: cat_result2 |
| 49 |
|
| 50 |
- debug: var=cat_result2.stdout |
| 51 |
|
| 52 |
- name: verify password (again) |
| 53 |
assert: |
| 54 |
that: |
| 55 |
- "cat_result2.stdout == newpass" |
| 56 |
- "' salt=' not in cat_result2.stdout" |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
- name: create a password (with salt) file |
| 61 |
debug: msg={{ lookup('password', output_dir + '/lookup/password_with_salt encrypt=sha256_crypt') }} |
| 62 |
|
| 63 |
- name: read password and salt |
| 64 |
shell: cat {{output_dir}}/lookup/password_with_salt |
| 65 |
register: cat_pass_salt |
| 66 |
|
| 67 |
- debug: var=cat_pass_salt.stdout |
| 68 |
|
| 69 |
- name: fetch unencrypted password |
| 70 |
set_fact: |
| 71 |
newpass: "{{ lookup('password', output_dir + '/lookup/password_with_salt') }}" |
| 72 |
|
| 73 |
- debug: var=newpass |
| 74 |
|
| 75 |
- name: verify password and salt |
| 76 |
assert: |
| 77 |
that: |
| 78 |
- "cat_pass_salt.stdout != newpass" |
| 79 |
- "cat_pass_salt.stdout.startswith(newpass)" |
| 80 |
- "' salt=' in cat_pass_salt.stdout" |
| 81 |
- "' salt=' not in newpass" |
| 82 |
|
| 83 |
|
| 84 |
- name: fetch unencrypted password (using empty encrypt parameter) |
| 85 |
set_fact: |
| 86 |
newpass2: "{{ lookup('password', output_dir + '/lookup/password_with_salt encrypt=') }}" |
| 87 |
|
| 88 |
- name: verify lookup password behavior |
| 89 |
assert: |
| 90 |
that: |
| 91 |
- "newpass == newpass2" |
| 92 |
|
| 93 |
- name: verify that we can generate a 1st password without writing it |
| 94 |
set_fact: |
| 95 |
newpass: "{{ lookup('password', '/dev/null') }}" |
| 96 |
|
| 97 |
- name: verify that we can generate a 2nd password without writing it |
| 98 |
set_fact: |
| 99 |
newpass2: "{{ lookup('password', '/dev/null') }}" |
| 100 |
|
| 101 |
- name: verify lookup password behavior with /dev/null |
| 102 |
assert: |
| 103 |
that: |
| 104 |
- "newpass != newpass2" |
| 105 |
|
| 106 |
- name: test both types of args and that seed guarantees same results |
| 107 |
vars: |
| 108 |
pns: "{{passwords_noseed['results']}}" |
| 109 |
inl: "{{passwords_inline['results']}}" |
| 110 |
kv: "{{passwords['results']}}" |
| 111 |
l: [1, 2, 3] |
| 112 |
block: |
| 113 |
- name: generate passwords w/o seed |
| 114 |
debug: |
| 115 |
msg: '{{ lookup("password", "/dev/null")}}' |
| 116 |
loop: "{{ l }}" |
| 117 |
register: passwords_noseed |
| 118 |
|
| 119 |
- name: verify they are all different, this is not guaranteed, but statistically almost impossible |
| 120 |
assert: |
| 121 |
that: |
| 122 |
- pns[0]['msg'] != pns[1]['msg'] |
| 123 |
- pns[0]['msg'] != pns[2]['msg'] |
| 124 |
- pns[1]['msg'] != pns[2]['msg'] |
| 125 |
|
| 126 |
- name: generate passwords, with seed inline |
| 127 |
debug: |
| 128 |
msg: '{{ lookup("password", "/dev/null seed=foo")}}' |
| 129 |
loop: "{{ l }}" |
| 130 |
register: passwords_inline |
| 131 |
|
| 132 |
- name: verify they are all the same |
| 133 |
assert: |
| 134 |
that: |
| 135 |
- inl[0]['msg'] == inl[1]['msg'] |
| 136 |
- inl[0]['msg'] == inl[2]['msg'] |
| 137 |
|
| 138 |
- name: generate passwords, with seed k=v |
| 139 |
debug: |
| 140 |
msg: '{{ lookup("password", "/dev/null", seed="foo")}}' |
| 141 |
loop: "{{ l }}" |
| 142 |
register: passwords |
| 143 |
|
| 144 |
- name: verify they are all the same |
| 145 |
assert: |
| 146 |
that: |
| 147 |
- kv[0]['msg'] == kv[1]['msg'] |
| 148 |
- kv[0]['msg'] == kv[2]['msg'] |
| 149 |
- kv[0]['msg'] == inl[0]['msg'] |