ansible/playbooks/test_replace.yml

30 lines
1.2 KiB
YAML
Raw Normal View History

2024-05-28 01:42:45 +02:00
- hosts: router
2024-06-03 00:38:40 +02:00
name: Switch destination
2024-05-27 23:44:28 +02:00
ignore_unreachable: false
tasks:
2024-05-28 01:42:45 +02:00
- name: Get ruleset
command: nvram get vts_rulelist
when: inventory_hostname in groups['router']
register: ruleset
2024-05-27 23:49:46 +02:00
- name: Print the gateway for each host when defined
ansible.builtin.debug:
2024-05-28 01:42:45 +02:00
msg: "var is {{ ruleset.stdout }}"
2024-05-28 02:13:52 +02:00
- name: initialize variables
set_fact:
2024-06-03 00:38:40 +02:00
regexp: "\\g<1>{{ DESTINATION }}\\3"
2024-05-28 00:29:54 +02:00
- set_fact:
2024-05-28 02:17:32 +02:00
app_path: "{{ ruleset.stdout | regex_replace('(\\<MAIL_SERVER\\>[0-9,]{1,}\\>)([0-9.]{1,})(\\>[0-9a-zA-Z\\s-]{0,}\\>TCP\\>)', regexp) | regex_replace('(\\<WEB_SERVER\\>[0-9,]{1,}\\>)([0-9.]{1,})(\\>[0-9a-zA-Z\\s-]{0,}\\>TCP\\>)', regexp) }}"
2024-05-28 00:35:57 +02:00
- name: Print the gateway for each host when defined
ansible.builtin.debug:
2024-06-03 00:41:48 +02:00
msg: "var is {{ app_path }}"
- name: Set ruleset
command: nvram set vts_rulelist={{ app_path }}
2024-06-03 00:44:37 +02:00
when: inventory_hostname in groups['router']
- name: Commit ruleset
command: nvram commit
when: inventory_hostname in groups['router']
- name: Commit ruleset
command: service restart_firewall
when: inventory_hostname in groups['router']