Skip to content
This repository has been archived by the owner on Sep 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #6 from roquie/full_cfg
Browse files Browse the repository at this point in the history
Added full configuration and public IP auto-resolving feature. Powered by issue #4.
  • Loading branch information
roquie authored Oct 1, 2017
2 parents 6be7945 + 8004606 commit ae8e552
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 21 deletions.
54 changes: 53 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,59 @@
---

## Role variables ##

ka_resolvconf_install: yes

## Kontena main Variables ##

# Kontena Master websocket uri (required)
ka_master_uri: "ws://127.0.0.1:8080"

# Kontena Grid token (required)
ka_token: "secret_token"

# network interface for peer/private communication (default: eth1)
ka_peer_interface: "eth1"

ka_config_path: "{{ (ansible_distribution_release == 'xenial') | ternary('/etc/kontena-agent.env', '/etc/default/kontena-agent') }}"


## Kontena other variables ##

# ka public_ip variable will be overridden if this parameter is enabled
#ka_public_ip_auto_resolve: yes

# Specify node public ip, overrides default resolving
#ka_public_ip: ""

# Specify node private ip, overrides default resolving
#ka_private_ip: ""

# Logging level, http://www.rubydoc.info/gems/logger/1.2.8/Logger/Severity#INFO-constant
#ka_log_level: 1

# etcd image (default: kontena/etcd)
#ka_etcd_image: "kontena/etcd"

# etcd image version
#ka_etcd_version: "2.3.7"

# cadvisor image (default: kontena/cadvisor)
#ka_cadvisor_image: "kontena/cadvisor"

# cadvisor image version
#ka_cadvisor_version: "v0.24.1"

# if set to `true` agent won't start cadvisor at all
#ka_cadvisor_disabled: "false"

# weave net image (default: weaveworks/weave)
#ka_weave_image: "weaveworks/weave"

# weave exec image (default: weaveworks/weaveexec)
#ka_weaveexec_image: "weaveworks/weaveexec"

# weave net version
#ka_weave_version: "1.9.3"

# websocket timeout in seconds (default: 5.0)
#ka_websocket_timeout: 5.0
38 changes: 21 additions & 17 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
dest: /etc/apt/sources.list.d/kontena.list

- name: Ensure resolvconf is installed.
when: ka_resolvconf_install
package: name=resolvconf state=installed

- name: Install Kontena Agent without interactive mode & postinstall script
Expand All @@ -24,23 +25,26 @@
args:
chdir: /tmp # W: Can't drop privileges for downloading as file ...

- name: Setup Master URI inside env file
lineinfile:
path: "{{ ka_config_path }}"
regexp: "^KONTENA_URI="
line: "KONTENA_URI={{ ka_master_uri }}"

- name: Setup Token inside env file
lineinfile:
path: "{{ ka_config_path }}"
regexp: "^KONTENA_TOKEN="
line: "KONTENA_TOKEN={{ ka_token }}"

- name: Setup Peer Interface
lineinfile:
path: "{{ ka_config_path }}"
regexp: "^KONTENA_PEER_INTERFACE="
line: "KONTENA_PEER_INTERFACE={{ ka_peer_interface|default('eth1') }}"
- name: Get server public IP
when: ka_public_ip_auto_resolve|default(false)
ipify_facts:
register: resolve_result

- when: ka_public_ip_auto_resolve|default(false)
set_fact:
ka_public_ip: "{{ resolve_result.ansible_facts.ipify_public_ip }}"

- name: Configure Kontena Agent (xenial)
when: ansible_distribution_release == 'xenial'
template:
src: "templates/kontena-agent.env.j2"
dest: "/etc/kontena-agent.env"

- name: Configure Kontena Agent (trusty)
when: ansible_distribution_release == 'trusty'
template:
src: "templates/kontena-agent.env.j2"
dest: "/etc/default/kontena-agent"

- name: Restart services
when: ansible_distribution_release == "xenial"
Expand Down
97 changes: 97 additions & 0 deletions templates/kontena-agent.env.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#
# {{ ansible_managed }}
#

# Set URL of your kontena server
KONTENA_URI={{ ka_master_uri|default('ws://127.0.0.1:8080') }}

# Set Kontena token
KONTENA_TOKEN={{ ka_token|default('secret_token') }}

