# How do I write a playbook for this cobbler snippet?

**URL:** <https://forum.ansible.com/t/how-do-i-write-a-playbook-for-this-cobbler-snippet/11782>\
**Category:** Ansible Project\
**Created:** [August 10, 2012, 2:08pm UTC](https://forum.ansible.com/t/how-do-i-write-a-playbook-for-this-cobbler-snippet/11782 "2012-08-10T14:08:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andreas\_Davour](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@Andreas\_Davour](https://forum.ansible.com/u/Andreas_Davour)\
**Post date:** [August 10, 2012, 2:08pm UTC](https://forum.ansible.com/t/how-do-i-write-a-playbook-for-this-cobbler-snippet/11782/1 "2012-08-10T14:08:41Z")

</div>

In cobbler I have a snippet that looks like this:

pushd /lvn  
#include $bestmatch('/var/lib/cobbler/code/')  
popd  
yum -y install software  
rm -f /lvn/service/config/database.yml  
lvc setgamecenter

This is run on a bunch of machines.

The issue is that include.

That will pull in a file dependent on hostname that does different things (git checkout and then some trigger actions) dependent on hostname.

How do I turn that into a playbook?

I can't do:  
tasks:  
&nbsp;&nbsp;- include: code/{$ansible\_hostname}.yaml

Can i?

I tried without the extension and got this error:  
Traceback (most recent call last):  
&nbsp;&nbsp;File "/usr/bin/ansible-playbook", line 132, in \<module\>  
&nbsp;&nbsp;&nbsp;&nbsp;sys.exit(main(sys.argv[1:]))  
&nbsp;&nbsp;File "/usr/bin/ansible-playbook", line 109, in main  
&nbsp;&nbsp;&nbsp;&nbsp;pb.run()  
&nbsp;&nbsp;File "/usr/lib/python2.7/site-packages/ansible/playbook/\_\_init\_\_.py", line 153, in run  
&nbsp;&nbsp;&nbsp;&nbsp;self.\_run\_play(Play(self,play\_ds))  
&nbsp;&nbsp;File "/usr/lib/python2.7/site-packages/ansible/playbook/play.py", line 81, in \_\_init\_\_  
&nbsp;&nbsp;&nbsp;&nbsp;self.\_tasks = self.\_load\_tasks(self.\_ds, 'tasks')  
&nbsp;&nbsp;File "/usr/lib/python2.7/site-packages/ansible/playbook/play.py", line 104, in \_load\_tasks  
&nbsp;&nbsp;&nbsp;&nbsp;tokens = shlex.split(x['include'])  
&nbsp;&nbsp;File "/usr/lib64/python2.7/shlex.py", line 279, in split  
&nbsp;&nbsp;&nbsp;&nbsp;return list(lex)  
&nbsp;&nbsp;File "/usr/lib64/python2.7/shlex.py", line 269, in next  
&nbsp;&nbsp;&nbsp;&nbsp;token = self.get\_token()  
&nbsp;&nbsp;File "/usr/lib64/python2.7/shlex.py", line 96, in get\_token  
&nbsp;&nbsp;&nbsp;&nbsp;raw = self.read\_token()  
&nbsp;&nbsp;File "/usr/lib64/python2.7/shlex.py", line 124, in read\_token  
&nbsp;&nbsp;&nbsp;&nbsp;nextchar = self.instream.read(1)  
AttributeError: 'dict' object has no attribute 'read'

when my included file looked like this:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: do some funky stuff  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action: command "touch /tmp/fnorp"

/andreas

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [August 11, 2012, 1:46am UTC](https://forum.ansible.com/t/how-do-i-write-a-playbook-for-this-cobbler-snippet/11782/2 "2012-08-11T01:46:50Z")

</div>

Well, a few things, there’s a syntax issue:

${ansible\_hostname} is good

$ansible\_hostname is good

{$ansible\_hostname} puts the hostname in curly brackets

Part two is:

I can’t reproduce your dict traceback, but it should be noted that ansible facts _CANNOT_ be used in includes, because we build the structure of the playbook (which tasks should be run) earlier and all task defintions go to all hosts. They can, however, be used in vars\_files. Which means you can set variables that can later be used in only\_if conditions and so forth, should you wish to set a variable that says “don’t run on me”, but “run that on this guy”.
