Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
ukohae
Contributor
Jump to solution

Using Run-Script with Ansible

Hi, I am trying to use Run-Script module. Below is my code

 

---
- hosts: check_point
  connection: httpapi
  gather_facts: False
  vars_files:
    - 'credentials/ansible_login_information.yml'
  tasks:
  - name: run-script
    check_point.mgmt.cp_mgmt_run_script:
      script: ./stat.sh
      script_name: 'Check stat'
      targets:
      - Some_Server
      wait_for_task_timeout: 30

 


shell script

 

#!/bin/bash
cpstat os -f all

 

 TASK [run-script] ******************************************************************************************************************************************
fatal: [check_point]: FAILED! => {"changed": false, "msg": "Task Some_Server - Check stat with task id af3660dc-9e23-4a90-a398-6d54357a failed. Look at the logs for more details"}


I  noticed this playbook is not running my script. What can I do to fix this erroor

0 Kudos
1 Solution

Accepted Solutions
masher
Employee
Employee

My only guess regarding the SIC error is that the target definition isn't reachable or hasn't been fully configured yet.

The run-script will not copy a script from the local directory and deploy it to a remote deployment for use. You need to insert the body of the script into the "script" command before running it from the management API.

From https://github.com/CheckPointSW/CheckPointAnsibleMgmtCollection/blob/master/plugins/modules/checkpoi...

 

 

  script:
    description:
    - Script body contents.
    type: str
    required: true

 

 

This mirrors the run-script API documentation.

- https://sc1.checkpoint.com/documents/latest/APIs/index.html#cli/run-script~v1.7%20

I haven't run this in my lab, so this might not provide the results. However, I would expect it to look similar to below.

 

 

---
- hosts: check_point
  connection: httpapi
  gather_facts: False
  vars_files:
    - 'credentials/ansible_login_information.yml'
  tasks:
  - name: run-script
    check_point.mgmt.cp_mgmt_run_script:
      script: "cpstat os -f all"
      script_name: 'Check stat'
      targets:
      - deployed-gw-1
      wait_for_task_timeout: 30

 

EDIT: One other thing I didn't mention is that you'll need to query the task-id from the run-script command to see the results for this particular playbook.

 

View solution in original post

0 Kudos
3 Replies
PhoneBoy
Admin
Admin

Try specifying the full path to the script.
If not, I recommend checking the task status in SmartConsole to see what it says.

0 Kudos
ukohae
Contributor

The shell script is in the same directory as the playbook.

Error message on SmartConsole

Run One Time Script

Results ..............................................................
Task Results Connection failed for 192.1.1.1
             Make sure that the machine is up and running, and that  
             SIC has been established

Details ..............................................................
Script  ./stat.sh


Connection failed for IP Address

Makes sure that the machine is up and running, and that SIC has been established

 

0 Kudos
masher
Employee
Employee

My only guess regarding the SIC error is that the target definition isn't reachable or hasn't been fully configured yet.

The run-script will not copy a script from the local directory and deploy it to a remote deployment for use. You need to insert the body of the script into the "script" command before running it from the management API.

From https://github.com/CheckPointSW/CheckPointAnsibleMgmtCollection/blob/master/plugins/modules/checkpoi...

 

 

  script:
    description:
    - Script body contents.
    type: str
    required: true

 

 

This mirrors the run-script API documentation.

- https://sc1.checkpoint.com/documents/latest/APIs/index.html#cli/run-script~v1.7%20

I haven't run this in my lab, so this might not provide the results. However, I would expect it to look similar to below.

 

 

---
- hosts: check_point
  connection: httpapi
  gather_facts: False
  vars_files:
    - 'credentials/ansible_login_information.yml'
  tasks:
  - name: run-script
    check_point.mgmt.cp_mgmt_run_script:
      script: "cpstat os -f all"
      script_name: 'Check stat'
      targets:
      - deployed-gw-1
      wait_for_task_timeout: 30

 

EDIT: One other thing I didn't mention is that you'll need to query the task-id from the run-script command to see the results for this particular playbook.

 

0 Kudos
Upcoming Events

    CheckMates Events