# Kontena peer interface (overlay network interface)
KONTENA_PEER_INTERFACE={{ ka_peer_interface }}

# Specify node public ip, overrides default resolving
{% if ka_public_ip is defined %}
KONTENA_PUBLIC_IP={{ ka_public_ip }}
{% else %}
#KONTENA_PUBLIC_IP={{ ka_public_ip|default('') }}
{% endif %}

# Specify node private ip, overrides default resolving
{% if ka_private_ip is defined %}
KONTENA_PRIVATE_IP={{ ka_private_ip }}
{% else %}
#KONTENA_PRIVATE_IP={{ ka_private_ip|default('') }}
{% endif %}

# Logging level, http://www.rubydoc.info/gems/logger/1.2.8/Logger/Severity#INFO-constant
{% if ka_log_level is defined %}
LOG_LEVEL={{ ka_log_level }}
{% else %}
#LOG_LEVEL={{ ka_log_level|default(1) }}
{% endif %}

# etcd image (default: kontena/etcd)
{% if ka_etcd_image is defined %}
ETCD_IMAGE={{ ka_etcd_image }}
{% else %}
#ETCD_IMAGE={{ ka_etcd_image|default('kontena/etcd') }}
{% endif %}

# etcd image version
{% if ka_etcd_version is defined %}
ETCD_VERSION={{ ka_etcd_version }}
{% else %}
#ETCD_VERSION={{ ka_etcd_version|default('2.3.7') }}
{% endif %}

# cadvisor image (default: kontena/cadvisor)
{% if ka_cadvisor_image is defined %}
CADVISOR_IMAGE={{ ka_cadvisor_image }}
{% else %}
#CADVISOR_IMAGE={{ ka_cadvisor_image|default('kontena/cadvisor') }}
{% endif %}

# cadvisor image version
{% if ka_cadvisor_version is defined %}
CADVISOR_VERSION={{ ka_cadvisor_version }}
{% else %}
#CADVISOR_VERSION={{ ka_cadvisor_version|default('v0.24.1') }}
{% endif %}

# if set to `true` agent won't start cadvisor at all
{% if ka_cadvisor_disabled is defined %}
CADVISOR_DISABLED={{ ka_cadvisor_disabled }}
{% else %}
#CADVISOR_DISABLED={{ ka_cadvisor_disabled|default('false') }}
{% endif %}

# weave net image (default: weaveworks/weave)
{% if ka_weave_image is defined %}
WEAVE_IMAGE={{ ka_weave_image }}
{% else %}
#WEAVE_IMAGE={{ ka_weave_image|default('weaveworks/weave') }}
{% endif %}

# weave exec image (default: weaveworks/weaveexec)
{% if ka_weaveexec_image is defined %}
WEAVEEXEC_IMAGE={{ ka_weaveexec_image }}
{% else %}
#WEAVEEXEC_IMAGE={{ ka_weaveexec_image|default('weaveworks/weaveexec') }}
{% endif %}

# weave net version
{% if ka_weave_version is defined %}
WEAVE_VERSION={{ ka_weave_version }}
{% else %}
#WEAVE_VERSION={{ ka_weave_version|default('1.9.3') }}
{% endif %}

# websocket timeout in seconds (default: 5.0)
{% if ka_websocket_timeout is defined %}
WEBSOCKET_TIMEOUT={{ ka_websocket_timeout }}
{% else %}
#WEBSOCKET_TIMEOUT={{ ka_websocket_timeout|default('5.0') }}
{% endif %}

2 changes: 1 addition & 1 deletion tests/playbooks/travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- hosts: local
pre_tasks:
- include_role: name=geerlingguy.ntp
- include_role: name=roquie.ansible-ntpdate
- include_role: name=galexrt.ansible-ntpdate
roles:
- role_under_test
tags:
Expand Down
2 changes: 1 addition & 1 deletion tests/playbooks/vagrant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- ../../../ansible-kontena-agent
post_tasks:
- include_role:
name: roquie.ansible-ntpdate
name: galexrt.ansible-ntpdate
tags:
- kontena_agent

2 changes: 1 addition & 1 deletion tests/requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- name: geerlingguy.docker
version: 2.0.5

- name: roquie.ansible-ntpdate
- name: galexrt.ansible-ntpdate

- name: geerlingguy.ntp
version: 1.5.2

0 comments on commit ae8e552

Please sign in to comment.