Foreman ENC and Facts

Hi everyone,

hopefully someone can point me in the right direction here
I started using foreman earlier this year,

The short of what i want to achieve is have Foreman Host Name field
provided as a fact so puppet can use it to ensure the hostname is enforced,
this is so when a machine is pre-created in foreman, puppet can ensure its
hostname is always correct,
also making renaming the machine possible via foreman.

The most obvious place to find this information is via the YAML output
values provided per host, specifically the primary interface's name value.
however is this the best source, is it possible to get the host name from
the Name* field when you go to edit a host, thus allowing for the direct
change if its name is changed?

any assistance would be greatly appreciated, even if its a simple push in a
certain direction.

Cheers,
Luke

It's possible to make some kind of a workaround (like with everything).
You have to remember that the default enc script request the YAML from
Foreman using the Puppet's agent certname.
If you just change the hostname it still request the YAML using the old
"hostname" (certname).
If you really need this, you can use UUID generated certs or implement a
small module that will trigger a rename (for example, if the certname
differs from the hostname foreman gives)
This rename will need to regenerate certs, etc and resend the facts to
Foreman

I will take a very caution for when using it as if by mistake someone will
use an old hostname (that was renamed) it can create some issues which as
sometimes will be difficult to debug.

As with any CM it all depends on your environment, team, workflows
implemented, etc…

··· On Wednesday, September 7, 2016 at 6:41:14 AM UTC+3, Luke Tinker wrote: > > Hi everyone, > > hopefully someone can point me in the right direction here > I started using foreman earlier this year, > > The short of what i want to achieve is have Foreman Host Name field > provided as a fact so puppet can use it to ensure the hostname is enforced, > this is so when a machine is pre-created in foreman, puppet can ensure its > hostname is always correct, > also making renaming the machine possible via foreman. > > The most obvious place to find this information is via the YAML output > values provided per host, specifically the primary interface's name value. > however is this the best source, is it possible to get the host name from > the Name* field when you go to edit a host, thus allowing for the direct > change if its name is changed? > > any assistance would be greatly appreciated, even if its a simple push in > a certain direction. > > Cheers, > Luke > > > >

Hello

I'd say it's a good source. A host name + primary interface domain name is
what give us host FQDN. Host name is always synced to primary interface name.

Hope this helps

··· On Tuesday 06 of September 2016 20:41:13 Luke Tinker wrote: > Hi everyone, > > hopefully someone can point me in the right direction here > I started using foreman earlier this year, > > The short of what i want to achieve is have Foreman Host Name field > provided as a fact so puppet can use it to ensure the hostname is enforced, > this is so when a machine is pre-created in foreman, puppet can ensure its > hostname is always correct, > also making renaming the machine possible via foreman. > > The most obvious place to find this information is via the YAML output > values provided per host, specifically the primary interface's name value. > however is this the best source, is it possible to get the host name from > the Name* field when you go to edit a host, thus allowing for the direct > change if its name is changed? > > any assistance would be greatly appreciated, even if its a simple push in a > certain direction. > > Cheers, > Luke


Marek

Hi Erez and Marek,

I should have explained my setup a little more,
I am generating certificates based on a Unique Identifier so the names are
quite separate from the certificates used to identify with puppet,
however the names in foreman need to be very accurate for everything to
work smoothly.

I thought using the name value from the interface with the primary marked
as true would be the best option,
just wasn't sure if there was some easier option,
I'm still having trying to learn how to work best with an ENC as i find it
difficult to test while writing config,
so figuring out how to leverage this will be interesting,
if you have any tips it would be greatly appreciated.

Cheers for the help,
Luke

