Ansible playbook not working

Hello Team, I have written an ansible play book for creating oracle restore point and I am running from ansible tower and GitHub and hasivolt.

My logic is

  1. Provide bellow variable in template
    Db name
    Pdb name
    Create/drop
    Restore point name
  2. Resister the output of select count(*) from v$restorepoint where restorepoint={{Restore point name}};
  3. If rc value of above query is 0 and restore point action is create then create restore point or else
  4. If rc value of above query is not equal to 0 and restorepoint action is drop then run drop restore point.
  5. Display the register value of create or drop register value.

But the issue is bellow task is getting skipped when executing

  • name create restore point
    when:
    • restorepoint_action = “create”
    • restorepoint_exist == 0
      shell |
      . oraenv << {{db_name}}
      sqlplus “/as sysdba” > EOF
      create restore point for {{pdb}};
      EOF
      register created_restore
      change_when

Have you looked to see if there’s a module that supports this instead of using shell tasks? It would probably be more convenient.

Using conditionals with shell, it could look like this:

- shell: "{{ create_cmd }}"
  when:
    - restorepoint_action == "create"
    - restorepoint_exist == 0
  register: created_restore
  
- shell: "{{ drop_cmd }}"
  when:
    - created_restore is skipped
    - restorepoint_action == "drop"
    - restorepoint_exist != 0

Also, please use ``` on to the line below and above playbook snippets to make them easier to read.

1 Like

Thank you very much .

Our main motive behind this automation is to reduce the direct login of server and debase login using password so can use “community.oracle.oracle_sql” as it will require password as variable . Also I need to use .oraenv