How to define multiple /etc/hosts entries with Puppet ENC?

Solution 1:

ad 1 & 2:

host {
  'front-01': ip => '192.168.1.103';
  'front-02': ip => '192.168.1.106';
}

is just a shortened notation for

host { 'front-01':
  ip => '192.168.1.103',
}
host { 'front-02':
  ip => '192.168.1.106',
}

ad 3:

When you have a YAML data entry like this:

custom_hosts:
  www1:
    ip: 1.2.3.4
  www2:
    ip: 1.2.3.5
    comment: other attributes work also
  www3:
    name: testserver
    ip: 1.2.3.6

you can load it into a puppet hash and then create resources from it

$custom_hosts = hiera('custom_hosts',{})
create_resources(host, $custom_hosts)

This yields the same result as:

host { 'www1':
  ip => '1.2.3.4',
}
host { 'www2':
  ip      => '1.2.3.5',
  comment => 'other attributes work also',
}
host { 'www3':
  name => 'testserver',
  ip   => '1.2.3.6',
}

So these lines should be written to /etc/hosts:

1.2.3.4 www1
1.2.3.5 www2 # other attributes work also
1.2.3.6 testserver