Skip to content

Instantly share code, notes, and snippets.

@charandas
Created December 29, 2017 00:06
Show Gist options
  • Select an option

  • Save charandas/0585f2dc64e0baf276d3e9cd36e05238 to your computer and use it in GitHub Desktop.

Select an option

Save charandas/0585f2dc64e0baf276d3e9cd36e05238 to your computer and use it in GitHub Desktop.

Revisions

  1. charandas revised this gist Dec 29, 2017. 1 changed file with 46 additions and 0 deletions.
    46 changes: 46 additions & 0 deletions container-config.tpl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    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
  2. charandas created this gist Dec 29, 2017.
    37 changes: 37 additions & 0 deletions rancher.jsonnet
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    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)}"
    }
    }
    }
    }
    }
    }