Skip to content

Commit 5fe2f32

Browse files
committed
Add ability to define additional puppet agent config settings
1 parent d9e6d19 commit 5fe2f32

8 files changed

Lines changed: 35 additions & 8 deletions

File tree

aws/infrastructure.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module "configuration" {
3232
cloud_provider = local.cloud_provider
3333
cloud_region = local.cloud_region
3434
skip_upgrade = var.skip_upgrade
35+
puppet_conf = var.puppet_conf
3536
}
3637

3738
module "provision" {

azure/infrastructure.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module "configuration" {
3232
cloud_provider = local.cloud_provider
3333
cloud_region = local.cloud_region
3434
skip_upgrade = var.skip_upgrade
35+
puppet_conf = var.puppet_conf
3536
}
3637

3738
module "provision" {

common/configuration/main.tf

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ locals {
99

1010
variable "config_git_url" {}
1111
variable "config_version" {}
12+
variable "puppet_conf" {}
1213

1314
variable "sudoer_username" {}
1415

@@ -92,6 +93,20 @@ locals {
9293
software_stack = var.software_stack,
9394
})
9495

96+
puppetservers = {
97+
for host, values in var.inventory : host => try(values.local_ip, "") if contains(values.tags, "puppet")
98+
}
99+
puppet_conf = concat(
100+
length(local.puppetservers) > 0 ? [
101+
{ key = "server", value = keys(local.puppetservers)[0], section = "main" }
102+
] : [],
103+
[
104+
{ key = "waitforcert", value = "15s", section = "main" },
105+
{ key = "report", value = "true", section = "main" },
106+
{ key = "postrun_command", value = "/opt/puppetlabs/bin/postrun", section = "main" }
107+
],
108+
)
109+
95110
user_data = {
96111
for key, values in var.inventory : key =>
97112
templatefile("${path.module}/puppet.yaml.tftpl",
@@ -105,8 +120,9 @@ locals {
105120
domain_name = var.domain_name
106121
puppetenv_git = var.config_git_url,
107122
puppetenv_rev = var.config_version,
108-
puppetservers = { for host, values in var.inventory : host => try(values.local_ip, "") if contains(values.tags, "puppet") }
123+
puppetservers = local.puppetservers
109124
puppetserver_password = local.puppet_passwd,
125+
puppet_conf = concat(local.puppet_conf, var.puppet_conf, [{ key = "certname", value = key, section = "main" }])
110126
sudoer_username = var.sudoer_username,
111127
ssh_authorized_keys = local.public_keys
112128
tf_ssh_public_key = chomp(tls_private_key.ssh.public_key_openssh)

common/configuration/puppet.yaml.tftpl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,9 @@ runcmd:
134134
%{ endif ~}
135135
- chgrp puppet /etc/puppetlabs/puppet/csr_attributes.yaml
136136
%{ endif ~}
137-
%{ if length(puppetservers) > 0 ~}
138-
- /opt/puppetlabs/bin/puppet config set server ${keys(puppetservers)[0]}
139-
%{ endif ~}
140-
- /opt/puppetlabs/bin/puppet config set certname ${node_name}
141-
- /opt/puppetlabs/bin/puppet config set waitforcert 15s
142-
- /opt/puppetlabs/bin/puppet config set report true
143-
- /opt/puppetlabs/bin/puppet config set postrun_command /opt/puppetlabs/bin/postrun
137+
%{ for conf in puppet_conf ~}
138+
- ${jsonencode(["/opt/puppetlabs/bin/puppet", "config", "set", conf.key, conf.value, "--section", conf.section])}
139+
%{ endfor ~}
144140
- systemctl enable puppet
145141
# Remove all ifcfg configuration files that have no corresponding network interface in ip link show.
146142
- for i in /etc/sysconfig/network-scripts/ifcfg-*; do if ! ip link show | grep -q "$${i##*-}:"; then rm -f $i; fi; done

common/variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,13 @@ variable "bastion_tags" {
179179
default = []
180180
description = "Tags identifying instances that can be used by Terraform as the first hop to transfer files to the Puppet server."
181181
}
182+
183+
variable "puppet_conf" {
184+
type = list(object({
185+
key = string
186+
value = string
187+
section = optional(string, "main")
188+
}))
189+
default = []
190+
description = "List of additional settings for Puppet agent https://help.puppet.com/core/current/Content/PuppetCore/Markdown/configuration.htm"
191+
}

gcp/infrastructure.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module "configuration" {
3232
cloud_provider = local.cloud_provider
3333
cloud_region = local.cloud_region
3434
skip_upgrade = var.skip_upgrade
35+
puppet_conf = var.puppet_conf
3536
}
3637

3738
module "provision" {

incus/infrastructure.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module "configuration" {
2828
cloud_provider = "incus"
2929
cloud_region = "local"
3030
skip_upgrade = var.skip_upgrade
31+
puppet_conf = var.puppet_conf
3132
}
3233

3334
module "provision" {

openstack/infrastructure.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module "configuration" {
2727
cloud_provider = local.cloud_provider
2828
cloud_region = local.cloud_region
2929
skip_upgrade = var.skip_upgrade
30+
puppet_conf = var.puppet_conf
3031
}
3132

3233
module "provision" {

0 commit comments

Comments
 (0)