I quasi-solved this with some clever Ansible-fu myself. It's a bit involved, but the meat of it is:
* Inventory
1a) if you have a vsx cluster, define ansible hosts for each vsx cluster gateway. Define the IP for "ansible_host: x.x.x.x"
1b) define a logical ansible group for the VSX cluster (VSX_CLUSTER01, with members: gw1, gw2, gw3)
2) Define each VS as an inventory host - attach 2 variables:
vs_id: <vsid>
vsx: <name of the hosting vsx> (either the vsx cluster group name [VSX_CLUSTER01], or single vsx gateway )
3) I have my inventory set for different groups, but somewhere you want to define the Check Point connection variables
# cat inventory/group_vars/check_point/vars.yml
---
ansible_httpapi_validate_certs: false
ansible_httpapi_use_ssl: true
ansible_httpapi_port: "{{ gaia_api_port |default(443) }}"
ansible_network_os: check_point.gaia.checkpoint
...
* Playbooks
I chose to do this all with Gaia API [yes Gaia API works on VSX, just VS0, which is all we need]
It's a nested series of loops. Since the target is a VS, and the VS is on a cluster, the playbooks run the same CLISH command on all VSX gateways of the cluster where that VS is hosted. "show ospf neighbors" only returns neighbors on the active VSX gateway for the VS. But you might want "show configuration ospf" to verify configuration evenness.
I loop through the group of VSX gateways for the that VS's hosting VSX, and building the variables as it goes:
main.yml:
- name: Run CLISH command
hosts: check_point
become: false
gather_facts: false
connection: httpapi
serial: 3
vars:
ansible_network_os: check_point.gaia.checkpoint
output_dir: "clish_output/"
tasks:
tasks:
- name: Run CLISH command on gateways
include_tasks: gaia_clish_cmd.yml
when: vsx is not defined
- name: Run CLISH command on VSX VS
include_tasks: vsx_clish_cmd.yml
when: vsx is defined
...
So if 'vsx' is defined for the inventory host, loop through an inventory group with that name (VSX cluster); no i don't have this really set right to work if the VS is on a single-host VSX; i don't have one of those handy at the moment. It's not too hard to figure out how to adapt this, tho.
# cat vsx_clish_cmd.yml
---
- include_tasks: clish_script_build.yml
loop: "{{ groups[vsx] }}"
loop_control:
label: "{{ vsx_host }}: {{ inventory_hostname }}"
vars:
config_file: "{{ vsx_host }}.{{ inventory_hostname }}.clish"
config_dir: "vs_configs"
vsx_host: "{{ item }}"
...
Eventually it gets to a Jinja2 template that does the core work:
clish_script_build.yml:
...
...
- name: Generate CLISH script
ansible.builtin.template:
src: clish_cmd.j2
dest: "files/{{ config_dir }}/{{ config_file }}"
lstrip_blocks: true
delegate_to: localhost
...
...
# cat templates/clish_cmd.j2
{# VSX CLISH command #}
set virtual-system {{ hostvars[inventory_hostname]['vs_id'] }}
{{ clish_cmd }}
Send it over with put_file API:
- name: Copy CLISH script
check_point.gaia.cp_gaia_put_file:
file_name: "/home/admin/{{ config_dir }}/{{ config_file }}"
text_content: "{{ lookup('file', [ 'files', config_dir, config_file ] |join('/') ) }}\n"
override: true
delegate_to: "{{ vsx_host |default(inventory_hostname) }}"
Run it:
- name: Apply CLISH script
check_point.gaia.cp_gaia_run_script:
description: 'CLISH script: {{ config_file }}'
script: |
clish -c 'lock database override'
clish -c 'unlock database'
clish -f /home/admin/{{ config_dir }}/{{ config_file }}
wait_for_task: "{{ wait_for_api_task |default(true) }}"
delegate_to: "{{ vsx_host }}"
register: script_res
Granted, I use and abuse put_file and run_script API to do the dirty work. This helps (but does not eliminate) with the frustrating CLISH lock. You also can run your playbook with 'admin' user if you want, and either do ansible-vault for the password, or prompt for it. Or do other trickery.
I run this with a shell script:
./run_clish_command.sh -u admin_user_name -c 'show bgp peers' -l RTP_VS_1
The shell script uses 'getopts' to parse the variables and send to the playbook.
# ./run_clish_command.sh -u admin_user_name -c 'show bgp peers' -l RTP_VS_1
Vault password:
PLAY [Run CLISH command] *****************************************************************************************************************************
TASK [Run CLISH command on gateways] *****************************************************************************************************************
skipping: [RTP_VS_1]
TASK [Run CLISH command on VSX VS] *******************************************************************************************************************
included: /iac/playbooks/run_clish_command/vsx_clish_cmd.yml for RTP_VS_1
TASK [include_tasks] *********************************************************************************************************************************
included: /iac/playbooks/run_clish_command/clish_script_build.yml for RTP_VS_1 => (item=usdc2-gw1: RTP_VS_1)
included: /iac/playbooks/run_clish_command/clish_script_build.yml for RTP_VS_1 => (item=usdc2-gw2: RTP_VS_1)
included: /iac/playbooks/run_clish_command/clish_script_build.yml for RTP_VS_1 => (item=usdc2-gw3: RTP_VS_1)
...
..
...
TASK [Copy CLISH script] *****************************************************************************************************************************
changed: [RTP_VS_1 -> usdc2-gw3(192.0.2.113)]
TASK [include_tasks] *********************************************************************************************************************************
included: /iac/playbooks/run_clish_command/clish_script_apply.yml for RTP_VS_1
TASK [Apply CLISH script] ****************************************************************************************************************************
changed: [RTP_VS_1 -> usdc2-gw3(192.0.2.113)]
TASK [Check for run-time errors] *********************************************************************************************************************
skipping: [RTP_VS_1]
TASK [Save output] ***********************************************************************************************************************************
included: /iac/playbooks/run_clish_command/save_output.yml for RTP_VS_1
TASK [Parse output] **********************************************************************************************************************************
ok: [RTP_VS_1]
TASK [Show command output] ***************************************************************************************************************************
ok: [RTP_VS_1] => {
"msg": [
"Flags: R - Peer restarted, W - Waiting for End-Of-RIB from Peer",
"",
"PeerID AS Routes ActRts State InUpds OutUpds Uptime ",
"100.64.0.2 64950 0 0 Idle 0 0 00:00:00 ",
"100.64.0.3 64950 0 0 Idle 0 0 00:00:00 "
]
}
...
..
...
TASK [Copy CLISH script] *****************************************************************************************************************************
changed: [RTP_VS_1 -> usdc2-gw2(192.0.2.112)]
TASK [include_tasks] *********************************************************************************************************************************
included: /iac/playbooks/run_clish_command/clish_script_apply.yml for RTP_VS_1
TASK [Apply CLISH script] ****************************************************************************************************************************
changed: [RTP_VS_1 -> usdc2-gw2(192.0.2.112)]
TASK [Check for run-time errors] *********************************************************************************************************************
skipping: [RTP_VS_1]
TASK [Save output] ***********************************************************************************************************************************
included: /iac/playbooks/run_clish_command/save_output.yml for RTP_VS_1
TASK [Parse output] **********************************************************************************************************************************
ok: [RTP_VS_1]
TASK [Show command output] ***************************************************************************************************************************
ok: [RTP_VS_1] => {
"msg": [
"Flags: R - Peer restarted, W - Waiting for End-Of-RIB from Peer",
"",
"PeerID AS Routes ActRts State InUpds OutUpds Uptime ",
"100.64.0.2 64950 2399 2391 Established 7429 1 8w2d ",
"100.64.0.3 64950 2399 6 Established 7453 1 8w2d "
]
}
Anyhoo... yes, it's serial, because of the loop.
But, you can still run the Ansible host target against any VS, or all of them. 🙂 You can also see that I have a companion (very similar) playbook to do this for non-VSX gateways. Blast that all out in a playbook run, and I can pull "show bgp peers" for 150 different systems if I wanted.
Hope this helps. No I don't have this on a github, but I could be convinced...