In this blog post, I will show you how to use Ansible to deploy configurations to the Palo Alto Firewalls.
Setting up the environment
I'm using Ubuntu 18.04 server for this example.
- Ansible Galaxy Role
- pip
- pan-os SDK
Palo Alto Networks Ansible Galaxy Role
https://ansible-pan.readthedocs.io/en/latest/
The Palo Alto Networks Ansible Galaxy role is a collection of modules that automate configuration and operational tasks on Palo Alto Firewalls and Panorama. The underlying protocol uses API calls that are wrapped within the Ansible framework.
You can install the collection by using ansible-galaxy collection install paloaltonetworks.panos
command
Install pip
Pip is a package management system that simplifies the installation and management of software packages written in Python.
You can install it by using sudo apt install python-pip
command
Palo Alto Networks PAN-OS SDK for Python
The PAN-OS SDK for Python (pan-os-python) is a package to help interact with Palo Alto Networks devices
Ansible Installation
You can install Ansible by using this guide: Installing Ansible — Ansible Documentation
Ansible Installation
Ansible files
Tree
hosts
Ansible.cfg
Diagram

I created a local user name and password on the Palo Alto via the GUI
Get your API key
In this example, I'm using the API key instead of using username/password.
To use the API, you must generate the API key required for authenticating API calls. To generate an API key, make a GET
or POST
request to the firewall’s hostname or IP addresses using the administrative credentials and type keygen
A successful API call returns status="success"
along with the API key within the key element.
Playbook
The Playbook creates the following
- Create address-objects for
server1
andusers
- Management Profile which allows ping to the
INSIDE
interface - Create
INSIDE
andUSERS
zones - Adding
eth1/1
andeth1/2
interfaces to each zone. - Security rule allowing
ping
fromusers-subnet
toserver1
Playbook
Verification

Encrypting sensitive data with Ansible Vault.
Ansible Vault encrypts variables or files so, the sensitive data such as passwords or keys are not visible. In our example, we can see that the api_key
is visible in the Playbook.
I'm going to move the palo_provider
variable to group_vars
directory and add the api_key
to the vault.
Create a vault and move the api_key
The most straightforward way of decrypting content at runtime is to have Ansible prompt you for the appropriate credentials. You can do this by adding the --ask-vault-pass
to any ansible
or ansible-playbook
command.
Using Ansible Vault with a Password File
If you do not wish to type in the Vault password each time you execute a task, you can add your Vault password to a file and reference the file during execution.
To make Ansible aware of the password file, you can edit your ansible.cfg
file
Now, when you run commands that require decryption, you will no longer be prompted for the vault password.
Thanks for reading.
As always, your feedback and comments are more than welcome.