kubespray/roles/network_plugin/calico/tasks/main.yml

146 lines
5.0 KiB
YAML
Raw Normal View History

2015-10-04 04:19:50 +08:00
---
- name: Calico | Set docker daemon options
template:
src: docker
dest: "/etc/default/docker"
owner: root
group: root
mode: 0644
notify:
- restart docker
when: ansible_os_family != "CoreOS"
- meta: flush_handlers
- name: Calico | Install calicoctl container script
template:
src: calicoctl-container.j2
dest: "{{ bin_dir }}/calicoctl"
mode: 0755
owner: root
group: root
2016-01-22 23:37:07 +08:00
changed_when: false
notify: restart calico-node
2015-10-04 04:19:50 +08:00
- name: Calico | Do not use hyperkube cni if kube_version under v1.3.4
set_fact:
use_hyperkube_cni: false
when: kube_version | version_compare('v1.3.4','<')
- name: Calico | Use hyperkube cni if kube_version above v1.3.4
set_fact:
use_hyperkube_cni: true
when: kube_version | version_compare('v1.3.4','>=')
- name: Calico | Copy cni plugins from hyperkube
command: "/usr/bin/docker run --rm -v /opt/cni/bin:/cnibindir {{ hyperkube_image_repo }}:{{ hyperkube_image_tag }} /usr/bin/rsync -a /opt/cni/bin/ /cnibindir/"
register: cni_task_result
until: cni_task_result.rc == 0
retries: 4
delay: "{{ retry_stagger | random + 3 }}"
changed_when: false
when: "{{ use_hyperkube_cni|bool }}"
- name: Calico | Install calico cni bin
command: rsync -pi "{{ local_release_dir }}/calico/bin/calico" "/opt/cni/bin/calico"
changed_when: false
when: "{{ not use_hyperkube_cni|bool or overwrite_hyperkube_cni|bool }}"
- name: Calico | Install calico-ipam cni bin
command: rsync -pi "{{ local_release_dir }}/calico/bin/calico-ipam" "/opt/cni/bin/calico-ipam"
changed_when: false
when: "{{ not use_hyperkube_cni|bool or overwrite_hyperkube_cni|bool }}"
2016-01-25 09:01:25 +08:00
- name: Calico | wait for etcd
uri: url=http://localhost:2379/health
register: result
until: result.status == 200
retries: 10
delay: 5
2016-01-09 17:45:50 +08:00
when: inventory_hostname in groups['kube-master']
2015-12-20 23:51:14 +08:00
- name: Calico | Check if calico network pool has already been configured
uri:
url: "{{ etcd_endpoint }}/v2/keys/calico/v1/ipam/v4/pool"
2015-12-20 23:51:14 +08:00
return_content: yes
status_code: 200,404
register: calico_conf
run_once: true
- name: Calico | Define ipip pool argument
run_once: true
set_fact:
ipip_arg: "--ipip"
when: cloud_provider is defined or ipip|default(false)
- name: Calico | Define nat-outgoing pool argument
2016-01-29 21:07:21 +08:00
run_once: true
set_fact:
nat_arg: "--nat-outgoing"
when: nat_outgoing|default(false) and not peer_with_router|default(false)
2016-01-29 21:07:21 +08:00
- name: Calico | Define calico pool task name
run_once: true
set_fact:
pool_task_name: "with options {{ ipip_arg|default('') }} {{ nat_arg|default('') }}"
when: ipip_arg|default(false) or nat_arg|default(false)
- name: Calico | Configure calico network pool {{ pool_task_name|default('') }}
command: "{{ bin_dir}}/calicoctl pool add {{ kube_pods_subnet }} {{ ipip_arg|default('') }} {{ nat_arg|default('') }}"
environment:
NO_DEFAULT_POOLS: true
run_once: true
when: calico_conf.status == 404 or "nodes" not in calico_conf.content
2015-12-20 23:51:14 +08:00
- name: Calico | Get calico configuration from etcd
uri:
url: "{{ etcd_endpoint }}/v2/keys/calico/v1/ipam/v4/pool"
2015-12-20 23:51:14 +08:00
return_content: yes
register: calico_pools
run_once: true
- name: Calico | Check if calico pool is properly configured
fail:
msg: 'Only one network pool must be configured and it must be the subnet {{ kube_pods_subnet }}.
Please erase calico configuration and run the playbook again ("etcdctl rm --recursive /calico/v1/ipam/v4/pool")'
2016-01-04 21:58:27 +08:00
when: ( calico_pools.json['node']['nodes'] | length > 1 ) or
2015-12-20 23:51:14 +08:00
( not calico_pools.json['node']['nodes'][0]['key'] | search(".*{{ kube_pods_subnet | ipaddr('network') }}.*") )
run_once: true
2016-02-01 22:53:23 +08:00
- name: Calico | Write /etc/network-environment
template: src=network-environment.j2 dest=/etc/network-environment
when: ansible_service_mgr in ["sysvinit","upstart"]
2016-02-01 22:53:23 +08:00
- name: Calico | Write calico-node systemd init file
template: src=calico-node.service.j2 dest=/etc/systemd/system/calico-node.service
when: ansible_service_mgr == "systemd"
2016-01-26 04:09:42 +08:00
notify: restart calico-node
2016-01-04 21:24:29 +08:00
- name: Calico | Write calico-node initd script
template: src=deb-calico.initd.j2 dest=/etc/init.d/calico-node owner=root mode=0755
when: ansible_service_mgr in ["sysvinit","upstart"] and ansible_os_family == "Debian"
2016-01-04 21:24:29 +08:00
notify: restart calico-node
2015-10-04 04:19:50 +08:00
2016-01-04 21:24:29 +08:00
- name: Calico | Write calico-node initd script
template: src=rh-calico.initd.j2 dest=/etc/init.d/calico-node owner=root mode=0755
when: ansible_service_mgr in ["sysvinit","upstart"] and ansible_os_family == "RedHat"
2016-01-04 21:24:29 +08:00
notify: restart calico-node
2015-11-20 21:04:13 +08:00
2016-01-25 09:01:25 +08:00
- meta: flush_handlers
- name: Calico | Enable calico-node
service:
name: calico-node
state: started
enabled: yes
2016-01-09 17:45:50 +08:00
- name: Calico | Disable node mesh
shell: "{{ bin_dir }}/calicoctl bgp node-mesh off"
2016-01-09 17:45:50 +08:00
when: peer_with_router|default(false) and inventory_hostname in groups['kube-node']
- name: Calico | Configure peering with router(s)
shell: "{{ bin_dir }}/calicoctl node bgp peer add {{ item.router_id }} as {{ item.as }}"
2016-01-09 17:45:50 +08:00
with_items: peers
when: peer_with_router|default(false) and inventory_hostname in groups['kube-node']