From 04deed8de6914f3291592ef9fe0df452408935c2 Mon Sep 17 00:00:00 2001 From: Michael Chapman Date: Thu, 22 Mar 2018 16:12:09 +1100 Subject: [PATCH] Add vagrant output options for nxos and eos Will add a vagrant user with SSH key configured, and create a .box file for use with vagrant-libvirt --- defaults/main.yml | 8 ++++++++ tasks/build_vagrant_box.yml | 13 +++++++++++++ tasks/main.yml | 3 +++ templates/eos/4.20.1F/config.j2 | 5 +++++ templates/nxos/7.0.3.I7.3/config.j2 | 6 ++++++ 5 files changed, 35 insertions(+) create mode 100644 tasks/build_vagrant_box.yml diff --git a/defaults/main.yml b/defaults/main.yml index a9add39..4548dec 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -9,6 +9,14 @@ regular_user: ansible regular_user_password: omgsosecureregular789 enable_password: omgsosecuresecret789 +# Will convert the output qcow2 to a .box that can be imported to vagrant +#build_vagrant_box: false +# +# Adds an admin user called vagrant with the vagrant insecure public key +# configured for ssh access +#add_vagrant_user: false +vagrant_sshkey: "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" + checksum_to_platform_version: 89e0fc9dd45f5682ed222f36f1ea952b049b1888: platform: nxos diff --git a/tasks/build_vagrant_box.yml b/tasks/build_vagrant_box.yml new file mode 100644 index 0000000..5635e9a --- /dev/null +++ b/tasks/build_vagrant_box.yml @@ -0,0 +1,13 @@ +--- +- name: Include platform variables + include_vars: + dir: "{{ platform }}/{{ build_version }}" + +- name: Get box building script + get_url: + url: https://raw.githubusercontent.com/vagrant-libvirt/vagrant-libvirt/master/tools/create_box.sh + dest: "{{ output_directory }}/create_box.sh" + mode: 0777 + +- name: Run box building script + shell: "bash {{ output_directory }}/create_box.sh {{output_directory}}/{{ platform }}.qcow2" diff --git a/tasks/main.yml b/tasks/main.yml index ee3d38c..e7f4bd2 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -10,3 +10,6 @@ - import_tasks: build_wrapper_image.yml when: wrapper_linux_image is defined + +- import_tasks: build_vagrant_box.yml + when: build_vagrant_box is defined and build_vagrant_box diff --git a/templates/eos/4.20.1F/config.j2 b/templates/eos/4.20.1F/config.j2 index 4aef8b4..1cc8fb4 100644 --- a/templates/eos/4.20.1F/config.j2 +++ b/templates/eos/4.20.1F/config.j2 @@ -7,6 +7,11 @@ username {{ regular_user }} secret {{ regular_user_password }} privilege 1 enable secret {{ enable_password }} +{% if add_vagrant_user is defined and add_vagrant +username vagrant secret vagrant privilege +user vagrant sshkey {{ vagrant_sshkey }} +{% endif %} + event-handler dhcp-ma1-on-boot trigger on-boot action bash /mnt/flash/dhcp-ma1-on-boot.sh diff --git a/templates/nxos/7.0.3.I7.3/config.j2 b/templates/nxos/7.0.3.I7.3/config.j2 index b4cfe53..14faf12 100644 --- a/templates/nxos/7.0.3.I7.3/config.j2 +++ b/templates/nxos/7.0.3.I7.3/config.j2 @@ -8,4 +8,10 @@ interface mgmt0 username {{ admin_user }} password {{ admin_user_password }} role network-admin username {{ regular_user }} password {{ regular_user_password }} +{% if add_vagrant_user is defined and add_vagrant_user %} +username vagrant password vagrant role network-admin +username vagrant sshkey {{ vagrant_sshkey }} +username vagrant shell bash +{% endif %} + boot nxos bootflash:nxos.7.0.3.I7.3.bin