Debian Codegraph @

ansible_collections/community/windows/tests/integration/targets/win_psmodule/tasks/setup.yml

raw
1 # Sets up 2 local repos that contains mock packages for testing.
2 #
3 # PSRepo 1 contains
4 # ansible-test1 - 1.0.0
5 # ansible-test1 - 1.0.5
6 # ansible-test1 - 1.1.0
7 # ansible-test2 - 1.0.0
8 # ansible-test2 - 1.0.1 (Not signed for skip_publisher tests)
9 # ansible-test2 - 1.1.0-beta1
10 # ansible-clobber - 0.1.0
11 # ansible-licensed - 1.1.1 (requires license acceptance)
12 # PSRepo 2 contains
13 # ansible-test2 - 1.0.0
14 #
15 # These modules will have the following cmdlets
16 # ansible-test1
17 # Get-AnsibleTest1
18 #
19 # ansible-test2
20 # Get-AnsibleTest2
21 #
22 # ansible-clobber
23 # Enable-PSTrace (clobbers the Enable-PSTrace cmdlet)
24 #
25 # All cmdlets return
26 # [PSCustomObject]@{
27 # Name = "the name of the module"
28 # Version = "the version of the module"
29 # Repo = "the repo where the module was sourced from"
30 # }
31 ---
32 - name: create test repo folders
33 ansible.windows.win_file:
34 path: '{{ remote_tmp_dir }}\{{ item }}'
35 state: directory
36 loop:
37 - PSRepo 1
38 - PSRepo 2
39
40 - name: register test repos
41 win_psrepository:
42 name: '{{ item.name }}'
43 source: '{{ remote_tmp_dir }}\{{ item.name }}'
44 installation_policy: '{{ item.policy }}'
45 notify: remove registered repos
46 loop:
47 - name: PSRepo 1
48 policy: trusted
49 - name: PSRepo 2
50 policy: untrusted
51
52 - name: remove PSGallery repository
53 win_psrepository:
54 name: PSGallery
55 state: absent
56 notify: re-add PSGallery repository
57
58 - name: create custom openssl conf
59 copy:
60 src: openssl.conf
61 dest: '{{ output_dir }}/openssl.conf'
62 delegate_to: localhost
63
64 - name: get absolute path of output_dir for script
65 shell: echo {{ output_dir }}
66 delegate_to: localhost
67 register: output_dir_abs
68
69 - name: check if we can use the default AES encryption
70 ansible.windows.win_powershell:
71 script: |
72 $osVersion = [Version](Get-Item -LiteralPath "$env:SystemRoot\System32\kernel32.dll").VersionInfo.ProductVersion
73 $osVersion -ge [Version]"10.0.17763"
74 changed_when: false
75 register: aes256_support
76
77 - name: create certificates for code signing
78 script: setup_certs.sh {{ '' if aes256_support.output[0] else '-use-legacy' }}
79 args:
80 chdir: '{{ output_dir_abs.stdout }}'
81 delegate_to: localhost
82
83 - name: copy the CA and sign certificates
84 ansible.windows.win_copy:
85 src: '{{ output_dir }}/{{ item }}'
86 dest: '{{ remote_tmp_dir }}\'
87 loop:
88 - ca.pem
89 - sign.pem
90 - sign.pfx
91
92 - name: import the CA key to the trusted root store
93 ansible.windows.win_certificate_store:
94 path: '{{ remote_tmp_dir }}\ca.pem'
95 state: present
96 store_location: LocalMachine
97 store_name: Root
98 register: ca_cert_import
99 notify: remove CA cert from trusted root store
100
101 - name: import the sign key to the trusted publisher store
102 ansible.windows.win_certificate_store:
103 path: '{{ remote_tmp_dir }}\sign.pem'
104 state: present
105 store_location: LocalMachine
106 store_name: TrustedPublisher
107 register: sign_cert_import
108 notify: remove signing key from trusted publisher store
109
110 - name: copy across module template files
111 ansible.windows.win_copy:
112 src: module/
113 dest: '{{ remote_tmp_dir }}'
114
115 # Used in the script below to create the .nupkg for each test module
116 - name: download NuGet binary for module publishing
117 ansible.windows.win_get_url:
118 url: https://ansible-ci-files.s3.amazonaws.com/test/integration/targets/win_psmodule/nuget.exe
119 dest: '{{ remote_tmp_dir }}'
120 register: download_res
121 until: download_res is successful
122 retries: 3
123 delay: 5
124
125 - name: create test PowerShell modules
126 script: setup_modules.ps1 "{{ remote_tmp_dir }}"
127 notify: remove test packages