# template destination logic

**URL:** <https://forum.ansible.com/t/template-destination-logic/13814>\
**Category:** Ansible Project\
**Created:** [October 31, 2013, 3:11pm UTC](https://forum.ansible.com/t/template-destination-logic/13814 "2013-10-31T15:11:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Angus1](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@Paul\_Angus1](https://forum.ansible.com/u/Paul_Angus1)\
**Post date:** [October 31, 2013, 3:11pm UTC](https://forum.ansible.com/t/template-destination-logic/13814/1 "2013-10-31T15:11:57Z")

</div>

Hi there,

I’m quite new to Ansible, and I’m trying to create multiple pxelinux.cfg files. I want to be able to generate files with the hex translation of the host’s IP address as the destination name.

I can put the hex translation in the inventory against the host, but I’d like to do it ‘on-the-fly’ a module to do the translation is easy enough, but how would i call it?

Many thanks

Paul Angus

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 1, 2013, 12:20am UTC](https://forum.ansible.com/t/template-destination-logic/13814/2 "2013-11-01T00:20:48Z")

</div>

" I want to be able to generate files with the hex translation of the host’s IP address as the destination name."

Well, technically you could write a lookup plugin:

src=foo dest={{ lookup(“hexify”, ansible\_eth0.ipv4.address) }}.j2

I should point out it sounds suspiciously like you’re trying to make a PXE server out of an ansible playbook.

If you are, I might suggest [http://www.cobblerd.org/](http://www.cobblerd.org/) as an option if you like the way James C. and myself usually think, seeing we’re the top 2 contributors to the project and James is still running it.

Note that I’ve wanted to split it out into a basic library for writing bits of PXE tree structure and it wouldn’t be hard to use Ansible to drive something like that if it happened.

---

<div class="post-metadata">

**Author:** ![Paul\_Angus1](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@Paul\_Angus1](https://forum.ansible.com/u/Paul_Angus1)\
**Post date:** [November 1, 2013, 2:33pm UTC](https://forum.ansible.com/t/template-destination-logic/13814/3 "2013-11-01T14:33:44Z")

</div>

Thanks Micheal,

Where would i put my hexify plugin?

And yes I am building a PXE server. My use case is as a system integrator building CloudStack infrastructures. Therefore I would tend to go into a company deploy CloudStack and its associated infrastructure and also hypervisor hosts and then largely move on to the next project. My goal is to be able to define an environment in terms of the hosts and the configuration on those hosts in as few files as possible, separating the configuration from the playbooks for portability.

Using Ansible to configure the PXE and DHCP config means that I only need to describe the hosts in one place to build and configure the entire environment.

Kind regards

Paul Angus  
ShapeBlue  
@CloudyAngus

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 2, 2013, 2:49am UTC](https://forum.ansible.com/t/template-destination-logic/13814/4 "2013-11-02T02:49:50Z")

</div>

In this case, I’d strongly recommend just making a module:

tasks:

- pxe: mac=AA:BB:CC:DD:EE:FF kernel=kernel initrd=initrd root=/var/lib/tftpboot/pxelinux.cfg/

---

<div class="post-metadata">

**Author:** ![Paul\_Angus1](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@Paul\_Angus1](https://forum.ansible.com/u/Paul_Angus1)\
**Post date:** [November 6, 2013, 2:03pm UTC](https://forum.ansible.com/t/template-destination-logic/13814/5 "2013-11-06T14:03:58Z")

</div>

Taking baby steps, where would i put my hexify plugin? ansible/library?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 10, 2013, 9:15pm UTC](https://forum.ansible.com/t/template-destination-logic/13814/6 "2013-11-10T21:15:53Z")

</div>

Only modules (like ‘django\_manage’ is a module, or ‘pxe’ might be) go in library/.

The lookup plugin path is configurable in ansible.cfg

[http://ansibleworks.com/docs/intro\_configuration.html#filter-plugins](http://ansibleworks.com/docs/intro_configuration.html#filter-plugins)

[http://ansibleworks.com/docs/intro\_configuration.html#lookup-plugins](http://ansibleworks.com/docs/intro_configuration.html#lookup-plugins)

I think you’d want to write the module because it would be cleaner.
