# In Ansible, how to get a variable from another variable and then fetch it's value

**URL:** <https://forum.ansible.com/t/in-ansible-how-to-get-a-variable-from-another-variable-and-then-fetch-its-value/20077>\
**Category:** Ansible Project\
**Created:** [December 27, 2015, 7:20pm UTC](https://forum.ansible.com/t/in-ansible-how-to-get-a-variable-from-another-variable-and-then-fetch-its-value/20077 "2015-12-27T19:20:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [December 27, 2015, 7:20pm UTC](https://forum.ansible.com/t/in-ansible-how-to-get-a-variable-from-another-variable-and-then-fetch-its-value/20077/1 "2015-12-27T19:20:56Z")

</div>

Here is my problem I need to use one variable ‘`RDS_SG_NAME`’ and then append ‘\_id’ to it’s value to get another variable name which value I want/need. My simple playbook look like this:

```auto
---
- hosts: localhost
  connection: local
  gather_facts: no 
  vars:
    abc_id: 'some-value'
    RDS_SG_NAME: 'abc'
    RDS_SG_ID: "{{ RDS_SG_NAME +'_id' }}"
  tasks:
    - debub: msg="{{ RDS_SG_NAME }}"
    - debub: msg="{{ RDS_SG_ID }}"

```

when I run this playbook, it give the values like this: RDS\_SG\_NAME: abc RDS\_SG\_ID: abc\_id But I want the some-value againt it, can someone point me to the right direction.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Pradeep\_Reddy1](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@Pradeep\_Reddy1](https://forum.ansible.com/u/Pradeep_Reddy1)\
**Post date:** [December 28, 2015, 9:19am UTC](https://forum.ansible.com/t/in-ansible-how-to-get-a-variable-from-another-variable-and-then-fetch-its-value/20077/2 "2015-12-28T09:19:50Z")

</div>

I do this generally, if I want to use a variable name as a value to another variable

---

<div class="post-metadata">

**Author:** ![Pradeep\_Reddy1](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@Pradeep\_Reddy1](https://forum.ansible.com/u/Pradeep_Reddy1)\
**Post date:** [December 28, 2015, 9:23am UTC](https://forum.ansible.com/t/in-ansible-how-to-get-a-variable-from-another-variable-and-then-fetch-its-value/20077/3 "2015-12-28T09:23:10Z")

</div>

Ignore pre\_tasks in second play.  
The thing to note is the usage of hostvars.
