Variable values not being passed to ansible script

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

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.

Wow,

Thank you Kai Stian Olstad for help

Its works fine now…Superb

my apologies for other duplicated post…on other project.

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\nSQLPlus: 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”
]
} `

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
[2] https://docs.ansible.com/ansible/2.6/plugins/callback.html#plugin-list