how to puppet and diff without fqdn?

182 Views Asked by At

I have one problem, that how to manage the agent-nodes with puppet?

I'm using the openstack to auto generating the vms, and then puppet with several puppet-code in special pattern.

eg.

The system provision several vms, each vm has two attrs:

fqdn: maybe repeat(you know the vms are genrate by system in a complex env)

uuid: this will be unique, and is stored in a persistent file. it won't change

and below are two of them.

VM1:

fqdn: api-server.expamle.com
uuid: 20a558f1-2cd9-4068-b5fc-8d252c3f3262

VM2:

fqdn: api-server.expamle.com
uuid: 096359d6-5dc9-47e9-946a-bd702fe7c2d5

(Also, I can specify the hostname with the uuid, but I think it's not a good idea.)

and now I want to puppet them with puppet kick or mcollective puppet runonce.

with mco, i can choose the facter uuid, that will diff VM1&VM2.

mco pupppetd runonce --with-facter uuid=20a558f1-2cd9-4068-b5fc-8d252c3f3262

but I STILL MUST hardcode the fqdn in the puppet-code

node api-server.expamle.com {
    ...
}

but in fact, I just want use it in the following style:

facter 20a558f1-2cd9-4068-b5fc-8d252c3f3262 {
    ...
}
facter 096359d6-5dc9-47e9-946a-bd702fe7c2d5 {
    ...
}

how can I write the puppet? or do some change in the architecture?

1

There are 1 best solutions below

1
On

There are multiple ways of assigning roles/classifying a node in puppet.

A solution closer to the example you provided would be to use the following node.pp file

node default {

  case $::uuid {
    "20a558f1-2cd9-4068-b5fc-8d252c3f3262": {
        include apache
        ...
    }
    "096359d6-5dc9-47e9-946a-bd702fe7c2d5": {
        include ngnix
        ...
    }
    default: {
        ...
    }
  }

}

Saying that, I am not sure that this is the best solution. There are better ways assigning classes/roles to a node.

I would suggest to look at puppet hiera (http://docs.puppetlabs.com/hiera/1/complete_example.html) or ENC (http://docs.puppetlabs.com/guides/external_nodes.html) for better mechanisms.