Uploaded image for project: 'IGB'
  1. IGB
  2. IGBF-2336

Answer: Can we refer to other variables in a vars_file ?

    Details

    • Type: Task
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None

      Description

      A quick question:

      In a "vars" file in ansible, can you refer to another variable defined in the same file?

      For example, can you do the following?

      var1: hello
      var2: world
      var3: "{{ var1 }} var2"

      That is, what I would like to do is define a variable and then use it to define additional variables elsewhere in a variables file.

      For example, I would like to be able to define "ec2_name" and then re-use it to define the name of the appstore database:

      ec2_name: appstore123
      ...
      rds_db_name: "{{ ec2_name }}"

      Do you know: Is this legal in ansible?

      Asking because you might know the answer off-hand. I have not had much luck searching google for the answer.

      If you don't know it off-hand, just add that as a comment in the ticket. No need to do a lot of deep dive research.

        Attachments

          Activity

          ann.loraine Ann Loraine created issue -
          ann.loraine Ann Loraine made changes -
          Field Original Value New Value
          Epic Link IGBF-2323 [ 18477 ]
          ann.loraine Ann Loraine made changes -
          Rank Ranked higher
          cdias1 Chester Dias (Inactive) made changes -
          Status To-Do [ 10305 ] In Progress [ 3 ]
          Hide
          cdias1 Chester Dias (Inactive) added a comment -

          https://stackoverflow.com/questions/47233395/ansible-combining-two-variables-adds-u-to-one-of-them

          The above link might help, but how I suggest to do it is don't declare a variable as a combination of 2 vars instead combine the vars where the playbook runs dynamically.

          In our case, we have too many vars currently, I am planning to reduce a few as time progresses. That will make things a bit simple

          Show
          cdias1 Chester Dias (Inactive) added a comment - https://stackoverflow.com/questions/47233395/ansible-combining-two-variables-adds-u-to-one-of-them The above link might help, but how I suggest to do it is don't declare a variable as a combination of 2 vars instead combine the vars where the playbook runs dynamically. In our case, we have too many vars currently, I am planning to reduce a few as time progresses. That will make things a bit simple
          cdias1 Chester Dias (Inactive) made changes -
          Status In Progress [ 3 ] Needs 1st Level Review [ 10005 ]
          cdias1 Chester Dias (Inactive) made changes -
          Assignee Chester Dias [ cdias1 ]
          ann.loraine Ann Loraine made changes -
          Status Needs 1st Level Review [ 10005 ] First Level Review in Progress [ 10301 ]
          ann.loraine Ann Loraine made changes -
          Status First Level Review in Progress [ 10301 ] Ready for Pull Request [ 10304 ]
          ann.loraine Ann Loraine made changes -
          Status Ready for Pull Request [ 10304 ] Pull Request Submitted [ 10101 ]
          ann.loraine Ann Loraine made changes -
          Status Pull Request Submitted [ 10101 ] Reviewing Pull Request [ 10303 ]
          ann.loraine Ann Loraine made changes -
          Status Reviewing Pull Request [ 10303 ] Merged Needs Testing [ 10002 ]
          ann.loraine Ann Loraine made changes -
          Status Merged Needs Testing [ 10002 ] Post-merge Testing In Progress [ 10003 ]
          ann.loraine Ann Loraine made changes -
          Resolution Done [ 10000 ]
          Status Post-merge Testing In Progress [ 10003 ] Closed [ 6 ]
          ann.loraine Ann Loraine made changes -
          Assignee Chester Dias [ cdias1 ]

            People

            • Assignee:
              cdias1 Chester Dias (Inactive)
              Reporter:
              ann.loraine Ann Loraine
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: