# conditionally give value to src of win\_copy

**URL:** <https://forum.ansible.com/t/conditionally-give-value-to-src-of-win-copy/30514>\
**Category:** Ansible Developer\
**Created:** [June 7, 2019, 12:58pm UTC](https://forum.ansible.com/t/conditionally-give-value-to-src-of-win-copy/30514 "2019-06-07T12:58:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deepak\_Asawa](https://avatars.discourse-cdn.com/v4/letter/d/e0b2c6/32.png) [@Deepak\_Asawa](https://forum.ansible.com/u/Deepak_Asawa)\
**Post date:** [June 7, 2019, 12:58pm UTC](https://forum.ansible.com/t/conditionally-give-value-to-src-of-win-copy/30514/1 "2019-06-07T12:58:03Z")

</div>

Hi,

- name: copy\_phoenix\_folder  
win\_copy:  
src: phoenix\_x86  
when: “{{ ansible\_architecture }} == 32-bit”  
src: phoenix\_x64  
when: “{{ ansible\_architecture }} == 64-bit”  
dest: c:\

I have written above code but scr will always be set to phoenix\_x64, giving below warning

[WARNING]: While constructing a mapping from /etc/ansible/roles/deepak\_role/tasks/copy\_phoenix\_folder.yml, line 3, column 10, found a duplicate dict key (when). Using  
last defined value only.

where phoenix\_x86 and phoenix\_x64 are the folders copied in files folder of role.

Please guide me so that the scr should be set to phoenix\_x86 when ansible\_architecture is “32-bit” and it should set to phoenix\_x64 when ansible\_architecture is “64-bit”

Thanks

---

<div class="post-metadata">

**Author:** ![Martin\_Krizek](https://avatars.discourse-cdn.com/v4/letter/m/d26b3c/32.png) [@Martin\_Krizek](https://forum.ansible.com/u/Martin_Krizek)\
**Post date:** [June 7, 2019, 1:06pm UTC](https://forum.ansible.com/t/conditionally-give-value-to-src-of-win-copy/30514/2 "2019-06-07T13:06:46Z")

</div>

I have not tested but you want to do something like the following:

- set\_fact  
&nbsp;&nbsp;&nbsp;&nbsp;win\_copy\_src\_var: phoenix\_x86  
&nbsp;&nbsp;when: "{{ ansible\_architecture }} == 32-bit"

- set\_fact  
&nbsp;&nbsp;&nbsp;&nbsp;win\_copy\_src\_var: phoenix\_x64  
&nbsp;&nbsp;when: "{{ ansible\_architecture }} == 64-bit"

- name: copy\_phoenix\_folder  
&nbsp;&nbsp;win\_copy:  
&nbsp;&nbsp;&nbsp;&nbsp;src: "{{ win\_copy\_src\_var }}"  
&nbsp;&nbsp;&nbsp;&nbsp;dest: c:\\

There might be better solutions depending on the structure of your playbook.

Thanks,  
Martin

---

<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:** [June 11, 2019, 1:45pm UTC](https://forum.ansible.com/t/conditionally-give-value-to-src-of-win-copy/30514/3 "2019-06-11T13:45:12Z")

</div>

first, this conditional is wrong:  
`when: "{{ ansible_architecture }} == 64-bit"`

should be:  
`when: ansible\_architecture == "64-bit"

alos you can just do:

src: "{{ (ansible\_architecture == '32-bit')|ternary('phoenix\_x86',  
'phoenix\_x64') }}"

---

<div class="post-metadata">

**Author:** ![Ravikumar\_Wagh](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@Ravikumar\_Wagh](https://forum.ansible.com/u/Ravikumar_Wagh)\
**Post date:** [June 13, 2019, 6:05am UTC](https://forum.ansible.com/t/conditionally-give-value-to-src-of-win-copy/30514/4 "2019-06-13T06:05:06Z")

</div>

Hello,

Please try as below:

- name: copy\_phoenix\_folder  
win\_copy:  
src: “{{ phoenix\_x86 if ansible\_architecture == 32-bit else phoenix\_x64 }}”  
dest: c:\
