Skip to content

Commit

Permalink
Added support for installing NSO from local files
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonking3 committed Jan 19, 2024
1 parent 661359c commit 2d87fa4
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 116 deletions.
8 changes: 8 additions & 0 deletions roles/nso/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
nso_host_group: 'nso'
nso_url: "{{ nso_rest_url }}/jsonrpc"
nso_package_src: "{{ lookup('env', 'PWD') }}/packages"
nso_remote_src: yes
nso_installer_name: "nso-5.5.3.linux.x86_64.signed.bin"
nso_install_dir: /opt/ncs/current
nso_run_dir: /var/opt/ncs
nso_etc_dir: /etc/ncs
nso_tmp_dir: /tmp/nso
nso_upload_dir: /tmp/nso
nso_java_opts: "-Xmx2G -Xms1G"
nso_package_requirements:
- default-jdk
- openssh-client
- ant
- make
- libxml2-utils
- xsltproc
# Default username/password for the NSO host
# admin_user: ubuntu
# admin_password: admin
Expand Down
174 changes: 65 additions & 109 deletions roles/nso/tasks/install.yaml
Original file line number Diff line number Diff line change
@@ -1,53 +1,10 @@
---
- name: Install prerequisites for NSO
apt:
name:
- default-jdk
- openssh-client
- ant
- make
- libxml2-utils
- xsltproc
name: "{{ nso_package_requirements }}"
update_cache: yes
install-recommends: no

# - name: Clean up any previous NSO installation
# hosts: nso_hosts
# connection: ssh
# vars:
# ansible_user: "{{ admin_user }}"
# ansible_ssh_private_key_file: "{{ admin_private_key_file }}"
# ansible_python_interpreter: "/usr/bin/python3"
# tags:
# - cleanup
# - nso
# any_errors_fatal: true
# gather_facts: no
# tasks:
# - name: Remove install directory
# file:
# path: '/home/{{ admin_user }}/{{ nso_install_dir }}'
# state: absent

# - name: Remove run directory
# file:
# path: '/home/{{ admin_user }}/{{ nso_run_dir }}'
# state: absent

# - name: NSO install
# hosts: nso_hosts
# connection: ssh
# vars:
# ansible_user: "{{ admin_user }}"
# ansible_ssh_private_key_file: "{{ admin_private_key_file }}"
# ansible_python_interpreter: "/usr/bin/python3"
# tags:
# - setup
# - nso
# any_errors_fatal: true
# gather_facts: no
# tasks:
# - name: Remove install directory
- name: Create temporary installer directory
file:
path: "{{ nso_tmp_dir }}"
Expand All @@ -57,10 +14,33 @@
get_url:
url: "{{ nso_installer_file }}"
dest: "{{ nso_tmp_dir }}"
# copy:
# src: "{{ nso_package_src }}/{{ nso_installer_name }}"
# dest: "{{ nso_tmp_dir }}/{{ nso_installer_name }}"
register: copy_results
when: nso_remote_src | bool

- block:
- name: Create temporary installer directory
file:
path: "{{ nso_tmp_dir }}"
state: directory
connection: local
become: no

- name: Copy installer to {{ nso_tmp_dir }} directory
get_url:
url: "{{ nso_installer_file }}"
dest: "{{ nso_tmp_dir }}/{{ nso_installer_file | basename }}"
connection: local
become: no
register: copy_results
vars:
ansible_python_interpreter: "{{ hostvars['localhost'].ansible_python_interpreter}}"

- name: Copy installer to {{ inventory_hostname }}
copy:
src: "{{ copy_results.dest }}"
dest: "{{ copy_results.dest }}"
register: copy_results
when: not nso_remote_src | bool

- block:
- set_fact:
Expand All @@ -70,28 +50,54 @@
- name: "Unpack '{{ local_installer_file }}'"
shell: 'cd {{ nso_tmp_dir }}; sh {{ local_installer_file }} --skip-verification'

# - name: Find installer name
# ansible.builtin.find:
# paths: "{{ nso_tmp_dir }}"
# patterns: 'nso-*.installer.bin'
# register: find_results

- set_fact:
nso_installer_bin: '{{ local_installer_file | regex_replace("signed.bin$","installer.bin") }}'
nso_installer_bin: '{{ local_installer_file | regex_replace("-freetrial", "") | regex_replace("signed.bin$","installer.bin") }}'
when: '"signed.bin" in local_installer_file'

- name: Run the NSO installer
- name: "Run {{ nso_installer_bin }}"
shell: 'sh {{ nso_installer_bin }} --system-install'
when: copy_results.changed

# - name: Find NSO packages
# find:
# paths: "{{ nso_package_src }}"
# patterns: 'ncs-*.signed.bin'
# delegate_to: localhost
# become: no
# register: find_results

