How do I write a playbook for this cobbler snippet?

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:
  - include: code/{$ansible_hostname}.yaml

Can i?

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

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

/andreas

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”.