template destination logic

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

" 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/ 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.

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

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/

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

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#lookup-plugins

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