# Can i use .yml file like this?

**URL:** <https://forum.ansible.com/t/can-i-use-yml-file-like-this/24731>\
**Category:** Ansible Project\
**Created:** [June 15, 2017, 5:31am UTC](https://forum.ansible.com/t/can-i-use-yml-file-like-this/24731 "2017-06-15T05:31:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![user45](https://avatars.discourse-cdn.com/v4/letter/u/7ab992/32.png) [@user45](https://forum.ansible.com/u/user45)\
**Post date:** [June 15, 2017, 5:31am UTC](https://forum.ansible.com/t/can-i-use-yml-file-like-this/24731/1 "2017-06-15T05:31:13Z")

</div>

tasks:

- name: Variable  
set\_fact:  
os: “ubi”  
host: “192.168.0.137”  
username: “root”  
password: “premier”  
commands: “show version”  
**module: “ios\_command”**

############### Working ############

- name: Cisco ios command  
**ios\_command:**  
host: “{{host}}”  
username: “{{username}}”  
password: “{{password}}”  
commands: “{{commands}}”

############## Not Working ###########

- name: Cisco ios command  
**“{{module}}”: \< – This occur error message.**  
host: “{{host}}”  
username: “{{username}}”  
password: “{{password}}”  
commands: “{{commands}}”

I want to make dynamic yml file like above, But This is not working.

If you were me, How could you do that?

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [June 15, 2017, 3:38pm UTC](https://forum.ansible.com/t/can-i-use-yml-file-like-this/24731/2 "2017-06-15T15:38:43Z")

</div>

You could perhaps use template to generate the playbook file that you want to use, then run the generated playbook.

I don’t know what alternative value for module might be, but you could perhaps use when: condition to only run ios\_command if some condition is true. Something like this (not tested):

- name: Cisco ios command

**ios\_command:**  
host: “{{host}}”  
username: “{{username}}”  
password: “{{password}}”  
commands: “{{commands}}”  
when: “‘cisco’ in group\_names”

- name: Non cisco ios command

**a\_different\_command:**  
host: “{{host}}”  
username: “{{username}}”  
password: “{{password}}”  
commands: “{{commands}}”  
when: “‘cisco’ not in group\_names”

Hope this helps.

Jon

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 15, 2017, 3:40pm UTC](https://forum.ansible.com/t/can-i-use-yml-file-like-this/24731/3 "2017-06-15T15:40:50Z")

</div>

I believe this is what you want:

- name: Cisco ios command  
&nbsp;&nbsp;&nbsp;&nbsp;action:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;module: "{{module}}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host: "{{host}}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;username: "{{username}}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password: "{{password}}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;commands: "{{commands}}"

---

<div class="post-metadata">

**Author:** ![user45](https://avatars.discourse-cdn.com/v4/letter/u/7ab992/32.png) [@user45](https://forum.ansible.com/u/user45)\
**Post date:** [June 16, 2017, 12:18am UTC](https://forum.ansible.com/t/can-i-use-yml-file-like-this/24731/4 "2017-06-16T00:18:52Z")

</div>

Thank you ! Brian Coca !

2017년 6월 16일 금요일 오전 12시 40분 58초 UTC+9, Brian Coca 님의 말:
