Passing variables from UNIX to Ansible to UNIX shell

 
Thread Tools Search this Thread
Special Forums UNIX and Linux Applications Passing variables from UNIX to Ansible to UNIX shell
# 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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

SHELL: UNIX : Ls regular expression not working when used with variables

If i do below command in unix prompt which static values (ie 27..97), it is working fine and gives desired output >ls -d $WORKDIR/batch/somefilename_{27..97}.* 2>/dev/null somefilename_27.sometxt somefilename_28.sometxt somefilename_29.sometxt .. somefilename_97.sometxt But if i want... (2 Replies)
Discussion started by: haiderali
2 Replies

2. Shell Programming and Scripting

UNIX: passing stuff to a shell function

I have users that print files to selected printers. Instead of creating one function for each printer I would like to have just one and passing the files to print as well as the wanted printer. The following code does not work, of course. I'm expecting that $1 is the list of files to be printed... (6 Replies)
Discussion started by: emare
6 Replies

3. Shell Programming and Scripting

Help Needed: UNIX shell variables to store Oracle table records

Hello Folks, I'm working on a requirement to automate the process of generating report(csv file) using metadata info stored in an Oracle table and E-mail it to respective people. Meta data table: Report_ID,Report_SUB_ID,Report_DB,Report_SQL,Report_to_email_Id 1,1,DEV,'select * From... (2 Replies)
Discussion started by: venkat_reddy
2 Replies

4. Shell Programming and Scripting

Passing awk variables to shell

Hi. I need to parse file and assign some values to variables, right now i do like below MYHOMEDIR=`awk '/Home/ {print $NF}' output.txt` MYSHELL=`awk '/Shell/ {print $NF}' output.txt` PRGRP=`awk '/Primary/ {print $NF}' output.txt` SECGRP=`awk '/Second/ {print $NF}' output.txt` In this... (10 Replies)
Discussion started by: urello
10 Replies

5. Homework & Coursework Questions

Passing shell variables to a webpage

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: This is my assignment as a whole - Use SVG to present certain dynamic (the raw data should change at least once... (5 Replies)
Discussion started by: ChedWick
5 Replies

6. Shell Programming and Scripting

Passing a value to stored procedure from unix shell script

Hi Dudes :) I want a unix shell script to pass value to SQL stored procedure. Below is the procedure declare res varchar2(10); begin odm_load_check('PRE_SANITY',res); dbms_output.put_line(res); end; select * from error_log; truncate table error_log; select * from test; (1 Reply)
Discussion started by: shirdi
1 Replies

7. UNIX for Dummies Questions & Answers

Help Passing An Oracle parameter to a unix shell.

I have an Oracle concurrent program that I'm passing a parameter to a unix shell script. An example value of the Oracle parameter is PO_TOP. The Oracle parameter represents the unix env var PO_TOP, meaning, on the unix side there is env var called PO_TOP (ex value: /oradev/apps/po/11.0.3/). My... (7 Replies)
Discussion started by: Mark_Wright
7 Replies

8. Shell Programming and Scripting

SSH - Passing Unix login passwords through shell scripts

Hi All , I need to call a script runscript_B.sh on server A, the runscript_B.sh script locating in server B. The runscript_B.sh in calls another script runscript_A on server A itself. it seend, i need to be connect from Server A to Server B using ssh. I have tryed like this in... (3 Replies)
Discussion started by: koti_rama
3 Replies

9. UNIX for Dummies Questions & Answers

Unix passing environmental Variables

In my script when I change an env variable in the parent shell it is only changed for that session - it there away to change it permanently using a script so that when I use rlogin (create a child session) that the env variable is set correctly? Basically what I am trying to do is to pass a... (7 Replies)
Discussion started by: belfastbelle
7 Replies

10. Shell Programming and Scripting

Passing the value of Out parm in SP to UNIX Shell Script

I have a simple procedure which accepts two input parms and returns and output count: CREATE OR REPLACE Procedure GET1 ( IN_FOLDER IN VARCHAR2, IN_SUBJECT_AREA IN VARCHAR2, OUT_CNT IN OUT VARCHAR2 ) AS BEGIN ... (2 Replies)
Discussion started by: Hangman2
2 Replies
Login or Register to Ask a Question