summaryrefslogtreecommitdiffstats
path: root/vagrant/playbooks/configure-multus.yml
blob: 58eda4bd6dca08092aa36c733e48862b40e665af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
---
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2018
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
- hosts: kube-node
  become: yes
  pre_tasks:
    - name: Load krd variables
      include_vars:
        file: krd-vars.yml
  roles:
    - { role: andrewrothstein.go, when: multus_source_type == "source" }
  environment:
    PATH: "{{ ansible_env.PATH }}:/usr/local/go/bin/"
  tasks:
    - name: create multus binary folder
      file:
        state: directory
        path: "{{ item }}"
      with_items:
        - /opt/cni/bin
        - "{{ multus_dest }}"
    - name: getting source code
      block:
      - name: clone Multus repo
        git:
          repo: "{{ multus_url }}"
          dest: "{{ multus_dest }}"
          version: "{{ multus_version }}"
          force: yes
      - name: build multus source code
        command: ./build
        args:
          chdir: "{{ multus_dest }}"
      - name: copy multus binary to opt folder
        command: "mv {{ multus_dest }}/bin/multus /opt/cni/bin/multus"
      when: multus_source_type == "source"
    - name: getting binary
      block:
      - name: download Multus tarball
        get_url:
          url: "{{ multus_url }}"
          dest: "/tmp/multus.tar.gz"
      - name: extract multus source code
        unarchive:
          src: "/tmp/multus.tar.gz"
          dest: "{{ multus_dest }}"
          remote_src: yes
      - name: copy multus binary to opt folder
        command: "mv {{ multus_dest }}/multus-cni_v{{ multus_version }}_linux_amd64/multus-cni /opt/cni/bin/multus"
      when: multus_source_type == "tarball"
    - name: create multus configuration file
      blockinfile:
        marker: ""
        path: /etc/cni/net.d/00-multus.conf
        create: yes
        block: |
          {
            "type": "multus",
            "kubeconfig": "/etc/kubernetes/admin.conf",
            "delegates": [
              {
                "type": "flannel",
                "masterplugin": true,
                "delegate": {
                  "isDefaultGateway": true
                }
              }
            ]
          }

- hosts: localhost
  roles:
    - andrewrothstein.kubectl
  tasks:
    - name: define a CRD network object specification
      blockinfile:
        path: /tmp/crdnetwork.yml
        create: yes
        block: |
          apiVersion: apiextensions.k8s.io/v1beta1
          kind: CustomResourceDefinition
          metadata:
            # name must match the spec fields below, and be in the form: <plural>.<group>
            name: networks.kubernetes.cni.cncf.io
          spec:
            # group name to use for REST API: /apis/<group>/<version>
            group: kubernetes.cni.cncf.io
            # version name to use for REST API: /apis/<group>/<version>
            version: v1
            # either Namespaced or Cluster
            scope: Namespaced
            names:
              # plural name to be used in the URL: /apis/<group>/<version>/<plural>
              plural: networks
              # singular name to be used as an alias on the CLI and for display
              singular: network
              # kind is normally the CamelCased singular type. Your resource manifests use this.
              kind: Network
              # shortNames allow shorter string to match your resource on the CLI
              shortNames:
              - net
    - name: create network objects
      shell: "/usr/local/bin/kubectl apply -f /tmp/crdnetwork.yml"
      ignore_errors: True