summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/blockinfile/tasks/multiline_search.yml
blob: 8eb94f579d1394b28c3696a3a0d89b85994b98cb (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
- name: Create multiline_search test file
  copy:
    dest: "{{ remote_tmp_dir }}/listener.ora"
    content: |
      LISTENER=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))) # line added by Agent
      ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON                                   # line added by Agent

      SID_LIST_LISTENER_DG =
          (SID_LIST =
              (SID_DESC =
                  (GLOBAL_DBNAME = DB01_DG)
                  (ORACLE_HOME = /u01/app/oracle/product/12.1.0.1/db_1)
                  (SID_NAME = DB011)
              )
          )

      SID_LIST_LISTENER =
          (SID_LIST =
              (SID_DESC =
                  (GLOBAL_DBNAME = DB02)
                  (ORACLE_HOME = /u01/app/oracle/product/12.1.0.1/db_1)
                  (SID_NAME = DB021)
              )
          )

- name: Set fact listener_line
  set_fact:
    listener_line: |
        (SID_DESC =
          (GLOBAL_DBNAME = DB03
          (ORACLE_HOME = /u01/app/oracle/product/12.1.0.1/db_1)
          (SID_NAME = DB031)
        )

- name: Add block using multiline_search enabled
  blockinfile:
    path: "{{ remote_tmp_dir }}/listener.ora"
    block: "{{ listener_line }}"
    insertafter: '(?m)SID_LIST_LISTENER_DG =\n.*\(SID_LIST ='
    marker: "    <!-- {mark} ANSIBLE MANAGED BLOCK 1-->"
  register: multiline_search1

- name: Add block using multiline_search enabled again
  blockinfile:
    path: "{{ remote_tmp_dir }}/listener.ora"
    block: "{{ listener_line }}"
    insertafter: '(?m)SID_LIST_LISTENER_DG =\n.*\(SID_LIST ='
    marker: "    <!-- {mark} ANSIBLE MANAGED BLOCK 1-->"
  register: multiline_search2

- name: Try to add block using without multiline flag in regex should add block add end of file
  blockinfile:
    path: "{{ remote_tmp_dir }}/listener.ora"
    block: "{{ listener_line }}"
    insertafter: 'SID_LIST_LISTENER_DG =\n.*\(SID_LIST ='
    marker: "    <!-- {mark} ANSIBLE MANAGED BLOCK 2-->"
  register: multiline_search3

- name: Stat the listener.ora file
  stat:
    path: "{{ remote_tmp_dir }}/listener.ora"
  register: listener_ora_file

- name: Ensure insertafter worked correctly
  assert:
    that:
      - multiline_search1 is changed
      - multiline_search2 is not changed
      - multiline_search3 is changed
      - listener_ora_file.stat.checksum == '5a8010ac4a2fad7c822e6aeb276931657cee75c0'