build-vm-bootstrap.yml 11.5 KB
Newer Older
1 2 3 4 5 6 7 8 9
- name: a play that runs entirely on the ansible host
  hosts: 127.0.0.1
  connection: local

  vars:
    upload_shacache: "{{ lookup('env','UPLOAD') }}"

  tasks:

10
### Build instances
11 12

    - shell: mkdir -p log/
13 14
    - name: Install latest version of slapos.libnetworkcache
      pip:
15
        name: slapos.libnetworkcache
16
        state: latest
17

18 19 20 21 22 23 24 25
    - shell: PATH=$PATH:/opt/packer/ packer build -var 'disk_size={{ item.size }}' -var 'name={{ item.name }}' -var 'custom_script={{ item.script }}' debian9.json >> log/debian9-{{ item.name }}.log
      args:
        creates: output-debian9-{{ item.size }}G-{{ item.name }}
      with_items:
        - { name: "vm-bootstrap", size: "200", script: "scripts/vm-bootstrap.sh"}
        - { name: "vm-bootstrap", size: "50", script: "scripts/vm-bootstrap.sh"}
        - { name: "vm-bootstrap", size: "25", script: "scripts/vm-bootstrap.sh"}

26
    - shell: PATH=$PATH:/opt/packer/ packer build -var 'disk_size={{ item.size }}' -var 'name={{ item.name }}' -var 'custom_script={{ item.script }}' debian10.json >> log/debian10-{{ item.name }}.log
27
      args:
28
        creates: output-debian10-{{ item.size }}G-{{ item.name }}
29 30 31 32 33
      with_items:
        - { name: "vm-bootstrap", size: "200", script: "scripts/vm-bootstrap.sh"}
        - { name: "vm-bootstrap", size: "50", script: "scripts/vm-bootstrap.sh"}
        - { name: "vm-bootstrap", size: "25", script: "scripts/vm-bootstrap.sh"}

Thomas Gambier's avatar
Thomas Gambier committed
34 35 36 37 38 39 40 41
    - shell: PATH=$PATH:/opt/packer/ packer build -var 'disk_size={{ item.size }}' -var 'name={{ item.name }}' -var 'custom_script={{ item.script }}' debian11.json >> log/debian11-{{ item.name }}.log
      args:
        creates: output-debian11-{{ item.size }}G-{{ item.name }}
      with_items:
        - { name: "vm-bootstrap", size: "200", script: "scripts/vm-bootstrap.sh"}
        - { name: "vm-bootstrap", size: "50", script: "scripts/vm-bootstrap.sh"}
        - { name: "vm-bootstrap", size: "25", script: "scripts/vm-bootstrap.sh"}

42

43
    - shell: PATH=$PATH:/opt/packer/ packer build -var 'disk_size={{ item.size }}' -var 'name={{ item.name }}' -var 'custom_script={{ item.script }}' ubuntu-18.04-server-amd64.json >> log/ubuntu-18.04-server-amd64-{{ item.name }}.log
44
      args:
45
        creates: output-ubuntu-18.04-server-{{ item.size }}G-{{ item.name }}
46 47 48 49 50
      with_items:
        - { name: "vm-bootstrap", size: "200", script: "scripts/vm-bootstrap.sh"}
        - { name: "vm-bootstrap", size: "50", script: "scripts/vm-bootstrap.sh"}
        - { name: "vm-bootstrap", size: "25", script: "scripts/vm-bootstrap.sh"}

51 52

    - shell: PATH=$PATH:/opt/packer/ packer build -var 'disk_size={{ item.size }}' -var 'name={{ item.name }}' -var 'custom_script={{ item.script }}' ubuntu-20.04-server-amd64.json >> log/ubuntu-20.04-server-amd64-{{ item.name }}.log
53
      args:
54
        creates: output-ubuntu-20.04-server-{{ item.size }}G-{{ item.name }}
55 56 57 58 59
      with_items:
        - { name: "vm-bootstrap", size: "200", script: "scripts/vm-bootstrap.sh"}
        - { name: "vm-bootstrap", size: "50", script: "scripts/vm-bootstrap.sh"}
        - { name: "vm-bootstrap", size: "25", script: "scripts/vm-bootstrap.sh"}

60

Francois Le Corre's avatar
Francois Le Corre committed
61 62 63 64 65 66 67
    - shell: PATH=$PATH:/opt/packer/ packer build -var 'disk_size={{ item.size }}' -var 'name={{ item.name }}' -var 'custom_script={{ item.script }}' centos-8.json >> log/centos8-{{ item.name }}.log
      args:
        creates: output-centos8-{{ item.size }}G-{{ item.name }}
      with_items:
        - { name: "vm-bootstrap", size: "200", script: "scripts/vm-bootstrap.sh"}
        - { name: "vm-bootstrap", size: "50", script: "scripts/vm-bootstrap.sh"}
        - { name: "vm-bootstrap", size: "25", script: "scripts/vm-bootstrap.sh"}
68

69
    - shell: PATH=$PATH:/opt/packer/ packer build -var 'disk_size={{ item.size }}' -var 'name={{ item.name }}' -var 'custom_script={{ item.script }}' centos-7.json >> log/centos7-{{ item.name }}.log
