# Set variable according to result of another variable?

**URL:** <https://forum.ansible.com/t/set-variable-according-to-result-of-another-variable/17424>\
**Category:** Ansible Project\
**Created:** [February 2, 2015, 7:52pm UTC](https://forum.ansible.com/t/set-variable-according-to-result-of-another-variable/17424 "2015-02-02T19:52:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Oliver](https://avatars.discourse-cdn.com/v4/letter/j/97f17d/32.png) [@John\_Oliver](https://forum.ansible.com/u/John_Oliver)\
**Post date:** [February 2, 2015, 7:52pm UTC](https://forum.ansible.com/t/set-variable-according-to-result-of-another-variable/17424/1 "2015-02-02T19:52:11Z")

</div>

If I:

- name: Copy SSL cert  
copy: src={{ ansible\_hostname if ansible\_hostname in valid\_hosts else (‘test’) }}.crt  
dest=/etc/pki/tls/certs/  
mode=0644

How can I capture the name of the certificate that was actually copied for action in another task?

---

<div class="post-metadata">

**Author:** ![Giovanni\_Tirloni](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Giovanni\_Tirloni](https://forum.ansible.com/u/Giovanni_Tirloni)\
**Post date:** [February 3, 2015, 11:42am UTC](https://forum.ansible.com/t/set-variable-according-to-result-of-another-variable/17424/2 "2015-02-03T11:42:55Z")

</div>

- name: Copy SSL cert  
&nbsp;&nbsp;copy: src={{ ansible\_hostname if ansible\_hostname in valid\_hosts else  
&nbsp;&nbsp;('test') }}.crt  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest=/etc/pki/tls/certs/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mode=0644  
&nbsp;&nbsp;register: cert\_copy

- debug: var=cert\_copy

[http://docs.ansible.com/playbooks\_variables.html#registered-variables](http://docs.ansible.com/playbooks_variables.html#registered-variables)

Giovanni
