Thanks again Vlado. I am struggling with the basics here...
This is my block
- 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;
I am seeing my key & values in my output
TASK [debug]
*****************************************************************************************************************************************************
ok: [tstdb.cdst2ld65goi.us-east-1.rds.amazonaws.com] => (item={'key':
u'Script1', 'value': u'select username from dba_users;'}) => {
"msg": "Script1: select username from dba_users;"
}
ok: [tstdb.cdst2ld65goi.us-east-1.rds.amazonaws.com] => (item={'key':
u'Script2', 'value': u'select name from v$profile;'}) => {
"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}}'
- 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
On Wednesday, February 12, 2020 at 11:22:46 PM UTC-5, Vladimir Botka wrote:
>
> On Wed, 12 Feb 2020 19:52:31 -0800 (PST)
> Anand Solomon <[email protected] <javascript:>> wrote:
>
> > How will get the value of item.key and item.value to variable
> >
> > sqlqry = "{{ item.key }}"
> > sqlid = "{{ item.value }}"
>
> Declare the vars in the scope of the task. For example
>
> - debug:
> msg: "{{ sqlqry }}: {{ sqlid }}"
> vars:
> sqlqry: "{{ item.key }}"
> sqlid: "{{ item.value }}"
> loop: "{{ scripts|dict2items }}"
>
> HTH,
>
> -vlado
>
--
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/d5c4a522-6bf7-4438-bc78-c6298f6fbc23%40googlegroups.com.