# import tasks depending on fact: import task name substitution possible?

**URL:** <https://forum.ansible.com/t/import-tasks-depending-on-fact-import-task-name-substitution-possible/32233>\
**Category:** Ansible Project\
**Created:** [February 14, 2020, 10:19am UTC](https://forum.ansible.com/t/import-tasks-depending-on-fact-import-task-name-substitution-possible/32233 "2020-02-14T10:19:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Heinz\_Meier](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@Heinz\_Meier](https://forum.ansible.com/u/Heinz_Meier)\
**Post date:** [February 14, 2020, 10:19am UTC](https://forum.ansible.com/t/import-tasks-depending-on-fact-import-task-name-substitution-possible/32233/1 "2020-02-14T10:19:18Z")

</div>

Hi,

I want to execute a task on my minions. The problem is, that there are different tasks depending on facts of the devices. How can ansible deal with it?

Basically I want to upgrade the operating system on Cisco network components. Different network models (fact: ansible\_net\_model) have different upgrade tasks.

At the moment I have

name: Upgrade IOS  
block:  
(…)  
when: (ansible\_net\_version != compliant\_ios\_version) and  
(ansible\_net\_model is regex(“2960”))

name: Upgrade IOSXE  
block:  
(…)  
when: (ansible\_net\_version != compliant\_ios\_version) and  
(ansible\_net\_model is regex(“9200”))

Intead of the block: when: construction I thought about a

- import\_task: upgrade-{{ ansible\_net\_model }}.yaml

and files called upgrade-c2960.yaml, upgrade-x9200.yaml, …

Is than possible?

Michael

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [February 14, 2020, 10:25am UTC](https://forum.ansible.com/t/import-tasks-depending-on-fact-import-task-name-substitution-possible/32233/2 "2020-02-14T10:25:20Z")

</div>

> Hi,
> 
> I want to execute a task on my minions. The problem is, that there are different tasks depending on facts of the  
> devices. How can ansible deal with it?
> 
> Basically I want to upgrade the operating system on Cisco network components. Different network models (fact:  
> ansible\_net\_model) have different upgrade tasks.
> 
> At the moment I have
> 
> name: Upgrade IOS  
> block:  
> (...)  
> when: (ansible\_net\_version != compliant\_ios\_version) and  
> (ansible\_net\_model is regex("2960"))
> 
> name: Upgrade IOSXE  
> block:  
> (...)  
> when: (ansible\_net\_version != compliant\_ios\_version) and  
> (ansible\_net\_model is regex("9200"))
> 
> Intead of the block: when: construction I thought about a
> 
> - import\_task: upgrade-{{ ansible\_net\_model }}.yaml
> 
> and files called upgrade-c2960.yaml, upgrade-x9200.yaml, ...
> 
> Is than possible?

Yes, but you need to use include\_tasks module (as the name of the task file is dynamic):

&nbsp;&nbsp;&nbsp;&nbsp;- include\_tasks: "upgrade-{{ ansible\_net\_model }}.yaml"

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Heinz\_Meier](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@Heinz\_Meier](https://forum.ansible.com/u/Heinz_Meier)\
**Post date:** [February 14, 2020, 10:32am UTC](https://forum.ansible.com/t/import-tasks-depending-on-fact-import-task-name-substitution-possible/32233/3 "2020-02-14T10:32:23Z")

</div>

Thanks. Will try that.