··· On Wednesday, 7 September 2016 18:21:18 UTC+10, Erez Zarum wrote: > > It's possible to make some kind of a workaround (like with everything). > You have to remember that the default enc script request the YAML from > Foreman using the Puppet's agent certname. > If you just change the hostname it still request the YAML using the old > "hostname" (certname). > If you really need this, you can use UUID generated certs or implement a > small module that will trigger a rename (for example, if the certname > differs from the hostname foreman gives) > This rename will need to regenerate certs, etc and resend the facts to > Foreman > > I will take a very caution for when using it as if by mistake someone will > use an old hostname (that was renamed) it can create some issues which as > sometimes will be difficult to debug. > > As with any CM it all depends on your environment, team, workflows > implemented, etc... > > > > On Wednesday, September 7, 2016 at 6:41:14 AM UTC+3, Luke Tinker wrote: >> >> Hi everyone, >> >> hopefully someone can point me in the right direction here >> I started using foreman earlier this year, >> >> The short of what i want to achieve is have Foreman Host Name field >> provided as a fact so puppet can use it to ensure the hostname is enforced, >> this is so when a machine is pre-created in foreman, puppet can ensure >> its hostname is always correct, >> also making renaming the machine possible via foreman. >> >> The most obvious place to find this information is via the YAML output >> values provided per host, specifically the primary interface's name value. >> however is this the best source, is it possible to get the host name from >> the Name* field when you go to edit a host, thus allowing for the direct >> change if its name is changed? >> >> any assistance would be greatly appreciated, even if its a simple push in >> a certain direction. >> >> Cheers, >> Luke >> >> >> >>

Thanks for the help Marek,

How do i access consume the primary interface details in puppet?
forman_interface: provides the array of mac addresses,
however because i don't know the mac address that is primary i am not sure
how to check the attributes associated with it,
i cant find any examples of how to go about this.

what i want to do is go,

$hostname = foreman_interface:mac:00:00:00:00:name if
foreman_interface:mac:00:00:00:00:primary

··· On Wednesday, 7 September 2016 17:38:42 UTC+10, Marek Hulán wrote: > > On Tuesday 06 of September 2016 20:41:13 Luke Tinker wrote: > > Hi everyone, > > > > hopefully someone can point me in the right direction here > > I started using foreman earlier this year, > > > > The short of what i want to achieve is have Foreman Host Name field > > provided as a fact so puppet can use it to ensure the hostname is > enforced, > > this is so when a machine is pre-created in foreman, puppet can ensure > its > > hostname is always correct, > > also making renaming the machine possible via foreman. > > > > The most obvious place to find this information is via the YAML output > > values provided per host, specifically the primary interface's name > value. > > however is this the best source, is it possible to get the host name > from > > the Name* field when you go to edit a host, thus allowing for the direct > > change if its name is changed? > > > > any assistance would be greatly appreciated, even if its a simple push > in a > > certain direction. > > > > Cheers, > > Luke > > Hello > > I'd say it's a good source. A host name + primary interface domain name is > what give us host FQDN. Host name is always synced to primary interface > name. > > Hope this helps > > -- > Marek >

You can always debug with facter
$ facter networking.hostname networking.fqdn networking.primary
networking.mac networking.interfaces.eth0.mac
networking.fqdn => server01.example.com
networking.hostname => server01
networking.interfaces.eth0.mac => 00:50:51:8f:dg:a3
networking.mac => 00:50:51:8f:dg:a3
networking.primary => eth0

