Hello! I can offer some advice. In my findings, often there are no vendor
canned, provided modules so you have to use the netcommon.cli module which
works just as well.
I have successfully deployed playbooks for cisco ios, cisco asa, dell, wlcs
and nxos. Here is one playbook I use for my asa devices that use the
netcommon.cli module.
---
- name: Run show running-config on ASAs
hosts: ASA
gather_facts: false
no_log: false
vars:
ansible_user: "{{ vault_net_user }}"
ansible_password: "{{ vault_net_pass }}"
dest: "{{ asapath }}"
to: "[email protected]
vars_files:
- '/etc/ansible/group_vars/vault.yml'
- '/etc/ansible/group_vars/bkup-paths.yml'
tasks:
- name: Check if backup file exists and is greater than zero
ansible.builtin.stat:
path: "{{ dest }}{{ inventory_hostname }}.cfg"
register: fstat
- name: Rename existing backup file
raw: mv -f "{{ dest |quote }}{{ inventory_hostname |quote }}.cfg"
"{{ dest |quote }}{{ inventory_hostname |quote }}.cfg.1"
when: fstat.stat.exists == true and fstat.stat.size > 0
- block:
- name: Set Terminal pager to unlimited
ansible.netcommon.cli_command:
command: terminal pager 0
register: term_output
- name: Pause
ansible.builtin.pause:
seconds: 1
- name: Run and save sh running-config to the NAS
ansible.netcommon.cli_command:
command: sh running-config
register: cfg_output
- name: Show output
ansible.builtin.debug:
var: cfg_output, term_output
- name: Save running config to the NAS
ansible.builtin.copy:
content: "{{ cfg_output.stdout | replace('\r\n', '\n') }}"
dest: "{{ dest }}{{ inventory_hostname }}.cfg"
rescue:
- name: 'Rescue - print and email failed results'
ansible.builtin.debug:
var: ansible_failed_result
- name: Create email body
set_fact:
email_body: |
<html>
<body><h4>Error during the ASA backup process.</h4>
<pre>
<h5> {{ansible_failed_result|replace('\r\n', '<br>')
}}</h5>
</pre>
</body>
</html>
always:
- name: Mail error result if any
community.general.mail:
sender: [email protected]
host: internal-smtp.xx.xx.com
subtype: plain
to: "{{ to }}"
subject: "{{ inventory_hostname }} backup error"
body: "{{ email_body }}"
when: term_output.failed == true or cfg_output.failed == true
...
On Wednesday, April 17, 2024 at 7:07:22 AM UTC-4 Rahul Kumar wrote:
> Hello All,
>
> I need help in setting ansible to take Sonicwall firewall backups.
>
> Anyone, who is willing to help me is greatly appreciated.
>
>
> Thanks,
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/2e8ab579-a85e-42d1-9499-107e36239ff6n%40googlegroups.com.