70
      args:
71
        creates: output-centos7-{{ item.size }}G-{{ item.name }}
72 73 74 75 76
      with_items:
        - { name: "vm-bootstrap", size: "200", script: "scripts/vm-bootstrap.sh"}
        - { name: "vm-bootstrap", size: "50", script: "scripts/vm-bootstrap.sh"}
        - { name: "vm-bootstrap", size: "25", script: "scripts/vm-bootstrap.sh"}

77
#### Generation of images are over.
78 79 80
#### Start compress everything


81 82 83 84 85 86 87 88 89
    - shell: gzip output-debian9-{{ item.size }}G-{{ item.name }}/packer-debian9-{{ item.size }}G-{{ item.name }}
      args:
        creates: output-debian9-{{ item.size }}G-{{ item.name }}/packer-debian9-{{ item.size }}G-{{ item.name }}.gz
      with_items:
        - { name: "vm-bootstrap", size: "200"}
        - { name: "vm-bootstrap", size: "50"}
        - { name: "vm-bootstrap", size: "25"}
      ignore_errors: True

90
    - shell: gzip output-debian10-{{ item.size }}G-{{ item.name }}/packer-debian10-{{ item.size }}G-{{ item.name }}
91
      args:
92
        creates: output-debian10-{{ item.size }}G-{{ item.name }}/packer-debian10-{{ item.size }}G-{{ item.name }}.gz
93 94 95 96 97 98
      with_items:
        - { name: "vm-bootstrap", size: "200"}
        - { name: "vm-bootstrap", size: "50"}
        - { name: "vm-bootstrap", size: "25"}
      ignore_errors: True

Thomas Gambier's avatar
Thomas Gambier committed
99 100 101 102 103 104 105 106 107
    - shell: gzip output-debian11-{{ item.size }}G-{{ item.name }}/packer-debian11-{{ item.size }}G-{{ item.name }}
      args:
        creates: output-debian11-{{ item.size }}G-{{ item.name }}/packer-debian11-{{ item.size }}G-{{ item.name }}.gz
      with_items:
        - { name: "vm-bootstrap", size: "200"}
        - { name: "vm-bootstrap", size: "50"}
        - { name: "vm-bootstrap", size: "25"}
      ignore_errors: True

108
    - shell: gzip output-ubuntu-18.04-server-{{ item.size }}G-{{ item.name }}/packer-ubuntu-18.04-server-{{ item.size }}G-{{ item.name }}
109
      args:
110
        creates: output-ubuntu-18.04-server-{{ item.size }}G-{{ item.name }}/packer-ubuntu-18.04-server-{{ item.size }}G-{{ item.name }}.gz
111 112 113 114 115 116
      with_items:
        - { name: "vm-bootstrap", size: "200"}
        - { name: "vm-bootstrap", size: "50"}
        - { name: "vm-bootstrap", size: "25"}
      ignore_errors: True

117
    - shell: gzip output-ubuntu-20.04-server-{{ item.size }}G-{{ item.name }}/packer-ubuntu-20.04-server-{{ item.size }}G-{{ item.name }}
118
      args:
119
        creates: output-ubuntu-20.04-server-{{ item.size }}G-{{ item.name }}/packer-ubuntu-20.04-server-{{ item.size }}G-{{ item.name }}.gz
120 121 122 123 124 125
      with_items:
        - { name: "vm-bootstrap", size: "200"}
        - { name: "vm-bootstrap", size: "50"}
        - { name: "vm-bootstrap", size: "25"}
      ignore_errors: True

126
    - shell: gzip output-centos8-{{ item.size }}G-{{ item.name }}/packer-centos8-{{ item.size }}G-{{ item.name }}
127
      args:
128
        creates: output-centos8-{{ item.size }}G-{{ item.name }}/packer-centos8-{{ item.size }}G-{{ item.name }}.gz
129 130 131 132 133 134
      with_items:
        - { name: "vm-bootstrap", size: "200"}
        - { name: "vm-bootstrap", size: "50"}
        - { name: "vm-bootstrap", size: "25"}
      ignore_errors: True

135
    - shell: gzip output-centos7-{{ item.size }}G-{{ item.name }}/packer-centos7-{{ item.size }}G-{{ item.name }}
136
      args:
137
        creates: output-centos7-{{ item.size }}G-{{ item.name }}/packer-centos7-{{ item.size }}G-{{ item.name }}.gz
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
      with_items:
        - { name: "vm-bootstrap", size: "200"}
        - { name: "vm-bootstrap", size: "50"}
        - { name: "vm-bootstrap", size: "25"}
      ignore_errors: True

#### Gzip is over, start to upload to shacache
#### Build SHA512SUM.txt and MD5SUM.txt of every file.

    - shell: rm -f SHA512SUM.txt MD5SUM.txt URL.txt

    - shell: |
        FILE=output-{{ item.distro }}-{{ item.size }}G-{{ item.name }}/packer-{{ item.distro }}-{{ item.size }}G-{{ item.name }}.gz
        sha512sum $FILE >> SHA512SUM.txt
        md5sum $FILE >> MD5SUM.txt
      with_items:
