Questions tagged [variables]

25 questions
980
votes
15 answers

How to determine if a bash variable is empty?

What is the best way to determine if a variable in bash is empty ("")? I have heard that it is recommended that I do if [ "x$variable" = "x" ] Is that the correct way? (there must be something more straightforward)
Brent
  • 22,857
  • 19
  • 70
  • 102
4
votes
1 answer

Get PowerShell command output as a variable in bat (cmd) script

I'm trying to get FQDN of a host in some .cmd file. We have disjointed AD domain so "@echo %COMPUTERNAME%.%USERDNSDOMAIN%" does not work. I mean it works, but returns wrong value. The solution I ended up with is powershell.exe -noninteractive…
Papa Smurf
  • 89
  • 1
  • 3
  • 9
2
votes
1 answer

ANSIBLE how to locate dict at host_vars file?

I try to master the work with dictionaries at ansible. When I include dict to playbook as at example all works like charm. But when I try to include vars block to my host_vars/myserv.yml file like this: host_vars/myserv.yml <- There is wrong syntax…
Kein
  • 131
  • 3
  • 14
2
votes
2 answers

How costly are nginx variables?

nginx FAQ Is there a proper way to use nginx variables to make sections of the configuration shorter, using them as macros for making parts of configuration work as templates? ) saying (bold is mine): Q: Is there a proper way to use nginx variables…
adrelanos
  • 37
  • 6
1
vote
3 answers

Kickstart CentOS 7 with pre-defined static IP and hostname (%pre) and used in KS, possible?

I don't know if this is possible, but going to ask anyways. I am trying to Kickstart newer servers of us with CentOS 7. So far I got most working, however for some reason if I use variables in the %pre section of my Kickstart script, then it does…
HudsonHawk
  • 103
  • 2
  • 14
1
vote
1 answer

bash change directory with spaces and backslash

I'm trying to build a script that I need to be quite able to manage directory with spaces or/and backslashes in their name or not. Inside a bash script or directly on bash shell using variables for testing, I cannot change to a directory with…
SimoneM
  • 121
  • 1
1
vote
1 answer

Ansible: Loop over template with related variables

Given the variable structure syncjobs: - filename: output1.bash content: data1 - filename: output2.bash content: data2 I want to loop over it creating the files with ansible.builtin.template using the field filename for the dest. I can…
Andreas Piening
  • 173
  • 1
  • 9
1
vote
1 answer

Ansible print debug message result variable

I have a simple task that I cannot overcome. I have a playbook that returns AWS EC2 instance configuration. I need to only print (display) private_ip_address. Here my playbook --- - hosts: local connection: local gather_facts: false become:…
housemd
  • 15
  • 2
  • 4
1
vote
2 answers

Bash script - check if a variable is located between 2 others variables?

In a Bash script I want to check if var1 is located between var2 and var3. But I can't find how to do it. Something like this. var1=15 var2=10 var3=20 if [ "$var1" is located beetween "$var2" and "$var3" ] then echo "ok" else echo "not…
Maxime
  • 69
  • 7
1
vote
1 answer

How does systemctl variable escaping work in a shell?

I want do a batch job with systemctl, something like: systemctl status v2ray-haproxy@{1..5} That's fine. But when i change 5 to a variable: n=5;systemctl status v2ray-haproxy@{1..$n} It's not working now, and error: Invalid unit name…
Rampage
  • 11
  • 2
0
votes
1 answer

Ansible - manage installed apps and send output via email - variables are filling wrong

so i have this playbook, which checking, if there are installed selected packages. nothing special there. Then i would like to send an output to my email, if everything went right etc. --- - name: Install basic apps hosts: some hosts from…
helloweenx
  • 1
  • 1
  • 3
0
votes
0 answers

How can I add multiple variables in Ansible PB from another file

I plan to add few hundred of lines in some files using Ansible. My idea is to put all those lines in a file and then use a variable inside the playbook. This is the first part. The second one is that those variables (in my case some URLs) will be…
razvanli
  • 1
  • 1
0
votes
0 answers

Interpolate environmental variable into a string

In a block I have this: # Extract the first subdir and assign it to "subdir" SetEnvIfNoCase Request_URI "^/?([^/]*)(?:/|$)" subdir=$1 # Add the subdir to the logging path CustomLog "|bin/rotatelogs.exe -l…
MonkeyZeus
  • 260
  • 1
  • 12
0
votes
1 answer

Pipe into command stored in bash variable

I enter two command in bash: $export g='grep "something"' $echo "something and another thing" | $g But it doesn't work. I want the second command to be evaluated by bash as : echo "something and another thing" | grep "something" What should I do…
rooni
  • 139
  • 7
0
votes
1 answer

Write original Ansible variable to xml file

I'm trying to find a way to write the original {{ ansible_host }} var in to a xml file. This variable will replace a static IP in a device config. The reason that I want to replace this IP with the original variable in the file, is because later in…
Collega
  • 65
  • 6
1
2