··· On Thursday, September 8, 2016 at 10:56:43 AM UTC+3, Luke Tinker wrote: > > Thanks for the help Marek, > > How do i access consume the primary interface details in puppet? > forman_interface: provides the array of mac addresses, > however because i don't know the mac address that is primary i am not sure > how to check the attributes associated with it, > i cant find any examples of how to go about this. > > what i want to do is go, > > $hostname = foreman_interface:mac:00:00:00:00:name if > foreman_interface:mac:00:00:00:00:primary > > On Wednesday, 7 September 2016 17:38:42 UTC+10, Marek Hulán wrote: >> >> On Tuesday 06 of September 2016 20:41:13 Luke Tinker wrote: >> > Hi everyone, >> > >> > hopefully someone can point me in the right direction here >> > I started using foreman earlier this year, >> > >> > The short of what i want to achieve is have Foreman Host Name field >> > provided as a fact so puppet can use it to ensure the hostname is >> enforced, >> > this is so when a machine is pre-created in foreman, puppet can ensure >> its >> > hostname is always correct, >> > also making renaming the machine possible via foreman. >> > >> > The most obvious place to find this information is via the YAML output >> > values provided per host, specifically the primary interface's name >> value. >> > however is this the best source, is it possible to get the host name >> from >> > the Name* field when you go to edit a host, thus allowing for the >> direct >> > change if its name is changed? >> > >> > any assistance would be greatly appreciated, even if its a simple push >> in a >> > certain direction. >> > >> > Cheers, >> > Luke >> >> Hello >> >> I'd say it's a good source. A host name + primary interface domain name >> is >> what give us host FQDN. Host name is always synced to primary interface >> name. >> >> Hope this helps >> >> -- >> Marek >> >

I thought you could not access server facts from a host?
which is part of what has made trying to get my head around consuming some
of the outputs from the ENC.

Cheers,
Luke

··· On Thursday, 8 September 2016 20:55:27 UTC+10, Erez Zarum wrote: > > You can always debug with facter > $ facter networking.hostname networking.fqdn networking.primary > networking.mac networking.interfaces.eth0.mac > networking.fqdn => server01.example.com > networking.hostname => server01 > networking.interfaces.eth0.mac => 00:50:51:8f:dg:a3 > networking.mac => 00:50:51:8f:dg:a3 > networking.primary => eth0 > > > > On Thursday, September 8, 2016 at 10:56:43 AM UTC+3, Luke Tinker wrote: >> >> Thanks for the help Marek, >> >> How do i access consume the primary interface details in puppet? >> forman_interface: provides the array of mac addresses, >> however because i don't know the mac address that is primary i am not >> sure how to check the attributes associated with it, >> i cant find any examples of how to go about this. >> >> what i want to do is go, >> >> $hostname = foreman_interface:mac:00:00:00:00:name if >> foreman_interface:mac:00:00:00:00:primary >> >> On Wednesday, 7 September 2016 17:38:42 UTC+10, Marek Hulán wrote: >>> >>> On Tuesday 06 of September 2016 20:41:13 Luke Tinker wrote: >>> > Hi everyone, >>> > >>> > hopefully someone can point me in the right direction here >>> > I started using foreman earlier this year, >>> > >>> > The short of what i want to achieve is have Foreman Host Name field >>> > provided as a fact so puppet can use it to ensure the hostname is >>> enforced, >>> > this is so when a machine is pre-created in foreman, puppet can ensure >>> its >>> > hostname is always correct, >>> > also making renaming the machine possible via foreman. >>> > >>> > The most obvious place to find this information is via the YAML output >>> > values provided per host, specifically the primary interface's name >>> value. >>> > however is this the best source, is it possible to get the host name >>> from >>> > the Name* field when you go to edit a host, thus allowing for the >>> direct >>> > change if its name is changed? >>> > >>> > any assistance would be greatly appreciated, even if its a simple push >>> in a >>> > certain direction. >>> > >>> > Cheers, >>> > Luke >>> >>> Hello >>> >>> I'd say it's a good source. A host name + primary interface domain name >>> is >>> what give us host FQDN. Host name is always synced to primary interface >>> name. >>> >>> Hope this helps >>> >>> -- >>> Marek >>> >>

What do you mean?
This was running on a host/puppet agent (not the puppet master server),
it's the host's facts

