Skip to content

Commit

Permalink
keeping existing netplan config
Browse files Browse the repository at this point in the history
  • Loading branch information
Giancarlo Garcia authored and Giancarlo Garcia committed Apr 27, 2020
1 parent 9425e79 commit 2c53a38
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 16 deletions.
28 changes: 28 additions & 0 deletions playbooks/config_network.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ansible-playbook -b --private-key /Users/giancarlo3g/.ssh/id_rsa_multipass --ask-vault-pass vsr_vm.yml

# ansible-galaxy install mrlesmithjr.netplan for netplan
# ansible-vault create password.yml -> add password in plain text

---
- hosts: packet
vars:
tasks:
roles:
- role: mrlesmithjr.netplan
become: yes
netplan_enabled: true
netplan_remove_existing: no
netplan_config_file: /etc/netplan/my_netplan.yaml
netplan_renderer: networkd
netplan_configuration:
network:
version: 2
bridges:
br-mgmt:
addresses:
- 192.168.1.1/24
#gateway4: 192.168.1.1
br-wan:
dhcp4: yes
netplan_apply: True

46 changes: 46 additions & 0 deletions playbooks/start_vm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# ansible-playbook -b --private-key /Users/giancarlo3g/.ssh/id_rsa_multipass --ask-vault-pass start_vm.yml

# sudo pip install passlib is required on MacOS for encrypted passwords
# ansible-galaxy install mrlesmithjr.netplan for netplan
# ansible-vault create password.yml -> add password in plain text

---
- hosts: packet

vars:
license_path: "/Users/giancarlo3g/Downloads/VSR-SIM_R20_license.txt"
xml_path: "/Users/giancarlo3g/Desktop/vsr01-sr1.xml"
image_path: "/Users/giancarlo3g/Downloads/vm/sros-i386/sros-vm.qcow2"

tasks:

##################### instantiate VMs #########################

- name: define vm
become: yes
virt:
command: define
xml: /etc/libvirt/qemu/vsr01-sr1.xml
- name: start vm
become: yes
virt:
name: vsr01-sr1
state: running
- name: set autostart for VM
become: yes
virt:
name: vsr01-sr1
autostart: yes

#############################################################











82 changes: 66 additions & 16 deletions playbooks/vsr_vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,17 @@
- hosts: packet

vars:
tasks:
- name: install basic pack
apt:
name: ['qemu-kvm', 'libvirt-bin', 'vsftpd']
update_cache: yes
become: yes

- name: create admin user with passwd
user:
name: admin
home: /home/admin
password: "{{ 'admin' | password_hash('sha512') }}" # check vault file for plain text password
update_password: always
src_license_path: "/Users/giancarlo3g/Downloads/VSR-SIM_R20_license.txt"
src_xml_path: "/Users/giancarlo3g/Desktop/vsr01-sr1.xml"
src_image_path: "/Users/giancarlo3g/Downloads/vm/sros-i386/sros-vm.qcow2"

# create br-mgmt and br-wan bridges
roles:
- role: mrlesmithjr.netplan
become: yes
netplan_enabled: true
netplan_config_file: /etc/netplan/my-netplan.yaml
netplan_remove_existing: no
netplan_config_file: /etc/netplan/my_netplan.yaml
netplan_renderer: networkd
netplan_configuration:
network:
Expand All @@ -36,13 +27,72 @@
br-mgmt:
addresses:
- 192.168.1.1/24
gateway4: 192.168.1.1
#gateway4: 192.168.1.1
br-wan:
dhcp4: yes
netplan_apply: True


# - name: copy files to server
tasks:
- name: install qemu, libvirt, vsftpd
apt:
name: ['qemu-kvm', 'libvirt-bin', 'vsftpd']
update_cache: yes
become: yes

- name: create admin user with passwd
user:
name: admin
home: /home/admin
password: "{{ 'admin' | password_hash('sha512') }}" # check vault file for plain text password
update_password: always

# copy vsr license to server
- name: create license directory
file:
path: /home/admin/license
state: directory
owner: admin
- name: copy files to server
copy:
src: "{{ src_license_path }}"
dest: /home/admin/license/VSR-SIM_R20_license.txt
register: copy_status

# create lab directory for vsr config files
- name: create lab directory
file:
path: /home/admin/lab
state: directory
owner: admin

################## iterate for several VMs ##################

# copy vsr xml to server
- name: copy xml to server
become: yes
copy:
src: "{{ src_xml_path }}"
dest: /etc/libvirt/qemu/vsr01-sr1.xml
register: copy_status

# copy vsr image to server
- name: copy vsr image to server
become: yes
copy:
src: "{{ src_image_path }}"
dest: /var/lib/libvirt/images/sros-vm.qcow2
register: copy_status













0 comments on commit 2c53a38

Please sign in to comment.