<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic SSH to gateways with ansible in Ansible</title>
    <link>https://community.checkpoint.com/t5/Ansible/SSH-to-gateways-with-ansible/m-p/136658#M616</link>
    <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I can connect via ssh with the command ansible without playbook:&lt;/P&gt;&lt;P&gt;$ ansible all -i inventory -a "clish -c 'show version all'"&lt;BR /&gt;[WARNING]: Platform linux on host ckp-lab is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change&lt;BR /&gt;this. See &lt;A href="https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html" target="_blank"&gt;https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html&lt;/A&gt; for more information.&lt;BR /&gt;ckp-lab | CHANGED | rc=0 &amp;gt;&amp;gt;&lt;BR /&gt;Product version Check Point Gaia R80.40&lt;BR /&gt;OS build 294&lt;BR /&gt;OS kernel version 3.10.0-957.21.3cpx86_64&lt;BR /&gt;OS edition 64-bit&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when I try with ansible-playbook does not work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;$ ansible-playbook -i inventory ssh-test.yml&lt;/P&gt;&lt;P&gt;PLAY [My playbook] **************************************************************************************************************************************************************&lt;/P&gt;&lt;P&gt;TASK [Gathering Facts] **********************************************************************************************************************************************************&lt;BR /&gt;fatal: [ckp-lab]: FAILED! =&amp;gt; {"ansible_facts": {}, "changed": false, "failed_modules": {"setup": {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "exception": "Traceback (most recent call last):\r\n File \"/home/test/.ansible/tmp/ansible-tmp-1639752859.0839593-81645-52571446332867/AnsiballZ_setup.py\", line 102, in &amp;lt;module&amp;gt;\r\n _ansiballz_main()\r\n File \"/home/test/.ansible/tmp/ansible-tmp-1639752859.0839593-81645-52571446332867/AnsiballZ_setup.py\", line 94, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File \"/home/test/.ansible/tmp/ansible-tmp-1639752859.0839593-81645-52571446332867/AnsiballZ_setup.py\", line 40, in invoke_module\r\n runpy.run_module(mod_name='ansible.modules.system.setup', init_globals=None, run_name='__main__', alter_sys=True)\r\n File \"/opt/CPsuite-R80.40/fw1/Python/lib/python2.7/runpy.py\", line 188, in run_module\r\n fname, loader, pkg_name)\r\n File \"/opt/CPsuite-R80.40/fw1/Python/lib/python2.7/runpy.py\", line 82, in _run_module_code\r\n mod_name, mod_fname, mod_loader, pkg_name)\r\n File \"/opt/CPsuite-R80.40/fw1/Python/lib/python2.7/runpy.py\", line 72, in _run_code\r\n exec code in run_globals\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/modules/system/setup.py\", line 136, in &amp;lt;module&amp;gt;\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/module_utils/facts/__init__.py\", line 34, in &amp;lt;module&amp;gt;\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/module_utils/facts/compat.py\", line 33, in &amp;lt;module&amp;gt;\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/module_utils/facts/default_collectors.py\", line 51, in &amp;lt;module&amp;gt;\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/module_utils/facts/system/service_mgr.py\", line 35, in &amp;lt;module&amp;gt;\r\nImportError: No module named distutils.version\r\n", "failed": true, "module_stderr": "Shared connection to 192.168.251.220 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n File \"/home/test/.ansible/tmp/ansible-tmp-1639752859.0839593-81645-52571446332867/AnsiballZ_setup.py\", line 102, in &amp;lt;module&amp;gt;\r\n _ansiballz_main()\r\n File \"/home/test/.ansible/tmp/ansible-tmp-1639752859.0839593-81645-52571446332867/AnsiballZ_setup.py\", line 94, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File \"/home/test/.ansible/tmp/ansible-tmp-1639752859.0839593-81645-52571446332867/AnsiballZ_setup.py\", line 40, in invoke_module\r\n runpy.run_module(mod_name='ansible.modules.system.setup', init_globals=None, run_name='__main__', alter_sys=True)\r\n File \"/opt/CPsuite-R80.40/fw1/Python/lib/python2.7/runpy.py\", line 188, in run_module\r\n fname, loader, pkg_name)\r\n File \"/opt/CPsuite-R80.40/fw1/Python/lib/python2.7/runpy.py\", line 82, in _run_module_code\r\n mod_name, mod_fname, mod_loader, pkg_name)\r\n File \"/opt/CPsuite-R80.40/fw1/Python/lib/python2.7/runpy.py\", line 72, in _run_code\r\n exec code in run_globals\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/modules/system/setup.py\", line 136, in &amp;lt;module&amp;gt;\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/module_utils/facts/__init__.py\", line 34, in &amp;lt;module&amp;gt;\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/module_utils/facts/compat.py\", line 33, in &amp;lt;module&amp;gt;\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/module_utils/facts/default_collectors.py\", line 51, in &amp;lt;module&amp;gt;\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/module_utils/facts/system/service_mgr.py\", line 35, in &amp;lt;module&amp;gt;\r\nImportError: No module named distutils.version\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1, "warnings": ["Platform linux on host ckp-lab is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See &lt;A href="https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html" target="_blank"&gt;https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html&lt;/A&gt; for more information."]}}, "msg": "The following modules failed to execute: setup\n"}&lt;/P&gt;&lt;P&gt;PLAY RECAP **********************************************************************************************************************************************************************&lt;BR /&gt;ckp-lab : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;playbook:&lt;/P&gt;&lt;P&gt;more ssh-test.yml&lt;BR /&gt;---&lt;BR /&gt;- name: My playbook&lt;BR /&gt;hosts: all&lt;BR /&gt;tasks:&lt;BR /&gt;- name: show version&lt;BR /&gt;command: "clish -c 'show version all'"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do someone knows what I am doing wrong?&lt;/P&gt;&lt;P&gt;Thank you in advance! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 17 Dec 2021 14:57:11 GMT</pubDate>
    <dc:creator>Cesc</dc:creator>
    <dc:date>2021-12-17T14:57:11Z</dc:date>
    <item>
      <title>SSH to gateways with ansible</title>
      <link>https://community.checkpoint.com/t5/Ansible/SSH-to-gateways-with-ansible/m-p/136658#M616</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I can connect via ssh with the command ansible without playbook:&lt;/P&gt;&lt;P&gt;$ ansible all -i inventory -a "clish -c 'show version all'"&lt;BR /&gt;[WARNING]: Platform linux on host ckp-lab is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change&lt;BR /&gt;this. See &lt;A href="https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html" target="_blank"&gt;https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html&lt;/A&gt; for more information.&lt;BR /&gt;ckp-lab | CHANGED | rc=0 &amp;gt;&amp;gt;&lt;BR /&gt;Product version Check Point Gaia R80.40&lt;BR /&gt;OS build 294&lt;BR /&gt;OS kernel version 3.10.0-957.21.3cpx86_64&lt;BR /&gt;OS edition 64-bit&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when I try with ansible-playbook does not work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;$ ansible-playbook -i inventory ssh-test.yml&lt;/P&gt;&lt;P&gt;PLAY [My playbook] **************************************************************************************************************************************************************&lt;/P&gt;&lt;P&gt;TASK [Gathering Facts] **********************************************************************************************************************************************************&lt;BR /&gt;fatal: [ckp-lab]: FAILED! =&amp;gt; {"ansible_facts": {}, "changed": false, "failed_modules": {"setup": {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "exception": "Traceback (most recent call last):\r\n File \"/home/test/.ansible/tmp/ansible-tmp-1639752859.0839593-81645-52571446332867/AnsiballZ_setup.py\", line 102, in &amp;lt;module&amp;gt;\r\n _ansiballz_main()\r\n File \"/home/test/.ansible/tmp/ansible-tmp-1639752859.0839593-81645-52571446332867/AnsiballZ_setup.py\", line 94, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File \"/home/test/.ansible/tmp/ansible-tmp-1639752859.0839593-81645-52571446332867/AnsiballZ_setup.py\", line 40, in invoke_module\r\n runpy.run_module(mod_name='ansible.modules.system.setup', init_globals=None, run_name='__main__', alter_sys=True)\r\n File \"/opt/CPsuite-R80.40/fw1/Python/lib/python2.7/runpy.py\", line 188, in run_module\r\n fname, loader, pkg_name)\r\n File \"/opt/CPsuite-R80.40/fw1/Python/lib/python2.7/runpy.py\", line 82, in _run_module_code\r\n mod_name, mod_fname, mod_loader, pkg_name)\r\n File \"/opt/CPsuite-R80.40/fw1/Python/lib/python2.7/runpy.py\", line 72, in _run_code\r\n exec code in run_globals\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/modules/system/setup.py\", line 136, in &amp;lt;module&amp;gt;\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/module_utils/facts/__init__.py\", line 34, in &amp;lt;module&amp;gt;\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/module_utils/facts/compat.py\", line 33, in &amp;lt;module&amp;gt;\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/module_utils/facts/default_collectors.py\", line 51, in &amp;lt;module&amp;gt;\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/module_utils/facts/system/service_mgr.py\", line 35, in &amp;lt;module&amp;gt;\r\nImportError: No module named distutils.version\r\n", "failed": true, "module_stderr": "Shared connection to 192.168.251.220 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n File \"/home/test/.ansible/tmp/ansible-tmp-1639752859.0839593-81645-52571446332867/AnsiballZ_setup.py\", line 102, in &amp;lt;module&amp;gt;\r\n _ansiballz_main()\r\n File \"/home/test/.ansible/tmp/ansible-tmp-1639752859.0839593-81645-52571446332867/AnsiballZ_setup.py\", line 94, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File \"/home/test/.ansible/tmp/ansible-tmp-1639752859.0839593-81645-52571446332867/AnsiballZ_setup.py\", line 40, in invoke_module\r\n runpy.run_module(mod_name='ansible.modules.system.setup', init_globals=None, run_name='__main__', alter_sys=True)\r\n File \"/opt/CPsuite-R80.40/fw1/Python/lib/python2.7/runpy.py\", line 188, in run_module\r\n fname, loader, pkg_name)\r\n File \"/opt/CPsuite-R80.40/fw1/Python/lib/python2.7/runpy.py\", line 82, in _run_module_code\r\n mod_name, mod_fname, mod_loader, pkg_name)\r\n File \"/opt/CPsuite-R80.40/fw1/Python/lib/python2.7/runpy.py\", line 72, in _run_code\r\n exec code in run_globals\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/modules/system/setup.py\", line 136, in &amp;lt;module&amp;gt;\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/module_utils/facts/__init__.py\", line 34, in &amp;lt;module&amp;gt;\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/module_utils/facts/compat.py\", line 33, in &amp;lt;module&amp;gt;\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/module_utils/facts/default_collectors.py\", line 51, in &amp;lt;module&amp;gt;\r\n File \"/tmp/ansible_setup_payload_LAX3Ae/ansible_setup_payload.zip/ansible/module_utils/facts/system/service_mgr.py\", line 35, in &amp;lt;module&amp;gt;\r\nImportError: No module named distutils.version\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1, "warnings": ["Platform linux on host ckp-lab is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See &lt;A href="https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html" target="_blank"&gt;https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html&lt;/A&gt; for more information."]}}, "msg": "The following modules failed to execute: setup\n"}&lt;/P&gt;&lt;P&gt;PLAY RECAP **********************************************************************************************************************************************************************&lt;BR /&gt;ckp-lab : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;playbook:&lt;/P&gt;&lt;P&gt;more ssh-test.yml&lt;BR /&gt;---&lt;BR /&gt;- name: My playbook&lt;BR /&gt;hosts: all&lt;BR /&gt;tasks:&lt;BR /&gt;- name: show version&lt;BR /&gt;command: "clish -c 'show version all'"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do someone knows what I am doing wrong?&lt;/P&gt;&lt;P&gt;Thank you in advance! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Dec 2021 14:57:11 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Ansible/SSH-to-gateways-with-ansible/m-p/136658#M616</guid>
      <dc:creator>Cesc</dc:creator>
      <dc:date>2021-12-17T14:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: SSH to gateways with ansible</title>
      <link>https://community.checkpoint.com/t5/Ansible/SSH-to-gateways-with-ansible/m-p/136909#M617</link>
      <description>&lt;P&gt;Hi Cesc,&lt;/P&gt;
&lt;P&gt;That's a really long and messy error message but basically it means that the host you're connecting to can't run the Ansible Python module that gets transferred and executed automatically. You should be fine with the CP Ansible modules which use the HTTP API, raw and possibly shell commands with Ansible, but the Python setup on Gaia is hardened so doesn't include the necessary modules for Ansible.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 10:17:17 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Ansible/SSH-to-gateways-with-ansible/m-p/136909#M617</guid>
      <dc:creator>StuartGreen</dc:creator>
      <dc:date>2021-12-21T10:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: SSH to gateways with ansible</title>
      <link>https://community.checkpoint.com/t5/Ansible/SSH-to-gateways-with-ansible/m-p/136935#M618</link>
      <description>&lt;P&gt;There are a couple of issues: One, you are running with &lt;EM&gt;gather_facts = True&lt;/EM&gt;, which is default state in Ansible for Playbooks. you ran ad-hoc command, which executes just the command/module you ask for. CHKP GW does not have default gathering stats over SSH, but we do have a module for that which we execute over HTTPAPI Plugin. Solution: Either add&amp;nbsp;&lt;EM&gt;gather_facts: false&lt;/EM&gt; to the playbook, or disable in the &lt;EM&gt;ansible.cfg&lt;/EM&gt; file globally (/etc/ansible/ansible.cfg) or locally to either the project (playbook location) or your home directory (~). Under section &lt;EM&gt;[defaults]&lt;/EM&gt; add&amp;nbsp;&lt;EM&gt;gathering = explicit .&amp;nbsp;&lt;/EM&gt;Look at the Ansible variables precedence on their Docs page&lt;EM&gt;.&amp;nbsp;&lt;/EM&gt;In general, don't collect facts of systems, unless you need to use those somewhere for whatever (conditional) reason.&lt;BR /&gt;Second, our CHKP Gaia does not carry &lt;EM&gt;distutils&lt;/EM&gt; python package. That is why it fails execution. Ansible needs it to package up and execute gathering facts on the host.&lt;BR /&gt;When you are working with SSH sessions to manage hosts, use &lt;EM&gt;pipelining = True&lt;/EM&gt; in your ansible config (look at the explanation in the main ansible.cfg file). For SSH connections, always use&amp;nbsp;&lt;EM&gt;pipelining&lt;/EM&gt;&lt;EM&gt; = True &lt;/EM&gt;unless you have issues with compatibility. That helps with a lot quicker execution of tasks over SSH.&lt;/P&gt;
&lt;P&gt;Here is my &lt;EM&gt;.ansible.cfg&lt;/EM&gt; in my project directory:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;[defaults]
inventory = inventory.ini
gathering = explicit
interpreter_python = /usr/bin/python3
callback_whitelist = timer

[ssh_connection]
pipelining = True
host_key_checking = False
control_path_dir = ~/.ansible/cp&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my inventory:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;[chkp]
chkp-gw ansbile_host=10.10.12.1 ansible_user=admin&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my playbook:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;---
- name: test ssh to chkp group
  hosts: chkp
  vars_prompt:
    - name: ansible_password
      prompt: Enter password
      unsafe: yes
      private: yes
  tasks:
  - name: show version
    command: clish -c 'show version all'
    register: result

  - debug: var=result.stdout_lines
...&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run playbook:&lt;BR /&gt;$ ansible-playbook test.yml&lt;/P&gt;
&lt;P&gt;Now, you can use the prompt in the playbook to force and ask for the password for the&amp;nbsp;&lt;EM&gt;ansible_password&lt;/EM&gt; variable (you don't want to hard-code that in the inventory or the playbook), you can skip that and call the playbook with&amp;nbsp;&lt;EM&gt;--ask-pass&lt;/EM&gt;, or best is to copy your SSH public key to the managed host with&amp;nbsp;&lt;EM&gt;$ ssh-copy-id admin@10.10.12.1&lt;/EM&gt;, and not use any password at all, which is highly recommended. You can of course encrypt with Ansible Vault a variable file, but that is another topic (Google for that). If you go the PKI route, don't forget to add&amp;nbsp;&lt;EM&gt;ansible_ssh_private_key_file=&amp;lt;path_to_private_key&amp;gt;&lt;/EM&gt; in either the playbook or directly into the&amp;nbsp;inventory file for that host or group of hosts.&lt;/P&gt;
&lt;P&gt;That should help. Have fun on the automation side!&lt;BR /&gt;PS: Look at using the HTTPAPI Plugin for managing CHKP GWs (Gaia or Passthrough over MGMT) and MGMT servers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;BR /&gt;Arturas Zalenekas&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 21:14:55 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Ansible/SSH-to-gateways-with-ansible/m-p/136935#M618</guid>
      <dc:creator>Art_Zalenekas</dc:creator>
      <dc:date>2021-12-21T21:14:55Z</dc:date>
    </item>
  </channel>
</rss>

