# Variable values not being passed to ansible script

**URL:** <https://forum.ansible.com/t/variable-values-not-being-passed-to-ansible-script/28632>\
**Category:** Ansible Project\
**Created:** [September 22, 2018, 8:07am UTC](https://forum.ansible.com/t/variable-values-not-being-passed-to-ansible-script/28632 "2018-09-22T08:07:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![onenessboy](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@onenessboy](https://forum.ansible.com/u/onenessboy)\
**Post date:** [September 22, 2018, 8:07am UTC](https://forum.ansible.com/t/variable-values-not-being-passed-to-ansible-script/28632/1 "2018-09-22T08:07:39Z")

</div>

Hi Friends,

Trying to achieve some thing like below with anisble with ansible command line --which will be executed from chatbot

- ssh into remote box
- run a script on that remote box using script module with parameters

Here is the code:  
Running the command from chatbot like below with positional parameters like below

run unlock7 ora /home/oracle/PRD abtestlock

[root@asp ops]# cat unlock

#!/bin/sh

ansible $1 -m shell -a “whoami”

ansible $1 -m script -a “/opt/scripts/ops/login.sh $2 $3”

The problem is in above code will ssh into that ops – itss working as expected, but the second line which is calling the login.sh is working, but its not taking $2 and $3 value as Parameter in it

How should i pass these values as paramenter ? Its is not being passed

root@asp ops]# cat login.sh

#!/bin/bash

source $2

sqlplus ‘/as sysdba’ \<\< EOF

ALTER USER $3 ACCOUNT UNLOCK;

EXIT;

EOF

ora ansible\_host=11.20.21.18 ansible\_user=cloud-user ansible\_ssh\_private\_key\_file=/home/asp/abkey.pem ansible\_become=yes ansible\_become\_user=oracle

and my ansible hosts look like

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 22, 2018, 8:21am UTC](https://forum.ansible.com/t/variable-values-not-being-passed-to-ansible-script/28632/2 "2018-09-22T08:21:32Z")

</div>

> Here is the code:  
> Running the command from chatbot like below with positional parameters like  
> below
> 
> run unlock7 ora /home/oracle/PRD abtestlock
> 
> [root@asp ops]# cat unlock
> 
> #!/bin/sh
> 
> ansible $1 -m shell -a "whoami"
> 
> ansible $1 -m script -a "/opt/scripts/ops/login.sh $2 $3"
> 
> The problem is in above code will ssh into that ops -- itss working as  
> expected, but the second line which is calling the login.sh is working,  
> but its not taking $2 and $3 value as Parameter in it
> 
> How should i pass these values as paramenter ? Its is not being passed

You are doing it correctly and they are being passed but you login.sh has errors.

> root@asp ops]# cat login.sh
> 
> #!/bin/bash
> 
> source $2
> 
> sqlplus '/as sysdba' \<\< EOF
> 
> ALTER USER $3 ACCOUNT UNLOCK;
> 
> EXIT;
> 
> EOF

$2 and $3 in the script unlock, becomes $1 and $2 for the script login.sh.

---

<div class="post-metadata">

**Author:** ![onenessboy](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@onenessboy](https://forum.ansible.com/u/onenessboy)\
**Post date:** [September 22, 2018, 9:41am UTC](https://forum.ansible.com/t/variable-values-not-being-passed-to-ansible-script/28632/3 "2018-09-22T09:41:26Z")

</div>

Wow,

Thank you Kai Stian Olstad for help

Its works fine now…Superb

my apologies for other duplicated post…on other project.

---

<div class="post-metadata">

**Author:** ![onenessboy](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@onenessboy](https://forum.ansible.com/u/onenessboy)\
**Post date:** [September 22, 2018, 10:01am UTC](https://forum.ansible.com/t/variable-values-not-being-passed-to-ansible-script/28632/4 "2018-09-22T10:01:18Z")

</div>

Its working fine,

However, I am getting too much ansible output on screen like below, I just need customized message " User account unlock" Is that possible with ansible ?

“stdout”: “\r\nSQL_Plus: Release 12.1.0.2.0 Production on Fri Sep 21 23:01:40 2018\r\n\r\nCopyright (c) 1982, 2014, Oracle. All rights reserved.\r\n\r\n\r\nConnected to:\r\nOracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production\r\nWith the Partitioning, OLAP, Advanced Analytics and Real Application Testing options\r\n\r\n23:01:40 SYS @ ORCL:ORCL:\>\r\nUser altered.\r\n\r\n23:01:40 SYS @ ORCL:ORCL:\>Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production\r\nWith the Partitioning, OLAP, Advanced Analytics and Real Application Testing options\r\n",  
“stdout\_lines”: [  
“”,  
"SQL_Plus: Release 12.1.0.2.0 Production on Fri Sep 21 23:01:40 2018”,  
“”,  
“Copyright (c) 1982, 2014, Oracle. All rights reserved.”,  
“”,  
“”,  
“Connected to:”,  
“Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production”,  
“With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options”,  
“”,  
“23:01:40 SYS @ ORCL:ORCL:\>”,  
“User altered.”,  
“”,  
“23:01:40 SYS @ ORCL:ORCL:\>Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production”,  
“With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options”  
]  
} `

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 22, 2018, 12:19pm UTC](https://forum.ansible.com/t/variable-values-not-being-passed-to-ansible-script/28632/5 "2018-09-22T12:19:13Z")

</div>

Probably, if you are willing to code.

Output is controlled by stdout\_callback[1], Ansible comes with different types you can try[2].  
But they probably wont give you what you are looking for, so you need to create your own by modify the one that resembles the most.

[1] [https://docs.ansible.com/ansible/2.6/plugins/callback.html#managing-stdout](https://docs.ansible.com/ansible/2.6/plugins/callback.html#managing-stdout)  
[2] [https://docs.ansible.com/ansible/2.6/plugins/callback.html#plugin-list](https://docs.ansible.com/ansible/2.6/plugins/callback.html#plugin-list)
