Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
Yevgeniy_Yeryom
Contributor

cpAnsible installation on Ubuntu 16.04 

Hi guys,

 

I am installing Ansible with CheckPoint module in my lab (on Ubuntu 16.04.01) according to the guide from:  

https://github.com/CheckPointSW/cpAnsible

 

I installed the Ansible 2.0.0.2 from Ubuntu repository.

 

I am getting following error.

TASK [login] *******************************************************************

task path: /home/yevgeniy/ansible/cpx_add_host.yml:4

fatal: [127.0.0.1]: FAILED! => {"failed": true, "msg": "ERROR! error importing module in /usr/share/my_modules/check_point_mgmt/check_point_mgmt.py, expecting format like 'from ansible.module_utils.basic import *'"}

 

The error comes from:

yevgeniy@kubuntu-desktop:/usr/share/my_modules/check_point_mgmt$ pwd

/usr/share/my_modules/check_point_mgmt

yevgeniy@kubuntu-desktop:/usr/share/my_modules/check_point_mgmt$ ls -al

-rw-r--r-- 1 root root 10115 Sep 13 17:31 check_point_mgmt.py

cat check_point_mgmt.py

#!/usr/bin/python

import ast

import json

import sys

from ansible.module_utils.basic import AnsibleModule

 

The file and object are exist:

yevgeniy@kubuntu-desktop:/usr/lib/python2.7/dist-packages$ pwd

/usr/lib/python2.7/dist-packages

yevgeniy@kubuntu-desktop:/usr/lib/python2.7/dist-packages$

yevgeniy@kubuntu-desktop:/usr/lib/python2.7/dist-packages$ cat ansible/module_utils/basic.py | grep AnsibleModule

class AnsibleModule(object):

 

 

Below is the configuration and playbook.

I would very appreciate your feedback.

 

 

 

 

 

/etc/ansible/hosts

[localhost]

127.0.0.1

[localhost:vars]

ansible_user=yevgeniy

ansible_ssh_pass=qwe123

ansible_python_interpreter=/usr/bin/python2.7

# Optional (variables detailing the Check Point's management server access):

mgmt_server=192.168.168.50

mgmt_user=admin

mgmt_password=qwe123

 

 

/etc/ansible/ansible.cfg

[defaults]

#inventory      = /etc/ansible/hosts

library        = /usr/share/my_modules/

host_key_checking = False

 

Playbook

yevgeniy@kubuntu-desktop:~/ansible$ cat cpx_add_host.yml

---

- hosts: "localhost"

  tasks:

  - name: "login"

    check_point_mgmt:

      command: login

      parameters:

        username: "{{mgmt_user}}"

        password: "{{mgmt_password}}"

        management: "{{mgmt_server}}"

      fingerprint: "FA:5A:A6:AC:93:D0:BD:69:9E:E1:72:05:1D:73:24:70:29:17:37:C1"

    register: login_response

 

  - name: "add-host-cpx-host1"

    check_point_mgmt:

      command: add-host

      parameters:

        name: "cpx-host1"

        ip-address: "192.168.202.100"

      session-data: "{{login_response}}"

 

  - name: "publish"

    check_point_mgmt:

      command: publish

      session-data: "{{login_response}}"

 

  - name: "logout"

    check_point_mgmt:

      command: logout

      session-data: "{{login_response}}"

 

 

 

yevgeniy@kubuntu-desktop:~/ansible$ sudo ansible-playbook cpx_add_host.yml -vvvvv

Using /etc/ansible/ansible.cfg as config file

Loaded callback default of type stdout, v2.0

1 plays in cpx_add_host.yml

 

PLAY ***************************************************************************

 

TASK [setup] *******************************************************************

<127.0.0.1> ESTABLISH SSH CONNECTION FOR USER: yevgeniy

<127.0.0.1> SSH: ansible.cfg set ssh_args: (-o)(ControlMaster=auto)(-o)(ControlPersist=60s)

<127.0.0.1> SSH: ANSIBLE_HOST_KEY_CHECKING/host_key_checking disabled: (-o)(StrictHostKeyChecking=no)

<127.0.0.1> SSH: ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u set: (-o)(User=yevgeniy)

<127.0.0.1> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=10)

<127.0.0.1> SSH: PlayContext set ssh_common_args: ()

<127.0.0.1> SSH: PlayContext set ssh_extra_args: ()

<127.0.0.1> SSH: found only ControlPersist; added ControlPath: (-o)(ControlPath=/home/yevgeniy/.ansible/cp/ansible-ssh-%h-%p-%r)

<127.0.0.1> SSH: EXEC sshpass -d14 ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=yevgeniy -o ConnectTimeout=10 -o ControlPath=/home/yevgeniy/.ansible/cp/ansible-ssh-%h-%p-%r -tt 127.0.0.1 '( umask 22 && mkdir -p "$( echo $HOME/.ansible/tmp/ansible-tmp-1536847648.88-30557354590131 )" && echo "$( echo $HOME/.ansible/tmp/ansible-tmp-1536847648.88-30557354590131 )" )'

<127.0.0.1> PUT /tmp/tmpJ04k4u TO /home/yevgeniy/.ansible/tmp/ansible-tmp-1536847648.88-30557354590131/setup

<127.0.0.1> SSH: ansible.cfg set ssh_args: (-o)(ControlMaster=auto)(-o)(ControlPersist=60s)

<127.0.0.1> SSH: ANSIBLE_HOST_KEY_CHECKING/host_key_checking disabled: (-o)(StrictHostKeyChecking=no)

