Skip to content

Instantly share code, notes, and snippets.

@charandas
Created December 29, 2017 00:06
Show Gist options
  • Save charandas/0585f2dc64e0baf276d3e9cd36e05238 to your computer and use it in GitHub Desktop.
Save charandas/0585f2dc64e0baf276d3e9cd36e05238 to your computer and use it in GitHub Desktop.
rancher-agent registration with terraform on coreos container linux
storage:
files:
- filesystem: "root"
path: "/etc/hostname"
mode: 0644
contents:
inline: ${hostname}
- filesystem: "root"
path: "/etc/hosts"
mode: 0644
contents:
inline: "127.0.0.1 ${hostname} localhost\n
::1 ${hostname} localhost"
- filesystem: "root"
path: "/opt/rancher/rancher.sh"
mode: 0755
contents:
inline: |
#!/bin/sh
set -e
umask 077
${registration_command}
passwd:
users:
- name: core
ssh_authorized_keys:
- some key
systemd:
units:
- name: register-rancher-agent.service
enabled: true
mask: false
contents: |
[Unit]
Description=Setup rancher agent
[Service]
Type=oneshot
ExecStart=/opt/rancher/rancher.sh
RemainAfterExit=true
[Install]
WantedBy=multi-user.target
function (rancher) {
provider: {
rancher: {
api_url: rancher.api_url,
access_key: rancher.access_key,
secret_key: rancher.secret_key
}
},
resource: {
rancher_environment: {
target_environment: {
name: rancher.environment,
orchestration: "cattle"
}
},
rancher_registration_token: {
registration_token: {
count: "${local.count}",
environment_id: "${rancher_environment.target_environment.id}",
name: "registration_token",
description: "Host registration token for specified environment"
}
},
data: {
template_file: {
container_config: {
count: "${local.count}",
template: '${file("./templates/rancher_agents/container-config.tpl")}',
vars: {
hostname: "${lookup(local.hosts, count.index)}",
registration_command: "${element(rancher_registration_token.registration_token.*.command, count.index)}"
}
}
}
}
}
}
@charandas
Copy link
Author

For those who are new to jsonnet, you can convert the above to json. Just hard code your rancher info (keys/url).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment