Skip to content

Commit

Permalink
Merge pull request #4 from gavinwill/linting
Browse files Browse the repository at this point in the history
Ansible linting for role
  • Loading branch information
gavinwill authored Apr 1, 2023
2 parents cdfaa59 + 99fa2c8 commit 6270e10
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
11 changes: 9 additions & 2 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
galaxy_info:
author: Gavin Will
description: ansible role to backup pfsense firewalls
description: Ansible Role to Backup pfSense Firewalls
role_name: ansible_role_pfsense_backup
namespace: ansible_role_pfsense_backup

issue_tracker_url: https://github.com/gavinwill/ansible-role-pfsense-backup/issues

license: MIT

min_ansible_version: 2.9
min_ansible_version: "2.9"

platforms:
- name: FreeBSD
versions:
- all

galaxy_tags:
- pfsense
Expand Down
46 changes: 23 additions & 23 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Documentation from netgate for remote backup options:
# https://docs.netgate.com/pfsense/en/latest/backup/remote-backup.html

- name: pfSense Backup | Assert that hostname and credentials supplied
- name: PfSense Backup | Assert that hostname and credentials supplied
ansible.builtin.assert:
that:
- "{{ item }} | length"
Expand All @@ -14,36 +14,36 @@
- pfsense_password
- pfsense_backup_directory

- name: pfSense Backup | Construct Backup URL Protocol
- name: PfSense Backup | Construct Backup URL Protocol
ansible.builtin.set_fact:
pfsense_backup_protocol: "{{'http' if not (pfsense_https) else 'https'}}"
pfsense_backup_protocol: "{{ 'http' if not (pfsense_https) else 'https' }}"

- name: pfSense Backup | Obtain Cookies & CSRF Token
- name: PfSense Backup | Obtain Cookies & CSRF Token
ansible.builtin.uri:
url: "{{ pfsense_backup_protocol }}://{{ pfsense_hostname }}/{{ pfsense_backup_page }}"
validate_certs: "{{ pfsense_validate_certificates }}"
method: GET
return_content: yes
return_content: true
register: pfsense_cookie_token
no_log: "{{ pfsense_backup_no_log }}"

- name: pfSense Backup | Set Fact for CSRF Token
- name: PfSense Backup | Set Fact for CSRF Token
ansible.builtin.set_fact:
pfsense_backup_csrf0: "{{ pfsense_cookie_token.content | regex_search('var\\s+csrfMagicToken\\s+=\\s+\\\"([a-f0-9sidp:;,]+)\\\"','\\1') }}"
pfsense_backup_csrf0: "{{ pfsense_cookie_token.content | regex_search('var\\s+csrfMagicToken\\s+=\\s+\\\"([a-f0-9sidp:;,]+)\\\"', '\\1') }}"
no_log: "{{ pfsense_backup_no_log }}"

- name: pfSense Backup | Set Fact for CSRF Cookie
- name: PfSense Backup | Set Fact for CSRF Cookie
ansible.builtin.set_fact:
pfsense_backup_cookie0: "{{ pfsense_cookie_token.set_cookie }}"
pfsense_backup_cookie0: "{{ pfsense_cookie_token.set_cookie }}"
no_log: "{{ pfsense_backup_no_log }}"

- name: pfSense Backup | Authenticate with backup page and register Backup CSRF
- name: PfSense Backup | Authenticate with backup page and register Backup CSRF
ansible.builtin.uri:
url: "{{ pfsense_backup_protocol }}://{{ pfsense_hostname }}/{{ pfsense_backup_page }}"
validate_certs: "{{ pfsense_validate_certificates }}"
follow_redirects: no
follow_redirects: false
method: POST
return_content: yes
return_content: true
body_format: form-urlencoded
status_code: 302
body:
Expand All @@ -56,39 +56,39 @@
register: pfsense_cookie_token2
no_log: "{{ pfsense_backup_no_log }}"

- name: pfSense Backup | Set Fact for Cookie from Backup Page
- name: PfSense Backup | Set Fact for Cookie from Backup Page
ansible.builtin.set_fact:
pfsense_backup_cookie1: "{{ pfsense_cookie_token2.set_cookie }}"
no_log: "{{ pfsense_backup_no_log }}"

- name: pfSense Backup | Fetch Target page for new CSRF token
- name: PfSense Backup | Fetch Target page for new CSRF token
ansible.builtin.uri:
url: "{{ pfsense_backup_protocol }}://{{ pfsense_hostname }}/{{ pfsense_backup_page }}"
validate_certs: "{{ pfsense_validate_certificates }}"
follow_redirects: no
follow_redirects: false
method: GET
return_content: yes
return_content: true
headers:
Cookie: "{{ pfsense_backup_cookie1 }}"
register: pfsense_cookie_token3
no_log: "{{ pfsense_backup_no_log }}"

- name: PFSENSE | Set Fact for CSRF Token
- name: PfSense Backup | Set Fact for CSRF Token
ansible.builtin.set_fact:
pfsense_backup_csrf1: "{{ pfsense_cookie_token3.content | regex_search('var\\s+csrfMagicToken\\s+=\\s+\\\"([a-f0-9sidp:;,]+)\\\"','\\1') }}"
pfsense_backup_csrf1: "{{ pfsense_cookie_token3.content | regex_search('var\\s+csrfMagicToken\\s+=\\s+\\\"([a-f0-9sidp:;,]+)\\\"', '\\1') }}"
no_log: "{{ pfsense_backup_no_log }}"

- name: pfSense Backup | Set Fact for CSRF Cookie
- name: PfSense Backup | Set Fact for CSRF Cookie
ansible.builtin.set_fact:
pfsense_backup_cookie2: "{{ pfsense_cookie_token3.set_cookie }}"
pfsense_backup_cookie2: "{{ pfsense_cookie_token3.set_cookie }}"
no_log: "{{ pfsense_backup_no_log }}"

- name: pfSense Backup | Download Backup Configuration
- name: PfSense Backup | Download Backup Configuration
ansible.builtin.uri:
url: "{{ pfsense_backup_protocol }}://{{ pfsense_hostname }}/{{ pfsense_backup_page }}"
validate_certs: "{{ pfsense_validate_certificates }}"
method: POST
return_content: yes
return_content: true
body_format: form-urlencoded
body:
download: download
Expand All @@ -97,7 +97,7 @@
donotbackuprrd: "{{'yes' if (pfsense_donotbackuprrd) | default(omit) }}"
encrypt: "{{'yes' if (pfsense_encrypted_password | length) | default(omit) }}"
encrypt_password: "{{ (pfsense_encrypted_password) | default(omit) }}"
encrypt_password_confirm: "{{ (pfsense_encrypted_password ) | default(omit) }}"
encrypt_password_confirm: "{{ (pfsense_encrypted_password) | default(omit) }}"
__csrf_magic: "{{ pfsense_backup_csrf1 }}"
headers:
Cookie: "{{ pfsense_backup_cookie2 }}"
Expand Down

0 comments on commit 6270e10

Please sign in to comment.