Deleting interface + dhcp relay using ansible

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Deleting interface + dhcp relay using ansible

L1 Bithead

Hello,

Versions in use:

ansible 2.9.22
pan-python==0.19.0
pandevice==0.14.0
panos firewall 9.1.10

I have created a playbook that adds a DHCP relay element and now i need to do the delete the DHCP relay and haven't found the way.
This is the playbook for adding one:

---
- name: DHCP
hosts: localhost
connection: local
vars:
- ansible_python_interpreter: /usr/bin/env python3
roles:
- role: PaloAltoNetworks.paloaltonetworks
gather_facts: False
tasks:
- name: Grab the credentials
include_vars: 'firewall-secrets.yml'
- name: Create DHCP relay on interface
panos_type_cmd:
ip_address: '{{ ip_address }}'
username: '{{ username }}'
password: '{{ password }}'
cmd: "set"
xpath: "/config/devices/entry[@name='localhost.localdomain']/network/dhcp/interface/entry[@name='a5.22']/relay"
element: "<ip><server><member>10.x.x.x1</member></server><enabled>yes</enabled></ip><ip><server><member>10.x.x.x2</member></server><enabled>yes</enabled></ip>"

When trying to delete i have used this:

tasks:
- name: delete DHCP relay on interface
panos_type_cmd:
ip_address: '{{ ip_address }}'
username: '{{ username }}'
password: '{{ password }}'
cmd: "delete"
xpath: "/config/devices/entry[@name='localhost.localdomain']/network/dhcp/interface/entry[@name='a5.22']/relay"

Ansible verbose doesn't give any error,
Its only getting the firewall stuck(i cannot preform any commits until I delete the change) , The main task is to remove the interface "a5.22" using panos_l3_subinterface module. but it doesn't give me to delete a device before I delete the relay.
there is no docs for this - does anyone know how?

Thanks.

2 REPLIES 2

L1 Bithead

Hey,

no it is not resolved if i figure this out ill post here  🙂

Hi @batchenr, when adapted to my lab, the code you posted works ok for me:

    - name: Create DHCP relay on interface
      paloaltonetworks.panos.panos_type_cmd:
        provider: "{{ device }}"
        cmd: "set"
        xpath: "/config/devices/entry[@name='localhost.localdomain']/network/dhcp/interface/entry[@name='{{ interface }}']/relay"
        element: "<ip><server><member>{{ relay_ip_1 }}</member><member>{{ relay_ip_2 }}</member></server><enabled>yes</enabled></ip>"

    - name: delete DHCP relay on interface
      paloaltonetworks.panos.panos_type_cmd:
        provider: "{{ device }}"
        cmd: "delete"
        xpath: "/config/devices/entry[@name='localhost.localdomain']/network/dhcp/interface/entry[@name='{{ interface }}']/relay"
Help the community: "Like" helpful comments, and click "Accept as Solution" if you found your answer 🙂
  • 2341 Views
  • 2 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!