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