··· On Friday, September 9, 2016 at 3:17:55 AM UTC+3, Luke Tinker wrote: > > I thought you could not access server facts from a host? > which is part of what has made trying to get my head around consuming some > of the outputs from the ENC. > > Cheers, > Luke > > On Thursday, 8 September 2016 20:55:27 UTC+10, Erez Zarum wrote: >> >> You can always debug with facter >> $ facter networking.hostname networking.fqdn networking.primary >> networking.mac networking.interfaces.eth0.mac >> networking.fqdn => server01.example.com >> networking.hostname => server01 >> networking.interfaces.eth0.mac => 00:50:51:8f:dg:a3 >> networking.mac => 00:50:51:8f:dg:a3 >> networking.primary => eth0 >> >> >> >> On Thursday, September 8, 2016 at 10:56:43 AM UTC+3, Luke Tinker wrote: >>> >>> Thanks for the help Marek, >>> >>> How do i access consume the primary interface details in puppet? >>> forman_interface: provides the array of mac addresses, >>> however because i don't know the mac address that is primary i am not >>> sure how to check the attributes associated with it, >>> i cant find any examples of how to go about this. >>> >>> what i want to do is go, >>> >>> $hostname = foreman_interface:mac:00:00:00:00:name if >>> foreman_interface:mac:00:00:00:00:primary >>> >>> On Wednesday, 7 September 2016 17:38:42 UTC+10, Marek Hulán wrote: >>>> >>>> On Tuesday 06 of September 2016 20:41:13 Luke Tinker wrote: >>>> > Hi everyone, >>>> > >>>> > hopefully someone can point me in the right direction here >>>> > I started using foreman earlier this year, >>>> > >>>> > The short of what i want to achieve is have Foreman Host Name field >>>> > provided as a fact so puppet can use it to ensure the hostname is >>>> enforced, >>>> > this is so when a machine is pre-created in foreman, puppet can >>>> ensure its >>>> > hostname is always correct, >>>> > also making renaming the machine possible via foreman. >>>> > >>>> > The most obvious place to find this information is via the YAML >>>> output >>>> > values provided per host, specifically the primary interface's name >>>> value. >>>> > however is this the best source, is it possible to get the host name >>>> from >>>> > the Name* field when you go to edit a host, thus allowing for the >>>> direct >>>> > change if its name is changed? >>>> > >>>> > any assistance would be greatly appreciated, even if its a simple >>>> push in a >>>> > certain direction. >>>> > >>>> > Cheers, >>>> > Luke >>>> >>>> Hello >>>> >>>> I'd say it's a good source. A host name + primary interface domain name >>>> is >>>> what give us host FQDN. Host name is always synced to primary interface >>>> name. >>>> >>>> Hope this helps >>>> >>>> -- >>>> Marek >>>> >>>

Hi Erez,

Thats what i suspected,
I want to use foremans ENC to set the hostname,
foreman stores a hostname against each interface/mac address,
as Marek mentioned Hostname is always synced to the primary interface name
in foreman,
the primary interface value is not a node side fact and is only in the ENC

what i'm stuck on is how to consume that information in puppet,
how can i retrieve the information,
if i could iterate i would iterate through each item (mac address) in
foreman_interfaces: and return the hostname value for the item(mac address)
that has primary = true

here is a cleaned output of a hosts YAML output provided by the ENC for
foreman as an example of what i am looking at.

parameters:
puppetmaster: puppet
hostgroup: HostGroup1/Example2
root_pw:
foreman_env: development
owner_name:
owner_email:
foreman_subnets: []
foreman_interfaces:

  • mac: 6a:ab:a5:a4:1a:99
    ip: 10.1.1.1
    type: Interface
    name: myhost.mydomain.tld
    attrs:
    netmask: 255.255.255.0
    mtu: '1500'
    network: 10.1.1.0
    virtual: false
    link: true
    identifier: en0
    managed: true
    primary: true
    provision: true
    subnet:
  • mac: a8:a0:ab:5a:ea:1f
    ip:
    type: Interface
    name: ''
    attrs:
    mtu: '1500'
    virtual: false
    link: true
    identifier: en1
    managed: false
    primary: false
    provision: false
    subnet:

Cheers,
Luke