- name: Upload the NSO packages
- name: Get the NSO packages
get_url:
url: "{{ item }}"
dest: "{{ nso_tmp_dir }}"
loop: "{{ nso_ned_files }}"
register: copy_results
when: nso_remote_src | bool

- block:
- name: Create temporary installer directory
file:
path: "{{ nso_tmp_dir }}"
state: directory
connection: local
become: no

- name: Copy NSO packages to {{ nso_tmp_dir }} directory
get_url:
url: "{{ item }}"
dest: "{{ nso_tmp_dir }}/{{ item | basename }}"
loop: "{{ nso_ned_files }}"
connection: local
become: no
register: copy_results
vars:
ansible_python_interpreter: "{{ hostvars['localhost'].ansible_python_interpreter}}"

- name: Copy NSO packages to {{ inventory_hostname }}
copy:
src: "{{ item.dest }}"
dest: "{{ item.dest }}"
loop: "{{ copy_results.results }}"
register: copy_results
when: not nso_remote_src | bool

- name: Unpack NSO packages
shell: 'cd {{ nso_tmp_dir }}; sh {{ item.dest }} --skip-verification'
Expand All @@ -100,7 +106,7 @@

- name: Extract packages into {{ nso_run_dir }}/packages
ansible.builtin.unarchive:
src: "{{ item.dest | regex_replace('signed.bin$', 'tar.gz') }}"
src: "{{ item.dest | regex_replace('-freetrial', '') | regex_replace('signed.bin$', 'tar.gz') }}"
dest: "{{ nso_run_dir }}/packages"
remote_src: yes
loop: "{{ copy_results.results }}"
Expand Down Expand Up @@ -145,53 +151,3 @@
name: ncs.service
state: started
enabled: yes

# - name: Clean up installer
# file:
# path: '{{ tempdir.path }}'
# state: absent

# - name: Tweak bash profile
# blockinfile:
# path: '/home/{{ admin_user }}/.bashrc'
# insertafter: EOF
# block: |
# if [ -f ~/{{ nso_install_dir }}/ncsrc ]; then
# . ~/{{ nso_install_dir }}/ncsrc
# fi
# export NCS_JAVA_VM_OPTIONS="{{ nso_java_opts }}"

# - name: Initial NSO setup
# shell: '$HOME/{{ nso_install_dir }}/bin/ncs-setup --dest $HOME/{{ nso_run_dir }}'

# - name: Install additional NSO packages/NEDs
# hosts: nso_hosts
# connection: ssh
# vars:
# ansible_user: "{{ admin_user }}"
# ansible_ssh_private_key_file: "{{ admin_private_key_file }}"
# ansible_python_interpreter: "/usr/bin/python3"
# tags:
# - setup
# - nso_packages
# - nso
# any_errors_fatal: true
# gather_facts: no
# tasks:
# - name: Process package list
# block:
# - name: Create temporary package holding directory
# tempfile:
# state: directory
# suffix: pkg
# register: tempdir

# - name: Process each package
# include_tasks: nso-installNSOPackage.yaml
# loop: "{{ nso_package_list }}"

# - name: Remove temporary package holding directory
# file:
# path: '{{ tempdir.path }}'
# state: absent
# when: nso_package_list is defined
10 changes: 4 additions & 6 deletions roles/nso/tasks/install_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
- name: Process package list
environment:
NCS_JAVA_VM_OPTIONS: "{{ nso_java_opts }}"
vars:
remote_src: yes
block:
- name: Remove old package directory
file:
Expand All @@ -23,12 +21,12 @@
copy:
src: "/tmp/{{ item.0.name }}/{{ item.1 }}"
dest: "{{ nso_run_dir }}/packages"
remote_src: "{{ remote_src }}"
remote_src: "{{ nso_remote_src }}"
register: copy_results
with_subelements:
- "{{ nso_package_repos }}"
- service_list
when: remote_src | bool
when: nso_remote_src | bool

- block:
- name: Clone model-driven-devops nso-oc-services repo locally
Expand All @@ -49,10 +47,10 @@
with_subelements:
- "{{ nso_package_repos }}"
- service_list
when: not remote_src | bool
when: not nso_remote_src | bool

- set_fact:
results: "{{ copy_results if remote_src | bool else synchronize_results }}"
results: "{{ copy_results if nso_remote_src | bool else synchronize_results }}"

- name: Make packages
command:
Expand Down
3 changes: 2 additions & 1 deletion roles/nso/tasks/update_yaml_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

- name: Write Config Data to Device Directory
copy:
content: "{{ data | ciscops.mdd.to_even_nicer_yaml }}"
# content: "{{ data | ciscops.mdd.to_even_nicer_yaml }}"
content: "{{ data | to_nice_yaml(2) }}"
dest: "{{ mdd_device_dir }}/config-data.yml"
vars:
data: "{{ { 'mdd_data': { 'config': nso_device_config['config'] } } }}"
Expand Down

0 comments on commit 2d87fa4

Please sign in to comment.