Questions tagged [variables]

31 questions
1087
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
  • 24,065
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…
3
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…
2
votes
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…
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
  • 141
2
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
  • 2,014
  • 8
  • 41
  • 66
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
  • 7
1
vote
1 answer

Collect packages versions with ansible

Hi friends hope you're being well. I got this very basic task i need to accomplish via ansible but i'm stuck with variable resiter : i need to collect some packages version with ansible and display the output as : host has 'this software :…
1
vote
2 answers

Ansible variable register in two tasks either one or the other

I have an Ansible role that manipulates some Zabbix components. This role has this set of tasks to check the Zabbix Agent type (1 or 2) and version. - name: Check if Zabbix Agent 2 is installed ansible.builtin.shell: cmd: which zabbix_agent2 …
markfree
  • 143
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 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
  • 79
1
vote
1 answer

ansible: difference between a variable and a fact

While I'm using Ansible for quite some time, I'm not sure I really understand the differences between a variable and a fact. Could someone explain me, possibly with an example where it really make a difference ?
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
  • 3
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…
1
2