Skip to content

Commit

Permalink
Merge pull request #473 from netscaler/sshconnection
Browse files Browse the repository at this point in the history
Migration of sshConnection module for netscaler adc
  • Loading branch information
shivashankar-vaddepally authored Dec 18, 2024
2 parents 460053d + 0dae055 commit d529b45
Show file tree
Hide file tree
Showing 13 changed files with 605 additions and 13 deletions.
19 changes: 19 additions & 0 deletions examples/ssh_connections/echo_hello.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Ansible ssh playbook
hosts: demo_netscalers
connection: netscaler.adc.ssh_netscaler_adc
remote_user: nsroot
gather_facts: false

vars:
ansible_python_interpreter: /var/python/bin/python

tasks:
- name: Calling shell module
register: echo_result
changed_when: false
ansible.builtin.command: "echo hello"

- name: Show command output
ansible.builtin.debug:
msg: "{{ echo_result }}"
7 changes: 7 additions & 0 deletions examples/ssh_connections/inventory_connection.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[demo_netscaler1]
demo_netscalers

[demo_netscaler1:vars]
ansible_host= <nsip>
remote_user= <username>
nitro_pass= <password>
34 changes: 34 additions & 0 deletions examples/ssh_connections/multiple_plays.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: Ansible ssh playbook
hosts: demo_netscalers
connection: netscaler.adc.ssh_netscaler_adc
remote_user: nsroot
gather_facts: false

vars:
ansible_python_interpreter: /var/python/bin/python

tasks:
- name: Calling shell module
ansible.builtin.command: "echo hello"
changed_when: false
register: echo_result

- name: Show command output
ansible.builtin.debug:
msg: "{{ echo_result }}"

- name: Ansible ssh playbook
hosts: demo_netscalers
gather_facts: false
tasks:
- name: Setup server
delegate_to: localhost
netscaler.adc.server:
nsip: "{{ ansible_host }}"
nitro_user: "{{ remote_user }}"
nitro_pass: "{{ nitro_pass }}"
validate_certs: false

name: test-server-1
ipaddress: 192.168.2.2
25 changes: 25 additions & 0 deletions examples/ssh_connections/nscli_command.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: Run nscli command
hosts: demo_netscalers
remote_user: nsroot
connection: netscaler.adc.ssh_netscaler_adc
gather_facts: false
vars:
ansible_python_interpreter: /var/python/bin/python

# Any valid nscli command works
nscli_command: "show ns ip"


tasks:
- name: Run nscli command
ansible.builtin.command: "nscli -s -U :nsroot:{{ nitro_pass }} {{ nscli_command }}"
no_log: true
changed_when: false
register: nscli_output

# Actually insecure for production environments since it will show the nitro_pass variable value.
# Used here for demonstration purposes only.
- name: Show nscli output
ansible.builtin.debug:
msg: "{{ nscli_output }}"
28 changes: 28 additions & 0 deletions examples/ssh_connections/override_generic_tasks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
- name: Ansible ssh playbook
hosts: demo_netscalers
gather_facts: false
tasks:
- name: Calling shell module
connection: netscaler.adc.ssh_netscaler_adc
remote_user: nsroot
vars:
ansible_python_interpreter: /var/python/bin/python
ansible.builtin.command: "echo hello"
changed_when: false
register: echo_result

- name: Show command output
ansible.builtin.debug:
msg: "{{ echo_result }}"

- name: Setup server
delegate_to: localhost
netscaler.adc.server:
nsip: "{{ ansible_host }}"
nitro_user: "{{ remote_user }}"
nitro_pass: "{{ nitro_pass }}"
validate_certs: false

name: test-server-1
ipaddress: 192.168.2.2
34 changes: 34 additions & 0 deletions examples/ssh_connections/override_netscaler_adc_tasks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: Ansible ssh playbook
hosts: demo_netscalers
connection: netscaler.adc.ssh_netscaler_adc
remote_user: nsroot
gather_facts: false


vars:
ansible_python_interpreter: /var/python/bin/python

tasks:
- name: Calling shell module
ansible.builtin.command: "echo hello"
changed_when: false
register: echo_result

- name: Show command output
ansible.builtin.debug:
msg: "{{ echo_result }}"

- name: Setup server
delegate_to: localhost
# vars:
# # Path of python executable in controlling machine
# ansible_python_interpreter: /usr/bin/python
netscaler.adc.server:
nsip: "{{ ansible_host }}"
nitro_user: "{{ remote_user }}"
nitro_pass: "{{ nitro_pass }}"
validate_certs: false

name: test-server-1
ipaddress: 192.168.2.2
42 changes: 42 additions & 0 deletions examples/ssh_connections/show_tech_support.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#
# Execute like: ansible-playbook show_tech_support.yml -i hosts
#
---
- name: Ansible ssh playbook
hosts: demo_netscalers
remote_user: nsroot
connection: netscaler.adc.ssh_netscaler_adc
gather_facts: false
vars:
ansible_python_interpreter: /var/python/bin/python


tasks:
- name: Generate technical support bundle
changed_when: false
ansible.builtin.command: "nscli -s -U :nsroot:{{ nitro_pass }} show techsupport"
register: sts_output
no_log: true

- name: Parse output to find tarball path
ansible.builtin.set_fact:
sts_bundle: >-
{{
(sts_output.stdout_lines
| select('search', 'points to')
| list
| first)
.split('points to --->')[1]
| trim
}}
- name: Download STS Bundle locally
changed_when: false
ansible.builtin.fetch:
src: "{{ sts_bundle }}"
dest: "my_ns_sts"

- name: Show STS Bundle path
ansible.builtin.debug:
msg: "STS Bundle downloaded locally into the following directory: ./my_ns_sts{{ sts_bundle }}"
2 changes: 1 addition & 1 deletion meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# Collections must specify a minimum required ansible version to upload
# to galaxy
requires_ansible: '>=2.14.0'
requires_ansible: '>=2.15.0'
# Content that Ansible needs to load from another location or that has
# been deprecated/removed
# plugin_routing:
Expand Down
Loading

0 comments on commit d529b45

Please sign in to comment.