| 1 |
# This file is part of Ansible |
| 2 |
|
| 3 |
# Copyright: (c) 2018, Wojciech Sciesinski <wojciech[at]sciesinski[dot]net> |
| 4 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 5 |
|
| 6 |
--- |
| 7 |
|
| 8 |
- name: check adding of repository defaults - check mode |
| 9 |
win_psrepository: |
| 10 |
name: "{{ repository_name }}" |
| 11 |
source: "{{ repository_source_location }}" |
| 12 |
state: present |
| 13 |
check_mode: True |
| 14 |
register: adding_repository_check |
| 15 |
|
| 16 |
- name: get result of adding repository defaults - check mode |
| 17 |
ansible.windows.win_shell: (Get-PSRepository -Name {{ repository_name | quote }} -ErrorAction SilentlyContinue | Measure-Object).Count |
| 18 |
changed_when: false |
| 19 |
register: result_adding_repository_check |
| 20 |
|
| 21 |
- name: test adding repository defaults - check mode |
| 22 |
assert: |
| 23 |
that: |
| 24 |
- adding_repository_check is changed |
| 25 |
- result_adding_repository_check.stdout_lines[0] == '0' |
| 26 |
|
| 27 |
- name: check adding repository defaults |
| 28 |
win_psrepository: |
| 29 |
name: "{{ repository_name }}" |
| 30 |
source: "{{ repository_source_location }}" |
| 31 |
state: present |
| 32 |
register: adding_repository |
| 33 |
|
| 34 |
- name: get result of adding repository defaults |
| 35 |
ansible.windows.win_shell: | |
| 36 |
$repo = Get-PSRepository -Name {{ repository_name | quote }} |
| 37 |
($repo | Measure-Object).Count |
| 38 |
$repo.SourceLocation |
| 39 |
$repo.InstallationPolicy |
| 40 |
register: result_adding_repository |
| 41 |
|
| 42 |
- name: test adding repository defaults |
| 43 |
assert: |
| 44 |
that: |
| 45 |
- adding_repository is changed |
| 46 |
- result_adding_repository.stdout_lines[0] == '1' |
| 47 |
- result_adding_repository.stdout_lines[1] == repository_source_location |
| 48 |
- result_adding_repository.stdout_lines[2] == 'Trusted' |
| 49 |
|
| 50 |
- name: check adding repository defaults - idempotent |
| 51 |
win_psrepository: |
| 52 |
name: "{{ repository_name }}" |
| 53 |
source: "{{ repository_source_location }}" |
| 54 |
state: present |
| 55 |
register: adding_repository_again |
| 56 |
|
| 57 |
- name: test check adding repository defaults - idempotent |
| 58 |
assert: |
| 59 |
that: |
| 60 |
- adding_repository_again is not changed |
| 61 |
|
| 62 |
- name: change InstallationPolicy - check mode |
| 63 |
win_psrepository: |
| 64 |
name: "{{ repository_name }}" |
| 65 |
source: "{{ repository_source_location }}" |
| 66 |
installation_policy: untrusted |
| 67 |
check_mode: True |
| 68 |
register: change_installation_policy_check |
| 69 |
|
| 70 |
- name: get result of change InstallationPolicy - check mode |
| 71 |
ansible.windows.win_shell: '(Get-PSRepository -Name {{ repository_name | quote }}).InstallationPolicy' |
| 72 |
changed_when: false |
| 73 |
register: result_change_installation_policy_check |
| 74 |
|
| 75 |
- name: test change InstallationPolicy - check mode |
| 76 |
assert: |
| 77 |
that: |
| 78 |
- change_installation_policy_check is changed |
| 79 |
- result_change_installation_policy_check.stdout | trim == 'Trusted' |
| 80 |
|
| 81 |
- name: change InstallationPolicy |
| 82 |
win_psrepository: |
| 83 |
name: "{{ repository_name }}" |
| 84 |
source: "{{ repository_source_location }}" |
| 85 |
installation_policy: untrusted |
| 86 |
register: change_installation_policy |
| 87 |
|
| 88 |
- name: get result of change InstallationPolicy |
| 89 |
ansible.windows.win_shell: '(Get-PSRepository -Name {{ repository_name | quote }}).InstallationPolicy' |
| 90 |
changed_when: false |
| 91 |
register: result_change_installation_policy |
| 92 |
|
| 93 |
- name: test change InstallationPolicy |
| 94 |
assert: |
| 95 |
that: |
| 96 |
- change_installation_policy is changed |
| 97 |
- result_change_installation_policy.stdout | trim == 'Untrusted' |
| 98 |
|
| 99 |
- name: change InstallationPolicy - idempotent |
| 100 |
win_psrepository: |
| 101 |
name: "{{ repository_name }}" |
| 102 |
source: "{{ repository_source_location }}" |
| 103 |
installation_policy: untrusted |
| 104 |
register: change_installation_policy_again |
| 105 |
|
| 106 |
- name: test change InstallationPolicy - idempotent |
| 107 |
assert: |
| 108 |
that: |
| 109 |
- change_installation_policy_again is not changed |
| 110 |
|
| 111 |
- name: change source - check mode |
| 112 |
win_psrepository: |
| 113 |
name: "{{ repository_name }}" |
| 114 |
source: "{{ repository_source_location2 }}" |
| 115 |
state: present |
| 116 |
check_mode: True |
| 117 |
register: change_source_check |
| 118 |
|
| 119 |
- name: get result of change source - check mode |
| 120 |
ansible.windows.win_shell: | |
| 121 |
$repo = Get-PSRepository -Name {{ repository_name | quote }} |
| 122 |
$repo.SourceLocation |
| 123 |
$repo.InstallationPolicy |
| 124 |
changed_when: False |
| 125 |
register: result_change_source_check |
| 126 |
|
| 127 |
- name: test change source - check mode |
| 128 |
assert: |
| 129 |
that: |
| 130 |
- change_source_check is changed |
| 131 |
- result_change_source_check.stdout_lines[0] == repository_source_location |
| 132 |
- result_change_source_check.stdout_lines[1] == 'Untrusted' |
| 133 |
|
| 134 |
- name: change source |
| 135 |
win_psrepository: |
| 136 |
name: "{{ repository_name }}" |
| 137 |
source: "{{ repository_source_location2 }}" |
| 138 |
state: present |
| 139 |
register: change_source |
| 140 |
|
| 141 |
- name: get result of change source |
| 142 |
ansible.windows.win_shell: | |
| 143 |
$repo = Get-PSRepository -Name {{ repository_name | quote }} |
| 144 |
$repo.SourceLocation |
| 145 |
$repo.InstallationPolicy |
| 146 |
changed_when: False |
| 147 |
register: result_change_source |
| 148 |
|
| 149 |
- name: test change source |
| 150 |
assert: |
| 151 |
that: |
| 152 |
- change_source is changed |
| 153 |
- result_change_source.stdout_lines[0] == repository_source_location2 |
| 154 |
- result_change_source.stdout_lines[1] == 'Untrusted' |
| 155 |
|
| 156 |
- name: remove repository - check mode |
| 157 |
win_psrepository: |
| 158 |
name: "{{ repository_name }}" |
| 159 |
state: absent |
| 160 |
check_mode: True |
| 161 |
register: removing_repository_check |
| 162 |
|
| 163 |
- name: get result of remove repository - check mode |
| 164 |
ansible.windows.win_shell: '(Get-PSRepository -Name {{ repository_name | quote }} -ErrorAction SilentlyContinue | Measure-Object).Count' |
| 165 |
changed_when: false |
| 166 |
register: result_removing_repository_check |
| 167 |
|
| 168 |
- name: test remove repository - check mode |
| 169 |
assert: |
| 170 |
that: |
| 171 |
- removing_repository_check is changed |
| 172 |
- result_removing_repository_check.stdout | trim == '1' |
| 173 |
|
| 174 |
- name: remove repository |
| 175 |
win_psrepository: |
| 176 |
name: "{{ repository_name }}" |
| 177 |
state: absent |
| 178 |
register: removing_repository |
| 179 |
|
| 180 |
- name: get result of remove repository |
| 181 |
ansible.windows.win_shell: '(Get-PSRepository -Name {{ repository_name | quote }} -ErrorAction SilentlyContinue | Measure-Object).Count' |
| 182 |
changed_when: false |
| 183 |
register: result_removing_repository |
| 184 |
|
| 185 |
- name: test remove repository |
| 186 |
assert: |
| 187 |
that: |
| 188 |
- removing_repository is changed |
| 189 |
- result_removing_repository.stdout | trim == '0' |
| 190 |
|
| 191 |
- name: remove repository - idempotent |
| 192 |
win_psrepository: |
| 193 |
name: "{{ repository_name }}" |
| 194 |
state: absent |
| 195 |
register: remove_repository_again |
| 196 |
|
| 197 |
- name: test remove repository - idempotent |
| 198 |
assert: |
| 199 |
that: |
| 200 |
- remove_repository_again is not changed |