Passing variables from UNIX to Ansible to UNIX shell

 
Thread Tools Search this Thread
# 1  
Old 04-05-2017
Hammer & Screwdriver Passing variables from UNIX to Ansible to UNIX shell

I m passing a variable stringg from Unix shell which has value 'Good Day' to ansible and from ansible to a second shell script where it print only Good instead of 'Good Day'

passing the variable stringg from unix shell script1.sh
Code:
echo $stringg
  ansible-playbook install.yml -i /web/hostfiles/myhost.txt --extra-vars "mystring=$stringg"



then passing the variable from ansible install.yml to unix shell script2.sh like this
Code:
     shell: /web/operations/script2.sh "{{mystring}}" chdir=/web/operations/



Then printing in the second unix shell script2.sh like this
Code:
echo "Printing:::::"
  echo $*

Output:
Quote:


Good Day

Printing:::::
Good



Can you please tell me why is the second script only printing Good instead of Good Day ?
# 2  
Old 04-05-2017
Quote:
Originally Posted by mohtashims
I m passing a variable stringg from Unix shell which has value 'Good Day' to ansible and from ansible to a second shell script where it print only Good instead of 'Good Day'

Code:
echo $stringg
  ansible-playbook install.yml -i /web/hostfiles/myhost.txt --extra-vars "mystring=$stringg"

I suppose the problem is this:

Code:
"mystring=$stringg"

because it is quoted on the outside, so the shell which interprets the command ansible-playbook ... will not interfere, but what is inside the quotes is interpreted by this ansible-playbook-command. Inside is an unquoted string, though, and if this command works similar to a shell it will interpret the string:

Code:
mystring=Good day

as declaration of the variable "mystring" with a value of "Good" and (maybe silently) drop "day" as a redundant word. Try it this way:

Code:
"mystring=\"$stringg\""

which might work (i don't know this ansible-playbook command, so you will have to try).

I hope this helps.

bakunin

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
UNIX: passing stuff to a shell function emare Shell Programming and Scripting 6 02-09-2017 07:29 AM
Help Needed: UNIX shell variables to store Oracle table records venkat_reddy Shell Programming and Scripting 2 11-02-2015 06:23 PM
Passing Global Shell variables to awk baanprog UNIX for Dummies Questions & Answers 6 08-26-2013 01:23 PM
Passing awk variables to shell urello Shell Programming and Scripting 10 03-01-2012 12:17 AM
Passing shell variables to a webpage ChedWick Homework & Coursework Questions 5 12-16-2011 01:14 AM
Passing Shell Variables to an awk command Gussifinknottle UNIX for Dummies Questions & Answers 2 08-23-2011 02:49 PM
Passing a value to stored procedure from unix shell script shirdi Shell Programming and Scripting 1 03-12-2010 05:03 AM
Help Passing An Oracle parameter to a unix shell. Mark_Wright UNIX for Dummies Questions & Answers 7 11-26-2009 06:52 AM
SSH - Passing Unix login passwords through shell scripts koti_rama Shell Programming and Scripting 3 11-01-2009 05:08 AM
Passing shell variables to a rsh command lopus Shell Programming and Scripting 2 09-29-2009 07:48 PM
Passing the nawk variables to the shell prav076 Shell Programming and Scripting 1 04-06-2009 04:23 AM
Passing Shell Variables in ISQL dikki Shell Programming and Scripting 0 03-12-2009 02:15 AM
Unix passing environmental Variables belfastbelle UNIX for Dummies Questions & Answers 7 09-15-2008 08:40 PM
Passing the value of Out parm in SP to UNIX Shell Script Hangman2 Shell Programming and Scripting 2 02-19-2008 03:20 AM
passing two variables into a shell script? Bashar Shell Programming and Scripting 2 05-15-2007 11:00 AM