··· On Friday, 9 September 2016 22:19:17 UTC+10, Erez Zarum wrote: > > What do you mean? > This was running on a host/puppet agent (not the puppet master server), > it's the host's facts > > On Friday, September 9, 2016 at 3:17:55 AM UTC+3, Luke Tinker wrote: >> >> I thought you could not access server facts from a host? >> which is part of what has made trying to get my head around consuming >> some of the outputs from the ENC. >> >> Cheers, >> Luke >> >> On Thursday, 8 September 2016 20:55:27 UTC+10, Erez Zarum wrote: >>> >>> You can always debug with facter >>> $ facter networking.hostname networking.fqdn networking.primary >>> networking.mac networking.interfaces.eth0.mac >>> networking.fqdn => server01.example.com >>> networking.hostname => server01 >>> networking.interfaces.eth0.mac => 00:50:51:8f:dg:a3 >>> networking.mac => 00:50:51:8f:dg:a3 >>> networking.primary => eth0 >>> >>> >>> >>> On Thursday, September 8, 2016 at 10:56:43 AM UTC+3, Luke Tinker wrote: >>>> >>>> Thanks for the help Marek, >>>> >>>> How do i access consume the primary interface details in puppet? >>>> forman_interface: provides the array of mac addresses, >>>> however because i don't know the mac address that is primary i am not >>>> sure how to check the attributes associated with it, >>>> i cant find any examples of how to go about this. >>>> >>>> what i want to do is go, >>>> >>>> $hostname = foreman_interface:mac:00:00:00:00:name if >>>> foreman_interface:mac:00:00:00:00:primary >>>> >>>> On Wednesday, 7 September 2016 17:38:42 UTC+10, Marek Hulán wrote: >>>>> >>>>> On Tuesday 06 of September 2016 20:41:13 Luke Tinker wrote: >>>>> > Hi everyone, >>>>> > >>>>> > hopefully someone can point me in the right direction here >>>>> > I started using foreman earlier this year, >>>>> > >>>>> > The short of what i want to achieve is have Foreman Host Name field >>>>> > provided as a fact so puppet can use it to ensure the hostname is >>>>> enforced, >>>>> > this is so when a machine is pre-created in foreman, puppet can >>>>> ensure its >>>>> > hostname is always correct, >>>>> > also making renaming the machine possible via foreman. >>>>> > >>>>> > The most obvious place to find this information is via the YAML >>>>> output >>>>> > values provided per host, specifically the primary interface's name >>>>> value. >>>>> > however is this the best source, is it possible to get the host name >>>>> from >>>>> > the Name* field when you go to edit a host, thus allowing for the >>>>> direct >>>>> > change if its name is changed? >>>>> > >>>>> > any assistance would be greatly appreciated, even if its a simple >>>>> push in a >>>>> > certain direction. >>>>> > >>>>> > Cheers, >>>>> > Luke >>>>> >>>>> Hello >>>>> >>>>> I'd say it's a good source. A host name + primary interface domain >>>>> name is >>>>> what give us host FQDN. Host name is always synced to primary >>>>> interface name. >>>>> >>>>> Hope this helps >>>>> >>>>> -- >>>>> Marek >>>>> >>>>

Hello Luke

based on output you sent you can tell which one is primary. I think you'd have
to write some puppet function for finding it in that array. Also this [1]
puppet module could be used for inspiration for how to parse ENC data.

[1] https://github.com/treydock/puppet-foreman_networking

Hope this helps

··· -- Marek

On Sunday 11 of September 2016 22:21:55 Luke Tinker wrote:

foreman_interfaces:

  • mac: 6a:ab:a5:a4:1a:99
    ip: 10.1.1.1
    type: Interface
    name: myhost.mydomain.tld
    attrs:
    netmask: 255.255.255.0
    mtu: '1500’
    network: 10.1.1.0
    virtual: false
    link: true
    identifier: en0
    managed: true
    primary: true

this is primary interface

provision: true
subnet: 
  • mac: a8:a0:ab:5a:ea:1f
    ip:
    type: Interface
    name: ''
    attrs:
    mtu: '1500’
    virtual: false
    link: true
    identifier: en1
    managed: false
    primary: false

this is not :slight_smile:

provision: false
subnet: