blob: c610905cdf1fc6736a0cf0da18b7af86e593a8bb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
- name: copy the sshd_config to the test dir
copy:
src: sshd_config
dest: "{{ remote_tmp_dir_test }}"
- name: insert/update "Match User" configuration block in sshd_config
blockinfile:
path: "{{ remote_tmp_dir_test }}/sshd_config"
block: |
Match User ansible-agent
PasswordAuthentication no
backup: yes
register: blockinfile_test0
- name: ensure we have a bcackup file
assert:
that:
- "'backup_file' in blockinfile_test0"
- name: check content
shell: 'grep -c -e "Match User ansible-agent" -e "PasswordAuthentication no" {{ remote_tmp_dir_test }}/sshd_config'
register: blockinfile_test0_grep
- debug:
var: blockinfile_test0
verbosity: 1
- debug:
var: blockinfile_test0_grep
verbosity: 1
- name: validate first example results
assert:
that:
- 'blockinfile_test0.changed is defined'
- 'blockinfile_test0.msg is defined'
- 'blockinfile_test0.changed'
- 'blockinfile_test0.msg == "Block inserted"'
- 'blockinfile_test0_grep.stdout == "2"'
- name: check idemptotence
blockinfile:
path: "{{ remote_tmp_dir_test }}/sshd_config"
block: |
Match User ansible-agent
PasswordAuthentication no
register: blockinfile_test1
- name: validate idempotence results
assert:
that:
- 'not blockinfile_test1.changed'
|