1- name: run tests with cleanup 2 block: 3 - name: gather facts 4 setup: 5 filter: ansible_hostname 6 7 - name: ensure testing folders exists 8 win_file: 9 path: '{{test_win_rds_settings_path}}' 10 state: directory 11 12 - name: deploy test artifacts 13 win_template: 14 src: '{{item}}.j2' 15 dest: '{{test_win_rds_settings_path}}\{{item | basename}}' 16 with_items: 17 - rds_base_cfg.xml 18 19 - name: import RDS test configuration 20 win_shell: | 21 $ts = Get-WmiObject Win32_TSGatewayServer -namespace root\cimv2\TerminalServices 22 $import_xml = Get-Content {{test_win_rds_settings_path}}\rds_base_cfg.xml 23 $import_result = $ts.Import(45, $import_xml) 24 exit $import_result.ReturnValue 25 26 - name: write certreq file 27 win_copy: 28 content: |- 29 [NewRequest] 30 Subject = "CN={{ rds_cert_suject }}" 31 KeyLength = 2048 32 KeyAlgorithm = RSA 33 MachineKeySet = true 34 RequestType = Cert 35 KeyUsage = 0xA0 ; Digital Signature, Key Encipherment 36 [EnhancedKeyUsageExtension] 37 OID=1.3.6.1.5.5.7.3.1 ; Server Authentication 38 dest: '{{test_win_rds_settings_path}}\certreq.txt' 39 40 - name: create self signed cert from certreq 41 win_command: certreq -new -machine {{test_win_rds_settings_path}}\certreq.txt {{test_win_rds_settings_path}}\certreqresp.txt 42 43 - name: register certificate thumbprint 44 raw: '(gci Cert:\LocalMachine\my | ? {$_.subject -eq "CN={{ rds_cert_suject }}"})[0].Thumbprint' 45 register: rds_cert_thumbprint 46 47 - name: run tests 48 include_tasks: win_rds_settings_tests.yml 49 50 always: 51 - name: restore RDS base configuration 52 win_shell: | 53 $ts = Get-WmiObject Win32_TSGatewayServer -namespace root\cimv2\TerminalServices 54 $import_xml = Get-Content {{test_win_rds_settings_path}}\rds_base_cfg.xml 55 $import_result = $ts.Import(45, $import_xml) 56 exit $import_result.ReturnValue 57 58 - name: remove certificate 59 raw: 'remove-item cert:\localmachine\my\{{ item }} -force -ea silentlycontinue' 60 with_items: 61 - "{{ rds_cert_thumbprint.stdout_lines[0] }}" 62 63 - name: cleanup test artifacts 64 win_file: 65 path: '{{test_win_rds_settings_path}}' 66 state: absent 67