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