summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/blockinfile/tasks/add_block_to_existing_file.yml
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 16:04:21 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 16:04:21 +0000
commit8a754e0858d922e955e71b253c139e071ecec432 (patch)
tree527d16e74bfd1840c85efd675fdecad056c54107 /test/integration/targets/blockinfile/tasks/add_block_to_existing_file.yml
parentInitial commit. (diff)
downloadansible-core-upstream.tar.xz
ansible-core-upstream.zip
Adding upstream version 2.14.3.upstream/2.14.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration/targets/blockinfile/tasks/add_block_to_existing_file.yml')
-rw-r--r--test/integration/targets/blockinfile/tasks/add_block_to_existing_file.yml52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/integration/targets/blockinfile/tasks/add_block_to_existing_file.yml b/test/integration/targets/blockinfile/tasks/add_block_to_existing_file.yml
new file mode 100644
index 0000000..c610905
--- /dev/null
+++ b/test/integration/targets/blockinfile/tasks/add_block_to_existing_file.yml
@@ -0,0 +1,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'