Questions tagged [variables]
24 questions
922
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,219
- 19
- 68
- 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
- 81
- 1
- 3
- 8
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
- 121
- 3
- 14
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
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
- 1
- 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
- 5
1
vote
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
- 25
- 6
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
- 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
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
- 3
- 3
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…
rimalroshan
- 139
- 6
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
0
votes
0 answers
How to pass variables inside docker container to application securely?
An application inside a docker container is a required connection for external PostgreSQL DB. How can I pass variables inside the docker container for this application securely? I have in the file pass.conf:
db_user=postgre
db_password=test
With…
cowilob216
- 1
- 2
0
votes
1 answer
Use variable to construct dictionary key in Ansible
I am trying to update a dict in a hostvar, and the name of the key is constructed using a variable (node). For example, if 'node' is 1 then I want to update hostvars['fakehost']['mydict']['localaddress1']. Here's my code:
- name: Read IPv4 of…
TSG
- 1,634
- 6
- 29
- 51