Commit eb929e98 authored by Klaus Frank's avatar Klaus Frank

Initial commit

parents
Pipeline #22358 failed with stage
in 1 minute and 4 seconds
.DS_Store
.AppleDouble
.LSOverride
Icon
._*
.Spotlight-V100
.Trashes
.vagrant
test
image: agowa338/ansible:latest
stages:
- check
variables:
GIT_STRATEGY: clone # GitLab deletes the extension folder, but dont cleans up the git hook registration (when just fetching), so calling it fails bevore checking out the repository again.
GIT_SUBMODULE_STRATEGY: recursive
before_script:
- echo $ANSIBLE_VAULT_PASSWORD > .vpass
- sha256sum .vpass
- chmod a-x .vpass
## Run ssh-agent (inside the build environment)
#- eval $(ssh-agent -s)
## Add the SSH key stored in ANSIBLE_DEPLOYMENT_SSH_KEY variable to the agent store
## We're using tr to fix line endings which makes ed25519 keys work
## without extra base64 encoding.
## https://gitlab.com/gitlab-examples/ssh-private-key/issues/1#note_48526556
##
#- echo "$ANSIBLE_DEPLOYMENT_SSH_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- chmod o-w -R ./tests
check:
stage: check
script:
- cd tests
## https://docs.ansible.com/ansible-lint/rules/default_rules.html
## ANSIBLE0010: Package installs should not use latest
## ANSIBLE0016: Tasks that run when changed should likely be handlers
## For now exclude external roles
- ansible-lint *.yml -x ANSIBLE0010,ANSIBLE0016
- ansible-playbook play*.yml --syntax-check -i inventory.ini
This diff is collapsed.
kubernetes_libvirt_ipv6_network: 2001:DB8:ABCD:12DA::/64
kubernetes_vagrant_image:
box: centos
version: '7'
directory: '1905.1'
kubernetes_qemu_path: /usr/libexec/qemu-kvm
galaxy_info:
author: agowa338
description: Deploy kubernetes using libvirt
min_ansible_version: 2.6
license: Apache
platforms:
- name: All
versions:
- all
categories:
- system
- Kubernetes
- Libvirt
- KVM
dependencies: []
- name: Pull vagrant image
command: '/usr/bin/vagrant box add --provider libvirt {{ kubernetes_vagrant_image.box }}/{{ kubernetes_vagrant_image.version }}'
args:
creates: '~/.vagrant.d/boxes/{{ kubernetes_vagrant_image.box }}-VAGRANTSLASH-{{ kubernetes_vagrant_image.version }}'
- name: Bootstrap and start vms
include: libvirt_bootstrap.yml
vars:
base_image: '/var/lib/libvirt/images/{{ item }}_root.img'
memory: '1'
vcpu: '1'
network_name: ipv6_only
loop:
- nat64
- controller001
- worker001
- worker002
- virt:
command: get_xml
register: libvirt_vms
changed_when: false
- name: Add vms to inventory
add_host:
hostname: 'libvirt_{{ item }}'
ansible_host: '{{ libvirt_vms | parse_xml(filter) }}'
ansible_port: 22
libvirt_host: '{{ inventory_hostname }}'
groups:
- 'libvirt_host_{{ inventory_hostname }}'
vars:
network_name: ipv6_only
filter: string(/domain[@type='kvm'][name='{{ item }}']/devices/interface[@type='network']/source[@network='{{ network_name }}']/../mac/@address)'
loops:
- nat64
- controller001
- worker001
- worker002
- name: Copy image
copy:
src: '~/.vagrant.d/boxes/{{ kubernetes_vagrant_image.box }}-VAGRANTSLASH-{{ kubernetes_vagrant_image.version }}/{{ kubernetes_vagrant_image.directory }}/libvirt/box.img'
dest: '/var/lib/libvirt/images/{{ item }}_root.img'
remote_src: yes
- name: Define VM
virt:
command: define
xml: "{{ lookup('template', 'libvirt_vm_template.xml.j2') }}"
- name: Start VM
virt:
name: '{{ item }}'
state: running
- name: Libvirt Network
include: network.yml
- name: Libvirt VM
include: libvirt.yml
- name: Define container network
virt_net:
command: define
name: '{{ network_name }}'
xml: |
<network>
<name>{{ network_name }}</name>
<domain name="network"/>
<ip family="ipv6" address="{{ kubernetes_libvirt_ipv6_network | ipaddr(1) | ipaddr('address') }}" prefix="{{ kubernetes_libvirt_ipv6_network | ipaddr(1) | ipaddr('prefix') }}"/>
</network>
vars:
network_name: ipv6_only
- name: Start container network
virt_net:
command: create
name: ipv6_only
- name: Activate container network
virt_net:
state: active
name: ipv6_only
- name: Start container network on boot
virt_net:
autostart: yes
name: ipv6_only
<domain type="kvm">
<name>{{ item }}</name>
<uuid>{{ item | to_uuid }}</uuid>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://centos.org/centos/7"/>
</libosinfo:libosinfo>
</metadata>
<memory unit="GiB">{{ memory }}</memory>
<currentMemory unit="GiB">{{ memory }}</currentMemory>
<vcpu placement="static">{{ vcpu }}</vcpu>
<os>
<type arch="x86_64" machine="pc-i440fx-rhel7.0.0">hvm</type>
<boot dev="hd"/>
</os>
<features>
<acpi/>
<apic/>
</features>
<cpu mode="host-model" check="partial">
<model fallback="allow"/>
</cpu>
<clock offset="utc">
<timer name="rtc" tickpolicy="catchup"/>
<timer name="pit" tickpolicy="delay"/>
<timer name="hpet" present="no"/>
</clock>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<pm>
<suspend-to-mem enabled="no"/>
<suspend-to-disk enabled="no"/>
</pm>
<devices>
<emulator>{{ kubernetes_qemu_path }}</emulator>
<disk type="file" device="disk">
<driver name="qemu" type="qcow2"/>
<source file="{{ base_image }}"/>
<target dev="vda" bus="virtio"/>
</disk>
<controller type="pci" index="0" model="pci-root"/>
<controller type="usb" index="0" model="nec-xhci" ports="15"/>
<interface type="network">
<source network="{{ network_name }}"/>
<model type="virtio"/>
</interface>
<serial type="pty">
<target type="isa-serial" port="0">
<model name="isa-serial"/>
</target>
</serial>
<console type="pty">
<target type="serial" port="0"/>
</console>
<input type="mouse" bus="ps2"/>
<input type="keyboard" bus="ps2"/>
<memballoon model="virtio"/>
<rng model="virtio">
<backend model="random">/dev/urandom</backend>
</rng>
</devices>
</domain>
- hosts: localhost
connection: local
roles:
- name: deploy-kubernetes
../..
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment