diff --git a/roles/coreos-bootstrap/tasks/main.yml b/roles/coreos-bootstrap/tasks/main.yml index 4d9e11ea6..3c3428827 100644 --- a/roles/coreos-bootstrap/tasks/main.yml +++ b/roles/coreos-bootstrap/tasks/main.yml @@ -42,6 +42,7 @@ - name: Check configured hostname shell: hostname register: configured_hostname + changed_when: false - name: Assign inventory name to unconfigured hostnames shell: sh -c "echo \"{{inventory_hostname}}\" > /etc/hostname; hostname \"{{inventory_hostname}}\"" diff --git a/roles/etcd/defaults/main.yml b/roles/etcd/defaults/main.yml index 63f485719..30f681dc2 100644 --- a/roles/etcd/defaults/main.yml +++ b/roles/etcd/defaults/main.yml @@ -2,9 +2,5 @@ etcd_version: v3.0.1 etcd_bin_dir: "{{ local_release_dir }}/etcd/etcd-{{ etcd_version }}-linux-amd64/" -# Possible values: host, docker -etcd_deployment_type: "host" - - etcd_image_repo: "quay.io/coreos/etcd" etcd_image_tag: "{{ etcd_version }}" diff --git a/roles/etcd/handlers/main.yml b/roles/etcd/handlers/main.yml index 334a4c396..ee5344e07 100644 --- a/roles/etcd/handlers/main.yml +++ b/roles/etcd/handlers/main.yml @@ -19,4 +19,4 @@ - name: reload etcd service: name: etcd - state: "{{ 'restarted' if etcd_deployment_type == 'host' else 'reloaded' }}" + state: reloaded diff --git a/roles/etcd/meta/main.yml b/roles/etcd/meta/main.yml index 84d029d58..81ff6c641 100644 --- a/roles/etcd/meta/main.yml +++ b/roles/etcd/meta/main.yml @@ -3,8 +3,6 @@ dependencies: - role: adduser user: "{{ addusers.etcd }}" when: ansible_os_family != 'CoreOS' - - role: download - file: "{{ downloads.etcd }}" - when: etcd_deployment_type == "host" + - role: kubernetes/common - role: docker - when: (ansible_os_family != "CoreOS" and etcd_deployment_type == "docker") + when: ansible_os_family != "CoreOS" diff --git a/roles/etcd/tasks/configure.yml b/roles/etcd/tasks/configure.yml index 818559239..77f561bce 100644 --- a/roles/etcd/tasks/configure.yml +++ b/roles/etcd/tasks/configure.yml @@ -12,7 +12,7 @@ - name: Configure | Copy etcd.service systemd file template: - src: "etcd-{{ etcd_deployment_type }}.service.j2" + src: "etcd.service.j2" dest: /etc/systemd/system/etcd.service backup: yes when: ansible_service_mgr == "systemd" @@ -20,7 +20,7 @@ - name: Configure | Write etcd initd script template: - src: "deb-etcd-{{ etcd_deployment_type }}.initd.j2" + src: "deb-etcd.initd.j2" dest: /etc/init.d/etcd owner: root mode: 0755 diff --git a/roles/etcd/tasks/install.yml b/roles/etcd/tasks/install.yml deleted file mode 100644 index 26271943a..000000000 --- a/roles/etcd/tasks/install.yml +++ /dev/null @@ -1,39 +0,0 @@ ---- -- name: Install | Copy etcd binary from downloaddir - command: rsync -piu "{{ etcd_bin_dir }}/etcd" "{{ bin_dir }}/etcd" - when: etcd_deployment_type == "host" - register: etcd_copy - changed_when: false - -- name: Install | Copy etcdctl binary from downloaddir - command: rsync -piu "{{ etcd_bin_dir }}/etcdctl" "{{ bin_dir }}/etcdctl" - when: etcd_deployment_type == "host" - changed_when: false - -#Plan A: no docker-py deps -- name: Install | Copy etcdctl binary from container - command: sh -c "/usr/bin/docker rm -f etcdctl-binarycopy; - /usr/bin/docker create --name etcdctl-binarycopy {{ etcd_image_repo }}:{{ etcd_image_tag }} && - /usr/bin/docker cp etcdctl-binarycopy:{{ etcd_container_bin_dir }}etcdctl {{ bin_dir }}/etcdctl && - /usr/bin/docker rm -f etcdctl-binarycopy" - when: etcd_deployment_type == "docker" - changed_when: false - -#Plan B: looks nicer, but requires docker-py on all hosts: -#- name: Install | Set up etcd-binarycopy container -# docker: -# name: etcd-binarycopy -# state: present -# image: "{{ etcd_image_repo }}:{{ etcd_image_tag }}" -# when: etcd_deployment_type == "docker" -# -#- name: Install | Copy etcdctl from etcd-binarycopy container -# command: /usr/bin/docker cp "etcd-binarycopy:{{ etcd_container_bin_dir }}etcdctl" "{{ bin_dir }}/etcdctl" -# when: etcd_deployment_type == "docker" -# -#- name: Install | Clean up etcd-binarycopy container -# docker: -# name: etcd-binarycopy -# state: absent -# image: "{{ etcd_image_repo }}:{{ etcd_image_tag }}" -# when: etcd_deployment_type == "docker" diff --git a/roles/etcd/tasks/main.yml b/roles/etcd/tasks/main.yml index 060d3708b..6d67b79a7 100644 --- a/roles/etcd/tasks/main.yml +++ b/roles/etcd/tasks/main.yml @@ -1,14 +1,18 @@ --- - include: set_facts.yml -- include: install.yml -- include: set_cluster_health.yml -- include: configure.yml -- include: refresh_config.yml -- name: Restart etcd if binary changed - command: /bin/true - notify: restart etcd - when: etcd_deployment_type == "host" and etcd_copy.stdout_lines +- name: Install | Copy etcdctl binary from container + command: sh -c "/usr/bin/docker rm -f etcdctl-binarycopy; + /usr/bin/docker create --name etcdctl-binarycopy {{ etcd_image_repo }}:{{ etcd_image_tag }} && + /usr/bin/docker cp etcdctl-binarycopy:{{ etcd_container_bin_dir }}etcdctl {{ bin_dir }}/etcdctl && + /usr/bin/docker rm -f etcdctl-binarycopy" + changed_when: false + +- include: set_cluster_health.yml + +- include: configure.yml + +- include: refresh_config.yml # Reload systemd before starting service - meta: flush_handlers diff --git a/roles/etcd/tasks/set_facts.yml b/roles/etcd/tasks/set_facts.yml index 415ed85c6..be0eab0a8 100644 --- a/roles/etcd/tasks/set_facts.yml +++ b/roles/etcd/tasks/set_facts.yml @@ -1,19 +1,23 @@ --- -- set_fact: etcd_access_address="{{ access_ip | default(ip | default(ansible_default_ipv4['address'])) }}" +- set_fact: etcd_access_address="{{access_ip | default(ip | default(ansible_default_ipv4['address']))}}" - set_fact: etcd_peer_url="http://{{ etcd_access_address }}:2380" - set_fact: etcd_client_url="http://{{ etcd_access_address }}:2379" + - set_fact: etcd_access_addresses: |- {% for item in groups['etcd'] -%} http://{{ hostvars[item].etcd_access_address }}:2379{% if not loop.last %},{% endif %} {%- endfor %} + - set_fact: etcd_member_name: |- {% for host in groups['etcd'] %} {% if inventory_hostname == host %}{{"etcd"+loop.index|string }}{% endif %} {% endfor %} + - set_fact: is_etcd_master: "{{ inventory_hostname in groups['etcd'] }}" + - set_fact: etcd_after_v3: etcd_version | version_compare("v3.0.0", ">=") - set_fact: diff --git a/roles/etcd/templates/deb-etcd-host.initd.j2 b/roles/etcd/templates/deb-etcd-host.initd.j2 deleted file mode 100644 index ccecdce4e..000000000 --- a/roles/etcd/templates/deb-etcd-host.initd.j2 +++ /dev/null @@ -1,114 +0,0 @@ -#!/bin/sh -set -a - -### BEGIN INIT INFO -# Provides: etcd -# Required-Start: $local_fs $network $syslog -# Required-Stop: -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: etcd distributed k/v store -# Description: -# etcd is a distributed, consistent key-value store for shared configuration and service discovery -### END INIT INFO - -PATH=/sbin:/usr/sbin:/bin:/usr/bin -DESC="etcd k/v store" -NAME=etcd -DAEMON={{ bin_dir }}/etcd -{% if is_etcd_master %} -DAEMON_ARGS="" -{% else %} -DAEMON_ARGS="--proxy on" -{% endif %} -SCRIPTNAME=/etc/init.d/$NAME -DAEMON_USER=etcd -STOP_SCHEDULE="${STOP_SCHEDULE:-QUIT/5/TERM/5/KILL/5}" -PID=/var/run/etcd.pid - -# Exit if the binary is not present -[ -x "$DAEMON" ] || exit 0 - -# Read configuration variable file if it is present -[ -f /etc/etcd.env ] && . /etc/etcd.env - -# Define LSB log_* functions. -# Depend on lsb-base (>= 3.2-14) to ensure that this file is present -# and status_of_proc is working. -. /lib/lsb/init-functions - -do_status() -{ - status_of_proc -p $PID "$DAEMON" "$NAME" && exit 0 || exit $? -} - -# Function that starts the daemon/service -# -do_start() -{ - start-stop-daemon --background --start --quiet --make-pidfile --pidfile $PID --user $DAEMON_USER --exec $DAEMON -- \ - $DAEMON_ARGS \ - || return 2 -} - -# -# Function that stops the daemon/service -# -do_stop() -{ - start-stop-daemon --stop --quiet --retry=$STOP_SCHEDULE --pidfile $PID --name $NAME - RETVAL="$?" - - sleep 1 - return "$RETVAL" -} - - -case "$1" in - start) - log_daemon_msg "Starting $DESC" "$NAME" - do_start - case "$?" in - 0|1) log_end_msg 0 || exit 0 ;; - 2) log_end_msg 1 || exit 1 ;; - esac - ;; - stop) - log_daemon_msg "Stopping $DESC" "$NAME" - if do_stop; then - log_end_msg 0 - else - log_failure_msg "Can't stop etcd" - log_end_msg 1 - fi - ;; - status) - if do_status; then - log_end_msg 0 - else - log_failure_msg "etcd is not running" - log_end_msg 1 - fi - ;; - - restart|force-reload) - log_daemon_msg "Restarting $DESC" "$NAME" - if do_stop; then - if do_start; then - log_end_msg 0 - exit 0 - else - rc="$?" - fi - else - rc="$?" - fi - log_failure_msg "Can't restart etcd" - log_end_msg ${rc} - ;; - *) - echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 - exit 3 - ;; -esac - diff --git a/roles/etcd/templates/deb-etcd-docker.initd.j2 b/roles/etcd/templates/deb-etcd.initd.j2 similarity index 100% rename from roles/etcd/templates/deb-etcd-docker.initd.j2 rename to roles/etcd/templates/deb-etcd.initd.j2 diff --git a/roles/etcd/templates/etcd-host.service.j2 b/roles/etcd/templates/etcd-host.service.j2 deleted file mode 100644 index 19cc0386e..000000000 --- a/roles/etcd/templates/etcd-host.service.j2 +++ /dev/null @@ -1,18 +0,0 @@ -[Unit] -Description=etcd - - -[Service] -User=etcd -EnvironmentFile=/etc/etcd.env -{% if inventory_hostname in groups['etcd'] %} -ExecStart={{ bin_dir }}/etcd -{% else %} -ExecStart={{ bin_dir }}/etcd -proxy on -{% endif %} -Restart=always -RestartSec=10s -LimitNOFILE=40000 - -[Install] -WantedBy=multi-user.target diff --git a/roles/etcd/templates/etcd-docker.service.j2 b/roles/etcd/templates/etcd.service.j2 similarity index 100% rename from roles/etcd/templates/etcd-docker.service.j2 rename to roles/etcd/templates/etcd.service.j2 diff --git a/roles/kubernetes-apps/tasks/main.yaml b/roles/kubernetes-apps/tasks/main.yaml index 9cb5efb7c..c30a73d24 100644 --- a/roles/kubernetes-apps/tasks/main.yaml +++ b/roles/kubernetes-apps/tasks/main.yaml @@ -5,11 +5,6 @@ state: latest when: ansible_os_family != "CoreOS" and kpm_packages | length > 0 -# workaround for the error "cannot import name IncompleteRead" -- name: Upgrade pip - command: easy_install -U pip - changed_when: false - - name: install kpm pip: name: "kpm"