summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzsdc <taras@vyos.io>2020-04-23 20:54:29 +0300
committerzsdc <taras@vyos.io>2020-04-23 21:06:35 +0300
commit6f037298fc0c48f2ffb4ba0780f1cfdbb1fa4acf (patch)
tree21b2dbe849d325099fd2e32418b56b7ddad23edc
parent6d85fa21b8dee034713770c21a1e2b11bc39fc51 (diff)
downloadvyos-vm-images-6f037298fc0c48f2ffb4ba0780f1cfdbb1fa4acf.tar.gz
vyos-vm-images-6f037298fc0c48f2ffb4ba0780f1cfdbb1fa4acf.zip
Added option to install guest agents
Supported agents: - open-vm-tools (`vmware` option) - qemu-guest-agent (`qemu` option)
-rw-r--r--README.md11
-rw-r--r--qemu.yml1
-rw-r--r--roles/install-guest-agent-wrapper/tasks/main.yml4
-rw-r--r--roles/install-guest-agent-wrapper/tests/inventory2
-rw-r--r--roles/install-guest-agent-wrapper/tests/test.yml4
-rw-r--r--roles/install-guest-agent/files/debian.list.buster4
-rw-r--r--roles/install-guest-agent/files/debian.list.jessie5
-rw-r--r--roles/install-guest-agent/files/resolv.conf1
-rw-r--r--roles/install-guest-agent/tasks/main.yml46
-rw-r--r--roles/install-guest-agent/tests/inventory2
-rw-r--r--roles/install-guest-agent/tests/test.yml4
11 files changed, 84 insertions, 0 deletions
diff --git a/README.md b/README.md
index 394a712..7cbf084 100644
--- a/README.md
+++ b/README.md
@@ -93,6 +93,17 @@ You need to copy the ISO image with VyOS to /tmp/vyos.iso before running ansible
-e cloud_init_ds=NoCloud,ConfigDrive,None
```
+- Install guest agent. It can be `qemu`, `vmware` (default: none):
+
+ ```
+ -e guest_agent=agent
+ ```
+
+ Example:
+ ```
+ -e guest_agent=qemu
+ ```
+
- Disable configuration stage modules in Cloud-init. Mostly useful when you are building for non-cloud environments, where Cloud-init meta-data is not available (default: false):
```
-e cloud_init_disable_config=true
diff --git a/qemu.yml b/qemu.yml
index 86a9e60..cd21dc7 100644
--- a/qemu.yml
+++ b/qemu.yml
@@ -25,6 +25,7 @@
- install-grub
- install-persistence-conf
- install-cloud-init-wrapper
+ - install-guest-agent-wrapper
- fstrim
- unmount-pre
- create-pxe-archive
diff --git a/roles/install-guest-agent-wrapper/tasks/main.yml b/roles/install-guest-agent-wrapper/tasks/main.yml
new file mode 100644
index 0000000..f41e111
--- /dev/null
+++ b/roles/install-guest-agent-wrapper/tasks/main.yml
@@ -0,0 +1,4 @@
+- name: Check if we need to install VM guest agents
+ include_role:
+ name: install-guest-agent
+ when: guest_agent is defined
diff --git a/roles/install-guest-agent-wrapper/tests/inventory b/roles/install-guest-agent-wrapper/tests/inventory
new file mode 100644
index 0000000..878877b
--- /dev/null
+++ b/roles/install-guest-agent-wrapper/tests/inventory
@@ -0,0 +1,2 @@
+localhost
+
diff --git a/roles/install-guest-agent-wrapper/tests/test.yml b/roles/install-guest-agent-wrapper/tests/test.yml
new file mode 100644
index 0000000..1c75a3b
--- /dev/null
+++ b/roles/install-guest-agent-wrapper/tests/test.yml
@@ -0,0 +1,4 @@
+---
+- hosts: localhost
+ roles:
+ - install-guest-agent-wrapper
diff --git a/roles/install-guest-agent/files/debian.list.buster b/roles/install-guest-agent/files/debian.list.buster
new file mode 100644
index 0000000..4950c4e
--- /dev/null
+++ b/roles/install-guest-agent/files/debian.list.buster
@@ -0,0 +1,4 @@
+deb http://deb.debian.org/debian buster main contrib non-free
+deb http://security.debian.org/debian-security/ buster/updates main contrib non-free
+deb http://deb.debian.org/debian buster-updates main contrib non-free
+deb http://dev.packages.vyos.net/repositories/current current main
diff --git a/roles/install-guest-agent/files/debian.list.jessie b/roles/install-guest-agent/files/debian.list.jessie
new file mode 100644
index 0000000..885e26b
--- /dev/null
+++ b/roles/install-guest-agent/files/debian.list.jessie
@@ -0,0 +1,5 @@
+deb http://deb.debian.org/debian jessie main contrib non-free
+deb http://security.debian.org/debian-security/ jessie/updates main contrib non-free
+deb http://deb.debian.org/debian jessie-updates main contrib non-free
+deb http://dev.packages.vyos.net/repositories/crux/vyos crux main
+deb http://dev.packages.vyos.net/repositories/crux/debian crux main
diff --git a/roles/install-guest-agent/files/resolv.conf b/roles/install-guest-agent/files/resolv.conf
new file mode 100644
index 0000000..81027f8
--- /dev/null
+++ b/roles/install-guest-agent/files/resolv.conf
@@ -0,0 +1 @@
+nameserver 1.1.1.1 \ No newline at end of file
diff --git a/roles/install-guest-agent/tasks/main.yml b/roles/install-guest-agent/tasks/main.yml
new file mode 100644
index 0000000..f636f53
--- /dev/null
+++ b/roles/install-guest-agent/tasks/main.yml
@@ -0,0 +1,46 @@
+- name: Get Debian version
+ become: true
+ command: chroot {{ vyos_install_root }} awk 'match($0, /VERSION=.*\((\w+)\)/, version) { print version[1] }' /etc/os-release
+ register: debian_version
+- name: Set VyOS branch name crux
+ set_fact:
+ vyos_branch: "crux"
+ when: vyos_version is regex("^1\.2.*$")
+- name: Put debian.list
+ become: true
+ copy:
+ src: "files/debian.list.{{ debian_version.stdout }}"
+ dest: "{{ vyos_install_root }}/etc/apt/sources.list.d/debian.list"
+- name: backup resolv.conf
+ become: true
+ command: mv {{ vyos_install_root }}/etc/resolv.conf /tmp/resolv.conf
+- name: add nameserver settings to chroot
+ become: true
+ copy:
+ src: "files/resolv.conf"
+ dest: "{{ vyos_install_root }}/etc/resolv.conf"
+- name: apt-get update
+ become: true
+ command: chroot {{ vyos_install_root }} apt-get update
+- name: Install qemu-guest-agent
+ become: true
+ command: chroot {{ vyos_install_root }} apt-get -t {{ vyos_branch | default('current') }} install -y qemu-guest-agent
+ when: guest_agent == "qemu"
+- name: Install open-vm-tools
+ become: true
+ command: chroot {{ vyos_install_root }} apt-get -t {{ vyos_branch | default('current') }} install -y open-vm-tools
+ when: guest_agent == "vmware"
+- name: apt-get clean
+ become: true
+ command: chroot {{ vyos_install_root }} apt-get clean
+- name: delete apt lists from cache
+ become: true
+ command: chroot {{ vyos_install_root }} rm -rf /var/lib/apt/lists/
+- name: Delete debian.list
+ become: true
+ file:
+ path: "{{ vyos_install_root }}/etc/apt/sources.list.d/debian.list"
+ state: absent
+- name: restore original resolv.conf
+ become: true
+ command: mv /tmp/resolv.conf {{ vyos_install_root }}/etc/resolv.conf
diff --git a/roles/install-guest-agent/tests/inventory b/roles/install-guest-agent/tests/inventory
new file mode 100644
index 0000000..878877b
--- /dev/null
+++ b/roles/install-guest-agent/tests/inventory
@@ -0,0 +1,2 @@
+localhost
+
diff --git a/roles/install-guest-agent/tests/test.yml b/roles/install-guest-agent/tests/test.yml
new file mode 100644
index 0000000..79b8c2d
--- /dev/null
+++ b/roles/install-guest-agent/tests/test.yml
@@ -0,0 +1,4 @@
+---
+- hosts: localhost
+ roles:
+ - install-guest-agent