154 155 156
        - { name: "vm-bootstrap", size: "200", distro: "debian9"}
        - { name: "vm-bootstrap", size: "50", distro: "debian9"}
        - { name: "vm-bootstrap", size: "25", distro: "debian9"}
157 158 159
        - { name: "vm-bootstrap", size: "200", distro: "debian10"}
        - { name: "vm-bootstrap", size: "50", distro: "debian10"}
        - { name: "vm-bootstrap", size: "25", distro: "debian10"}
Thomas Gambier's avatar
Thomas Gambier committed
160 161 162
        - { name: "vm-bootstrap", size: "200", distro: "debian11"}
        - { name: "vm-bootstrap", size: "50", distro: "debian11"}
        - { name: "vm-bootstrap", size: "25", distro: "debian11"}
163 164 165 166 167 168 169 170 171 172 173 174
        - { name: "vm-bootstrap", size: "200", distro: "centos7"}
        - { name: "vm-bootstrap", size: "50", distro: "centos7"}
        - { name: "vm-bootstrap", size: "25", distro: "centos7"}
        - { name: "vm-bootstrap", size: "200", distro: "centos8"}
        - { name: "vm-bootstrap", size: "50", distro: "centos8"}
        - { name: "vm-bootstrap", size: "25", distro: "centos8"}
        - { name: "vm-bootstrap", size: "200", distro: "ubuntu-18.04-server"}
        - { name: "vm-bootstrap", size: "50", distro: "ubuntu-18.04-server"}
        - { name: "vm-bootstrap", size: "25", distro: "ubuntu-18.04-server"}
        - { name: "vm-bootstrap", size: "200", distro: "ubuntu-20.04-server"}
        - { name: "vm-bootstrap", size: "50", distro: "ubuntu-20.04-server"}
        - { name: "vm-bootstrap", size: "25", distro: "ubuntu-20.04-server"}
175

176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
#### End of build SHA512SUM.txt and MD5SUM.txt
#### Start uploading to shacache

    - stat: path=/etc/opt/shacache/shacache.cfg
      register: shacache_config

    - name: Upload a list of images to shacache, there is no verification for now
      shell: |
        FILE=output-{{ item.distro }}-{{ item.size }}G-{{ item.name }}/packer-{{ item.distro }}-{{ item.size }}G-{{ item.name }}.gz
        networkcache-upload --prefix-key packerimage- --url $FILE --file $FILE /etc/opt/shacache/shacache.cfg
        SHA512SUM=$(cat SHA512SUM.txt | grep packer-{{ item.distro }}-{{ item.size }}G-{{ item.name }}.gz | cut -d ' ' -f1)
        BASE_URL=$(cat /etc/opt/shacache/shacache.cfg | grep 'download-cache-url' | cut -d ' ' -f3)
        MD5SUM=$(cat MD5SUM.txt | grep packer-{{ item.distro }}-{{ item.size }}G-{{ item.name }}.gz | cut -d ' ' -f1)
        echo "packer-{{ item.distro }}-{{ item.size }}G-{{ item.name }}.gz  $BASE_URL/$SHA512SUM   $MD5SUM" >> URL.txt
      with_items:
        - { name: "vm-bootstrap", size: "200", distro: "debian9"}
        - { name: "vm-bootstrap", size: "50", distro: "debian9"}
        - { name: "vm-bootstrap", size: "25", distro: "debian9"}
        - { name: "vm-bootstrap", size: "200", distro: "debian10"}
        - { name: "vm-bootstrap", size: "50", distro: "debian10"}
        - { name: "vm-bootstrap", size: "25", distro: "debian10"}
        - { name: "vm-bootstrap", size: "200", distro: "debian11"}
        - { name: "vm-bootstrap", size: "50", distro: "debian11"}
        - { name: "vm-bootstrap", size: "25", distro: "debian11"}
        - { name: "vm-bootstrap", size: "200", distro: "centos7"}
        - { name: "vm-bootstrap", size: "50", distro: "centos7"}
        - { name: "vm-bootstrap", size: "25", distro: "centos7"}
        - { name: "vm-bootstrap", size: "200", distro: "centos8"}
        - { name: "vm-bootstrap", size: "50", distro: "centos8"}
        - { name: "vm-bootstrap", size: "25", distro: "centos8"}
        - { name: "vm-bootstrap", size: "200", distro: "ubuntu-18.04-server"}
        - { name: "vm-bootstrap", size: "50", distro: "ubuntu-18.04-server"}
        - { name: "vm-bootstrap", size: "25", distro: "ubuntu-18.04-server"}
        - { name: "vm-bootstrap", size: "200", distro: "ubuntu-20.04-server"}
        - { name: "vm-bootstrap", size: "50", distro: "ubuntu-20.04-server"}
        - { name: "vm-bootstrap", size: "25", distro: "ubuntu-20.04-server"}
      when: shacache_config.stat.exists == True and  upload_shacache == "yes"

#### End of uploading to shacache