On Thu, 13 Feb 2020 05:57:39 -0800 (PST)
Anand Solomon <
anand.v...@gmail.com> wrote:
> - include_vars:
> file: /home/ansible/Playbooks/Compliance1.yml
> name: scripts
> - debug:
> msg: "{{ sqlqry }}: {{ sqlid }}"
> vars:
> sqlqry: "{{ item.key }}"
> sqlid: "{{ item.value }}"
> loop: "{{ scripts|dict2items }}"
> [...]
> The Complaince1.yml has the below
>
> Script1: select username from dba_users;
> Script2: select name from v$profile;
> [...]
> "msg": "Script1: select username from dba_users;"
> "msg": "Script2: select name from v$profile;"
>
> My problem is, I don't know how to get the key (like "Script1") and value
> (like "select username from dba_users;") to another block as
>
> - name: Script will revoke
> oracle_sql:
> username: "{{user}}"
> password: "{{password}}"
> service_name: "{{sname}}"
> port: "{{prt}}"
> sqlId: "{{hostnme}}"
> sql: "{{sqlqry}}'
vars:
sqlqry: "{{ item.key }}"
sqlid: "{{ item.value }}"
loop: "{{ scripts|dict2items }}"
Simply append "vars" and "loop".
But I think the above task "oracle_sql" won't work because of attribute
"sql". The documentation says "sql: The sql you want to execute" but
"item.key" is the label of the script. See
https://github.com/oravirt/ansible-oracle-modules/blob/master/oracle_sql
Instead, "item.value" is the SQL you want to execute. Correct syntax is
(substitution is not necessary)
- name: Script will revoke
oracle_sql:
username: "{{ user }}"
password: "{{ password }}"
service_name: "{{ sname }}"
port: "{{ prt }}"
sqlId: "{{ hostnme }}"
sql: "{{ item.value }}'
loop: "{{ scripts|dict2items }}"
> - name: Runs the revoke statements and spool out.
> command: $ORACLE_HOME/sqlplus -s {{user}}/{{password}}@{{sname}}
> @/home/ansible/Playbooks/{{sname}}/sql/{{sqlid}}_revoke.sql
> environment: "{{oracle_env}}"
> register: sqloutput
> connection: local
dtto. Change "sqlid" to "item.key"
- name: Runs the revoke statements and spool out.
command: $ORACLE_HOME/sqlplus -s {{user}}/{{password}}@{{sname}}
@/home/ansible/Playbooks/{{sname}}/sql/{{ item.key }}_revoke.sql
environment: "{{oracle_env}}"
register: sqloutput
connection: local