<127.0.0.1> SSH: ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u set: (-o)(User=yevgeniy)

<127.0.0.1> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=10)

<127.0.0.1> SSH: PlayContext set ssh_common_args: ()

<127.0.0.1> SSH: PlayContext set sftp_extra_args: ()

<127.0.0.1> SSH: found only ControlPersist; added ControlPath: (-o)(ControlPath=/home/yevgeniy/.ansible/cp/ansible-ssh-%h-%p-%r)

<127.0.0.1> SSH: EXEC sshpass -d14 sftp -b - -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=yevgeniy -o ConnectTimeout=10 -o ControlPath=/home/yevgeniy/.ansible/cp/ansible-ssh-%h-%p-%r '[127.0.0.1]'

<127.0.0.1> ESTABLISH SSH CONNECTION FOR USER: yevgeniy

<127.0.0.1> SSH: ansible.cfg set ssh_args: (-o)(ControlMaster=auto)(-o)(ControlPersist=60s)

<127.0.0.1> SSH: ANSIBLE_HOST_KEY_CHECKING/host_key_checking disabled: (-o)(StrictHostKeyChecking=no)

<127.0.0.1> SSH: ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u set: (-o)(User=yevgeniy)

<127.0.0.1> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=10)

<127.0.0.1> SSH: PlayContext set ssh_common_args: ()

<127.0.0.1> SSH: PlayContext set ssh_extra_args: ()

<127.0.0.1> SSH: found only ControlPersist; added ControlPath: (-o)(ControlPath=/home/yevgeniy/.ansible/cp/ansible-ssh-%h-%p-%r)

<127.0.0.1> SSH: EXEC sshpass -d14 ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=yevgeniy -o ConnectTimeout=10 -o ControlPath=/home/yevgeniy/.ansible/cp/ansible-ssh-%h-%p-%r -tt 127.0.0.1 'LANG=de_DE.UTF-8 LC_ALL=de_DE.UTF-8 LC_MESSAGES=de_DE.UTF-8 /usr/bin/python2.7 /home/yevgeniy/.ansible/tmp/ansible-tmp-1536847648.88-30557354590131/setup; rm -rf "/home/yevgeniy/.ansible/tmp/ansible-tmp-1536847648.88-30557354590131/" > /dev/null 2>&1'

ok: [127.0.0.1]

 

TASK [login] *******************************************************************

task path: /home/yevgeniy/ansible/cpx_add_host.yml:4

fatal: [127.0.0.1]: FAILED! => {"failed": true, "msg": "ERROR! error importing module in /usr/share/my_modules/check_point_mgmt/check_point_mgmt.py, expecting format like 'from ansible.module_utils.basic import *'"}

 

PLAY RECAP *********************************************************************

127.0.0.1                  : ok=1    changed=0    unreachable=0    failed=1

 

yevgeniy@kubuntu-desktop:~/ansible$

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Mit freundlichen Grüßen / Best regards

 

Yevgeniy Yeryomin | Professional Services Consultant
Check Point Software Technologies
| M +49 151 4401 9871 | * yyeryomin@checkpoint.com

Advanced Technical Account Manager | Learn More  

4 Replies
Joe_Dillig
Employee Alumnus
Employee Alumnus

Yevgeniy,

I install Ansible on Ubuntu 16.04 quite a lot so i created this script to install Ansible 2.6.X and also download and place the Check Point Ansible libs in the proper locations. If you run this on an existing installation it will upgrade Ansible to 2.6.X version. Maybe this will help you out!

#Add Updated Ansible Repo
sudo apt-add-repository -y ppa:ansible/ansible
sudo apt-get update
sudo apt-get install -y ansible python-pip

#Clone Check Point Ansible libs
git clone --recursive https://github.com/CheckPoint-APIs-Team/cpAnsible
sudo cp -r cpAnsible/check_point_mgmt/ /usr/lib/python2.7/dist-packages/ansible/
sudo cp -r cpAnsible/check_point_mgmt/cp_mgmt_api_python_sdk/ /usr/lib/python2.7/dist-packages/

sudo mkdir -p $HOME/.ansible/plugins/modules
sudo cp -r cpAnsible/check_point_mgmt/ $HOME/.ansible/plugins/modules/

Yevgeniy_Yeryom
Contributor

Hello Joe, 

thanks for your instructions I managed to start ansible to work for me with the Multi-Domain Management in my lab. Smiley Happy 

According to your recommendations, 

- I updated repository and ansible. 

- Then I copied the check_point_mgmt/ to /usr/lib/python2.7/dist-packages/ansible/. 

It was in /usr/lib/python2.7/dist-packages/ before. 

Thanks a lot!

Harshpal_Bhati
Employee
Employee

i am hinting similar issue :

root@HP-ANSIBLE:/home/harshpal# vi /etc/ansible/hosts
root@HP-ANSIBLE:/home/harshpal# vi /etc/ansible/hosts
root@HP-ANSIBLE:/home/harshpal# ansible-playbook cpx_add_host.yml

PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [127.0.0.1]

TASK [login] *******************************************************************
fatal: [127.0.0.1]: FAILED! => {"failed": true, "msg": "ERROR! error importing module in /usr/lib/python2.7/dist-packages/ansible/check_point_mgmt/check_point_mgmt.py, expecting format like 'from ansible.module_utils.basic import *'"}

Any suggestion ?

Bryan_Lee
Employee Alumnus
Employee Alumnus

For lab purpose I downloaded the image from turnkey hub, save me the hassle with linux, ansible and python installation. Works fine for me.

https://www.turnkeylinux.org/ansible 

0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events