interop-workloads/workloads/ansible/shade/k8s/roles/worker/tasks/main.yml

162 lines
4.5 KiB
YAML
Executable File

---
- name: Setup few variables for coreos target
set_fact:
public_ip: "{{ groups['cmasters'][0] }}"
private_ip: "{{ hostvars[groups['cmasters'][0]].inter_ip }}"
this_ip: "{{ hostvars[ansible_host].inter_ip }}"
service_path: "/etc/systemd/system/"
when: app_env.target_os == "coreos"
- name: Setup few variables for ubuntu target
set_fact:
public_ip: "{{ groups['umasters'][0] }}"
private_ip: "{{ hostvars[groups['umasters'][0]].inter_ip }}"
this_ip: "{{ hostvars[ansible_host].inter_ip }}"
service_path: "/lib/systemd/system/"
when: app_env.target_os == "ubuntu"
- stat: path=/tmp/diskflag
register: diskflag
- shell: parted -s "{{ app_env.block_device_name }}" mklabel msdos
when: diskflag.stat.exists == false
- shell: parted -s "{{ app_env.block_device_name }}" mkpart primary ext4 1049kb 100%
when: diskflag.stat.exists == false
- lineinfile: dest=/tmp/diskflag line="disk is now partitioned!" create=yes
- name: Create file system on the volume
filesystem: fstype=ext4 dev="{{ app_env.block_device_name }}1"
- name: Mount the volume at /storage
mount: name=/storage src="{{ app_env.block_device_name }}1" fstype=ext4 state=mounted
- name: Get the network interface name
shell: >-
ip -4 -o addr | grep "{{ this_ip }}" | awk '{print $2}'
register: nodeif_name
- name: List all k8s service on the node
stat: "path=/opt/bin/{{ item }}"
with_items:
- kubelet
- kubectl
- kube-proxy
- flanneld
register: k8s_binaries
- name: Pull k8s binaries from the master
command: >-
scp -i "~/.ssh/id_rsa" -o "StrictHostKeyChecking no" "{{ app_env.
ssh_user }}@{{ private_ip }}:/opt/bin/{{ item.item }}"
"/opt/bin/{{ item.item }}"
with_items: " {{ k8s_binaries.results }} "
when: item.stat.exists == false
no_log: True
- name: Setup services for worker node
template:
src: roles/common/templates/k8s.service.j2
dest: "{{ service_path }}{{ item }}.service"
mode: 0644
with_items:
- flanneld
- kubelet
- kube-proxy
- name: Setup kubeconfig for each node
template:
src: roles/worker/templates/kubeconfig.j2
dest: "~/.kube/config"
mode: 0600
- name: Setup worker node service variables
set_fact:
kubelet_params: >-
--api-servers={{ private_ip }}:8080
--container-runtime=docker
--cluster-dns={{ app_env.dns_service_ip }}
--cluster-domain={{ app_env.domain }}
--hostname-override={{ inter_name }}
--resolv-conf=''
proxy_params: >-
--master={{ private_ip }}:8080
--cluster-cidr={{ app_env.pod_network.Network }}
flanneld_params: >-
-iface={{ nodeif_name.stdout }}
-etcd-endpoints=http://{{ private_ip }}:2379
-ip-masq=false
-etcd-prefix=/coreos.com/network/
- name: Configure the worker node services
template:
src: roles/common/templates/k8s.conf.j2
dest: "/etc/kubernetes/{{ item.name }}"
mode: 0644
with_items:
- { name: "kubelet", value: "{{ kubelet_params }}" }
- { name: "kube-proxy", value: "{{ proxy_params }}" }
- { name: "flanneld", value: "{{ flanneld_params }}" }
- name: Start the flanneld service
service:
name: flanneld
enabled: yes
state: started
- name: Wait for the flannel to setup the subnets
wait_for:
path: /run/flannel/subnet.env
search_regex: FLANNEL_SUBNET
- name: Get the bip address
shell: >-
. /run/flannel/subnet.env && echo $FLANNEL_SUBNET
register: bip
- name: Get the mtu
shell: >-
. /run/flannel/subnet.env && echo $FLANNEL_MTU
register: mtu
- name: Setup Docker service file
template:
src: "roles/worker/templates/docker.{{ app_env.target_os }}.j2"
dest: "{{ service_path }}docker.service"
- name: Reload daemon service
command: systemctl daemon-reload
- name: Start the worker services
service:
name: "{{ item }}"
enabled: yes
state: restarted
with_items:
- docker.socket
- docker
- kubelet
- kube-proxy
- name: Get all container image tar files
command: "{{ item }}"
with_items:
- "mkdir -p /opt/bin/containerimages"
- "rm -f /opt/bin/containerimages/*"
- "wget -q -O /opt/bin/cimages.tar.gz {{ app_env.cimages_repo }}"
- "tar xf /opt/bin/cimages.tar.gz -C /opt/bin/containerimages"
when: app_env.cimages_repo != ""
- name: List all the container images tar files
find:
paths: "/opt/bin/containerimages"
patterns: "*.tar"
when: app_env.cimages_repo != ""
register: tarfiles
- name: Load container images
command: "docker load --input {{ item.path }}"
with_items: " {{ tarfiles.files }} "
when: app_env.cimages_repo != ""