user1240076
user1240076

Reputation: 303

How to purge unmanaged hosts entries when hosts file has non-standard location?

I am using resource host. During my experiments the resource type "resources" has no impacts if a host resource is using a non-standard target.

resources { 'host':
  purge => true,
}

host { 'localhost.localdomain':
  ip           => '127.0.0.1',
  target       => '/chroot/etc/hosts',
}

When I am using target /etc/hosts and I remove the host resource or rename it the output is:

Info: Applying configuration version '1560267493'
Notice: /Stage[main]/Profile:abc:Hosts/Host[localhost.localdomain]/ensure: removed
Info: Computing checksum on file /etc/hosts
Notice: /Stage[main]/Profile::abc:Hosts/Host[localhost.localdomain]/ensure: created

When I am using non standard target e.g. /chroot/etc/hosts nothing happens. (If I rename the entry then just another host entry is created)

Another strange behaviour is that when there is no /etc/hosts file on the agent node an error is thrown: (even if I am using a different target.) Error: Could not find a suitable provider for host

Versions: Puppetserver: 5.3.8, puppet agent: 4.10.8

Upvotes: 1

Views: 296

Answers (1)

John Bollinger
John Bollinger

Reputation: 180201

I am using resource host. During my experiments the resource type "resources" has no impacts if a host resource is using a non-standard target.

That is not surprising. The resources resource type can purge only resource instances that the specified resource type "prefetches". For the Host resource type, this is hosts recorded in the default hosts file. This is the reason for the documented limitation that a Resources cannot purge type ssh_authorized_key. For that, as for hosts in other target files, Puppet has no way to identify the resources you want to purge.

Another strange behaviour is that when there is no /etc/hosts file on the agent node an error is thrown: (even if I am using a different target.) Error: Could not find a suitable provider for host

I would account that a bug. You could consider filing a ticket.

Upvotes: 1

Related Questions