in Technology by
How to access a variable name programmatically?

1 Answer

0 votes
by

Variable names can be built by adding strings together. For example, if we need to get ipv4 address of an arbitrary interface, where the interface to be used may be supplied via a role parameter or other input, we can do it in this way.

{{ hostvars[inventory_hostname]['ansible_' + which_interface]['ipv4']['address'] }}

Related questions

0 votes
    How can you access global and context variable?...
asked Mar 16, 2021 in Technology by JackTerrance
0 votes
    How to get the Jenkins version programmatically in Jobs/Pipelines or nodes other than master?...
asked Sep 14, 2021 in Technology by JackTerrance
0 votes
    How Jenkins jobs can be Triggered/Stopped/Controlled programmatically?...
asked Sep 14, 2021 in Technology by JackTerrance
0 votes
    How to download the Console log for a particular Jenkins build programmatically?...
asked Jul 17, 2021 in Technology by JackTerrance
0 votes
    Predict the output. Hi {{name}}. is used with the context variable: var context = { "name" : "< b>Jane Roe< /b>" } (1)Jane Roe ... display (3)< b>Jane Roe< /b> (4)< b>Jane Roe< /b>...
asked Aug 17, 2021 in Technology by JackTerrance
0 votes
    What is the name of the function that takes the input and maps it to the output variable called? (1)Hypothesis Function (2)None of the options (3)Map Function (4)Model Function...
asked May 22, 2021 in Technology by JackTerrance
0 votes
    In which process, a local variable has the same name as one of the instance variables? a) Serialization ... stackoverflow.com 🔗Source: Java Interview Questions and Answers...
asked Dec 19, 2020 in Technology by Editorial Staff
+1 vote
    What is true about variables 7Wonders is a valid variable name to give ? a) % is a valid first character for ... Variables are case sensitive c) ^US is a valid variable name...
asked Oct 8, 2020 in Technology by JackTerrance
0 votes
    I have inherited a large legacy ColdFusion app. There are hundreds of some sql here #variable# statements ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 27, 2022 in Education by JackTerrance
0 votes
    I found the following piece of code from the adw launcher: Object service = launcher.getSystemService("statusbar ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 13, 2022 in Education by JackTerrance
0 votes
    Which operator can be used to access union elements if union variable is a pointer variable?...
asked Jan 18, 2021 in Technology by JackTerrance
+1 vote
    Which operator can be used to access union elements if union variable is a pointer variable in C Programming ?...
asked Nov 9, 2020 in Technology by JackTerrance
0 votes
    I was asked a question in C last night and I did not know the answer since I have not used C ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 13, 2022 in Education by JackTerrance
0 votes
    I was asked a question in C last night and I did not know the answer since I have not used C ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 13, 2022 in Education by JackTerrance
0 votes
    I was asked a question in C last night and I did not know the answer since I have not used C ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 13, 2022 in Education by JackTerrance
...