Thanks again Vlado
I want to parse the json output and take the values
Here is the json debug output from the playbook I run,
TASK [Display the query results]
************************************************************************************************************
ok: "tstdb.fdst3sb9ngoi.us-east-1.rds.amazonaws.com] => {
"msg": {
"ansible_loop_var": "item",
"changed": false,
"failed": false,
"invocation": {
"module_args": {
"host":
"tstdb.fdst3sb9ngoi.us-east-1.rds.amazonaws.com",
"hostname":
"tstdb.fdst3sb9ngoi.us-east-1.rds.amazonaws.com",
"mode": "normal",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"port": "1521",
"script": null,
"service_name": "tstdb",
"sql": "select 'Revoke ' || privilege || ' on
UTL_FILE from ' || grantee || ';' from dba_tab_privs where
table_name='UTL_FILE' and grantee not like 'APEX%' and grantee != 'CTXSYS'
and grantee != 'DBSNMP' order by grantee;",
"user": "SYSDBA",
"username": "SYSDBA"
}
},
"item": {
"key": "Script1",
"value": "select 'Revoke ' || privilege || ' on
UTL_FILE from ' || grantee || ';' from dba_tab_privs where
table_name='UTL_FILE' and grantee not like 'APEX%' and grantee != 'CTXSYS'
and grantee != 'DBSNMP' and grantee != 'DMSYS' and grantee != 'EXFSYS' and
grantee != 'MDSYS' order by grantee;"
},
"msg": [
[
"Revoke EXECUTE on UTL_FILE from TESTDBA;"
],
[
"Revoke EXECUTE on UTL_FILE from TSTSCH;"
]
]
}
]
}
}
-------------------------------------------------------
I just want to get extract the below value and pass it on to my Jinja
template.
[
"Revoke EXECUTE on UTL_FILE from TESTDBA;"
],
[
"Revoke EXECUTE on UTL_FILE from TSTSCH;"
]
Here is my Jinja template
- name: Generate Revoke Statement
copy:
dest: /home/ansible/Playbooks/{{sname}}/sql/{{item.key}}_revoke.sql
content: |
spool /home/ansible/Playbooks/{{sname}}/log/{{item.key}}.log
{% for line in query_result | flatten %}
{{ line }}
{% endfor %}
spool off;
delegate_to: localhost
connection: local
loop: "{{ scripts|dict2items }}"
On Wednesday, February 12, 2020 at 9:02:20 PM UTC-5, Anand Solomon wrote:
>
> Hi,
> What is the best way to loop the below KEY : VALUE ?
>
>
> *main.yml*
>
> var_files:
> - /home/ansible/sqlvar.yml
>
> - name: Script
> oracle_sql:
> sql: {{Value}}
> environment: "{{oracle_env}}"
> register: query_result
> connection: local
>
> - name: Runs statements
> command: $ORACLE_HOME/sqlplus -s {{user}}/{{password}}@{{sname}}
> @/home/ansible/Playbooks/{{sname}}/sql/{{Key}}_revoke.sql
> environment: "{{oracle_env}}"
> register: sqloutput
> connection: local
>
> ------
> sqlvar.yml
>
> Key: Value
> Script1: select username from dba_users;
> Script2: select file_name from dba_data_files;
> Script3: select name from v$profile;
> Script4: select username from dba_profile;
>
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/c697b56c-df8a-4c1e-93cd-c582c0706385%40googlegroups.com.