Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/ssh_config/tasks/main.yml

raw
1 # Test code for ssh_config module
2 # Copyright (c) 2021, Abhijeet Kasurde (@Akasurde) <[email protected]>
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 - set_fact:
7 output_test_dir: '{{ remote_tmp_dir }}/test_ssh_config'
8
9 - set_fact:
10 ssh_config_test: '{{ output_test_dir }}/ssh_config_test'
11 ssh_private_key: '{{ output_test_dir }}/fake_id_rsa'
12
13 - name: create a temporary directory
14 file:
15 path: "{{ output_test_dir }}"
16 state: directory
17
18 - name: Copy sample config file
19 copy:
20 src: 'files/ssh_config_test'
21 dest: '{{ ssh_config_test }}'
22
23 - name: Copy sample private key file
24 copy:
25 src: 'files/fake_id_rsa'
26 dest: '{{ ssh_private_key }}'
27
28 - name: Fail for required argument
29 community.general.ssh_config:
30 ssh_config_file: "{{ ssh_config_test }}"
31 ignore_errors: true
32 register: host_required
33
34 - name: Check if ssh_config fails for required parameter host
35 assert:
36 that:
37 - not host_required.changed
38
39 - name: Add a host in check mode
40 community.general.ssh_config:
41 ssh_config_file: "{{ ssh_config_test }}"
42 host: "example.com"
43 hostname: github.com
44 identity_file: '{{ ssh_private_key }}'
45 port: '2223'
46 state: present
47 register: host_add
48 check_mode: true
49
50 - name: Check if changes are made in check mode
51 assert:
52 that:
53 - host_add.changed
54 - "'example.com' in host_add.hosts_added"
55 - host_add.hosts_changed is defined
56 - host_add.hosts_removed is defined
57
58 - name: Add a host
59 community.general.ssh_config:
60 ssh_config_file: "{{ ssh_config_test }}"
61 host: "example.com"
62 hostname: github.com
63 identity_file: '{{ ssh_private_key }}'
64 port: '2223'
65 state: present
66 register: host_add
67
68 - name: Check if changes are made
69 assert:
70 that:
71 - host_add.changed
72 - "'example.com' in host_add.hosts_added"
73 - host_add.hosts_changed is defined
74 - host_add.hosts_removed is defined
75
76 - name: Add same host again for idempotency
77 community.general.ssh_config:
78 ssh_config_file: "{{ ssh_config_test }}"
79 host: "example.com"
80 hostname: github.com
81 identity_file: '{{ ssh_private_key }}'
82 port: '2223'
83 state: present
84 register: host_add_again
85
86 - name: Check for idempotency
87 assert:
88 that:
89 - not host_add_again.changed
90 - host_add.hosts_changed is defined
91 - host_add.hosts_removed is defined
92 - host_add.hosts_added is defined
93
94 - name: Update host
95 community.general.ssh_config:
96 ssh_config_file: "{{ ssh_config_test }}"
97 host: "example.com"
98 hostname: github.com
99 identity_file: '{{ ssh_private_key }}'
100 port: '2224'
101 state: present
102 register: host_update
103
104 - name: Check for update operation
105 assert:
106 that:
107 - host_update.changed
108 - host_update.hosts_changed is defined
109 - "'example.com' in host_update.hosts_changed"
110 - host_update.hosts_removed is defined
111 - host_update.hosts_added is defined
112 - host_update.hosts_change_diff is defined
113
114 - name: Update host again
115 community.general.ssh_config:
116 ssh_config_file: "{{ ssh_config_test }}"
117 host: "example.com"
118 hostname: github.com
119 identity_file: '{{ ssh_private_key }}'
120 port: '2224'
121 state: present
122 register: host_update
123
124 - name: Check update operation for idempotency
125 assert:
126 that:
127 - not host_update.changed
128 - host_update.hosts_changed is defined
129 - host_update.hosts_removed is defined
130 - host_update.hosts_added is defined
131 - host_update.hosts_change_diff is defined
132
133 - name: Delete a host
134 community.general.ssh_config:
135 ssh_config_file: "{{ ssh_config_test }}"
136 host: "example.com"
137 state: absent
138 register: host_delete
139
140 - name: Check if changes are made
141 assert:
142 that:
143 - host_delete.changed
144 - "'example.com' in host_delete.hosts_removed"
145 - host_delete.hosts_changed is defined
146 - host_delete.hosts_added is defined
147
148 - name: Delete same host again for idempotency
149 community.general.ssh_config:
150 ssh_config_file: "{{ ssh_config_test }}"
151 host: "example.com"
152 hostname: github.com
153 state: absent
154 register: host_delete_again
155
156 - name: Check for idempotency
157 assert:
158 that:
159 - not host_delete_again.changed
160 - host_delete_again.hosts_changed is defined
161 - host_delete_again.hosts_removed is defined
162 - host_delete_again.hosts_added is defined
163
164 - name: Check if user and ssh_config_file are mutually exclusive
165 community.general.ssh_config:
166 ssh_config_file: "{{ ssh_config_test }}"
167 user: root
168 host: "example.com"
169 hostname: github.com
170 identity_file: '{{ ssh_private_key }}'
171 port: '2223'
172 state: present
173 register: mut_ex
174 ignore_errors: true
175
176 - name: Check mutual exclusive test - user and ssh_config_file
177 assert:
178 that:
179 - not mut_ex.changed
180 - "'parameters are mutually exclusive' in mut_ex.msg"
181
182 - name: Check if proxycommand and proxyjump are mutually exclusive
183 community.general.ssh_config:
184 ssh_config_file: "{{ ssh_config_test }}"
185 host: "example.com"
186 hostname: github.com
187 proxycommand: "ssh jumphost.example.com -W %h:%p"
188 proxyjump: "jumphost.example.com"
189 identity_file: '{{ ssh_private_key }}'
190 port: '2224'
191 state: present
192 register: proxy_mut_ex
193 ignore_errors: true
194
195 - name: Check mutual exclusive test - proxycommand and proxyjump
196 assert:
197 that:
198 - not proxy_mut_ex.changed
199 - "'parameters are mutually exclusive' in proxy_mut_ex.msg"
200
201 - name: Add a full name host
202 community.general.ssh_config:
203 ssh_config_file: "{{ ssh_config_test }}"
204 host: "full_name"
205 hostname: full_name.com
206 identity_file: '{{ ssh_private_key }}'
207 port: '2223'
208 state: present
209 register: full_name
210
211 - name: Check if changes are made
212 assert:
213 that:
214 - full_name is changed
215 - full_name.hosts_added == ["full_name"]
216 - full_name.hosts_changed == []
217 - full_name.hosts_removed == []
218
219 - name: Add a host with name which is contained in full name host
220 community.general.ssh_config:
221 ssh_config_file: "{{ ssh_config_test }}"
222 host: "full"
223 hostname: full.com
224 identity_file: '{{ ssh_private_key }}'
225 port: '2223'
226 state: present
227 register: short_name
228
229 - name: Check that short name host is added and full name host is not updated
230 assert:
231 that:
232 - short_name is changed
233 - short_name.hosts_added == ["full"]
234 - short_name.hosts_changed == []
235 - short_name.hosts_removed == []
236
237 - name: Include integration tests for additional options (e.g. proxycommand, proxyjump)
238 include_tasks: 'options.yml'