<?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 Re: Ansible with api-key in API / CLI Discussion</title>
    <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Ansible-with-api-key/m-p/161166#M7254</link>
    <description>&lt;P&gt;this feels a little like a weird problem I encountered recently where ansible wasn't sending the domain parameter in the login request. The 'solution' (which I'm not 100% convinced is actually addressing the root of the problem) was to roll back to the previous version of ansible-core (2.13.3 worked for me, 2.13.4 did not - but with a completely different user on the same Ubuntu host both versions worked).&lt;/P&gt;</description>
    <pubDate>Thu, 03 Nov 2022 15:40:13 GMT</pubDate>
    <dc:creator>StuartGreen</dc:creator>
    <dc:date>2022-11-03T15:40:13Z</dc:date>
    <item>
      <title>Ansible with api-key</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Ansible-with-api-key/m-p/161001#M7246</link>
      <description>&lt;P&gt;Hello CheckMates,&lt;/P&gt;&lt;P&gt;Because I haven't found an answer in google, and here using search .. I decided to ask you about this.&lt;BR /&gt;I was wondering if it's possible to use api-key authorization with ansible ?&lt;/P&gt;&lt;P&gt;As we all know configuration in file /etc/ansible/hosts looks like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[check_point]
10.0.0.1
[check_point:vars]
ansible_httpapi_use_ssl=True
ansible_httpapi_validate_certs=False
ansible_user=apiuser
ansible_password=s3cr3tp4$$word
ansible_network_os=check_point.mgmt.checkpoint&lt;/LI-CODE&gt;&lt;P&gt;But....&lt;BR /&gt;How much prettier it would be if we could use instead of &lt;STRONG&gt;ansible_user + ansible_password&lt;/STRONG&gt; ... something like &lt;STRONG&gt;ansible_api_key&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;I haven't found that it is possible ... but maybe someone else thought about this aswell and ... just maybe there is a way ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;--&lt;BR /&gt;Best&lt;BR /&gt;Marcin&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 09:07:46 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Ansible-with-api-key/m-p/161001#M7246</guid>
      <dc:creator>marcyn</dc:creator>
      <dc:date>2022-11-02T09:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible with api-key</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Ansible-with-api-key/m-p/161038#M7247</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.checkpoint.com/t5/user/viewprofilepage/user-id/78158"&gt;@marcyn&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes,&amp;nbsp;&lt;SPAN&gt;it's possible to use api-key authorization with ansible.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Replace&amp;nbsp;&lt;STRONG&gt;ansible_user + ansible_password&lt;/STRONG&gt;&amp;nbsp;with&amp;nbsp;&lt;STRONG&gt;ansible_api_key&lt;/STRONG&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Omer&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 15:15:31 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Ansible-with-api-key/m-p/161038#M7247</guid>
      <dc:creator>Omer_Kleinstern</dc:creator>
      <dc:date>2022-11-02T15:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible with api-key</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Ansible-with-api-key/m-p/161043#M7248</link>
      <description>&lt;P&gt;Hi Omer,&lt;/P&gt;&lt;P&gt;Ah ... if that would be so easy... I already tried that, of course &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[check_point]
10.0.0.1
[check_point:vars]
ansible_httpapi_use_ssl=True
ansible_httpapi_validate_certs=False
#ansible_user=apiuser
#ansible_password=qwerty123
ansible_api_key=yfD6ETO+ywCRwaoDxIUkTQ==
ansible_network_os=check_point.mgmt.checkpoint&lt;/LI-CODE&gt;&lt;P&gt;And the result:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# ansible-playbook playbook_add.yaml
PLAY [playbook] ************************************************************************************************************************************
TASK [Gathering Facts] *****************************************************************************************************************************ok: [10.0.0.1]

TASK [add host] ************************************************************************************************************************************An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.module_utils.connection.ConnectionError: 'Connection' object has no attribute '_session_uid'
(...)
PLAY RECAP *****************************************************************************************************************************************10.0.0.1
: ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are wondering if this api-key is valid ... here, take a look:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;mgmt_cli --api-key "yfD6ETO+ywCRwaoDxIUkTQ==" -m 10.0.0.1 login
uid: "96259ea1-d710-422f-ba2f-b02bbe196489"
sid: "nF4D-VqA1h7J4vUIeM1gwSAARt7lQI52kdnvr6whesg"
url: "https://10.0.0.1:443/web_api"
session-timeout: 600
last-login-was-at:
  posix: 1666349488319
  iso-8601: "2022-10-21T12:51+0200"
api-server-version: "1.8"
user-name: "api"
user-uid: "dc0b1c70-5b38-4443-9e8c-0c42850c468d"&lt;/LI-CODE&gt;&lt;P&gt;So yes ... it's valid &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;&lt;P&gt;So again .. if it would be so easy ... I wouldn't probably ask.&lt;BR /&gt;But maybe I'm doing something wrong ?&lt;/P&gt;&lt;P&gt;--&lt;BR /&gt;Best&lt;BR /&gt;Marcin&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 15:35:12 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Ansible-with-api-key/m-p/161043#M7248</guid>
      <dc:creator>marcyn</dc:creator>
      <dc:date>2022-11-02T15:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible with api-key</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Ansible-with-api-key/m-p/161047#M7249</link>
      <description>&lt;P&gt;It's definitely supported and works fine. Which module version are you using? You can see it mentioned in the plugin here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/CheckPointSW/CheckPointAnsibleMgmtCollection/blob/a05cb3f66ca703234db64ff1898e0422b9f4297f/plugins/httpapi/checkpoint.py#L24" target="_blank"&gt;https://github.com/CheckPointSW/CheckPointAnsibleMgmtCollection/blob/a05cb3f66ca703234db64ff1898e0422b9f4297f/plugins/httpapi/checkpoint.py#L24&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make sure you're not sending a username and password somewhere else in your play as an additional variable as that will cause the plugin to ignore the API key.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 15:48:36 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Ansible-with-api-key/m-p/161047#M7249</guid>
      <dc:creator>StuartGreen</dc:creator>
      <dc:date>2022-11-02T15:48:36Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible with api-key</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Ansible-with-api-key/m-p/161052#M7250</link>
      <description>&lt;P&gt;Hi Stuart,&lt;/P&gt;&lt;P&gt;Yes, I've already seen this site that you just mentioned... and it looks as if it should be supported ... but it doesn't work for me.&lt;BR /&gt;I have the newest ansible and the newest checkpoint module:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# ansible --version
ansible [core 2.12.9]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
  jinja version = 2.11.3
  libyaml = True

# head .ansible/collections/ansible_collections/check_point/mgmt/CHANGELOG.rst
==============================
Check_Point.Mgmt Release Notes
==============================
.. contents:: Topics

v4.0.0
======&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And of course when I change /etc/ansible/hosts to use &lt;STRONG&gt;ansible_api_key&lt;/STRONG&gt; ... I also comment out/remove &lt;STRONG&gt;ansible_user + ansible_password&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;What's funny is that when I have this &lt;STRONG&gt;ansible_api_key&lt;/STRONG&gt; in /etc/ansible/hosts it works "strange" because ansible starts with "logout" command &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;&lt;LI-CODE lang="markup"&gt;# tail -f $FWDIR/log/api.elg
2022-11-02 17:00:58,049  INFO org.apache.cxf.interceptor.LoggingInInterceptor.log:250 [qtp1587849480-90] - Inbound Message
----------------------------
ID: 12199
Address: http://127.0.0.1:65456/web_api/logout
Encoding: UTF-8
Http-Method: POST
Content-Type: application/json
Headers: {accept-encoding=[identity], connection=[keep-alive], Content-Length=[2], content-type=[application/json], Host=[127.0.0.1:65456], User-Agent=[Ansible], X-Forwarded-For=[172.19.99.100], X-Forwarded-Host=[172.19.99.253:443], X-Forwarded-Host-Port=[443], X-Forwarded-Server=[172.19.99.253]}
Payload: {}
--------------------------------------
2022-11-02 17:00:58,049 ERROR com.checkpoint.management.web_api.core.cxf.interceptor.WebApiInInterceptorSessionValidator.handleMessage:31 [qtp1587849480-90] - Session validation has failed
(...)
ID: 12199
Response-Code: 400
Content-Type: application/json
Headers: {Content-Type=[application/json], Date=[Wed, 02 Nov 2022 16:00:58 GMT]}
Payload: {
  "code" : "generic_err_missing_required_header",
  "message" : "Missing header: [X-chkp-sid]"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;no login ... first ... so it's not strange that logout doesn't have session_id &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;And no entry at all into $FWDIR/log/api.csv...&lt;BR /&gt;&lt;SPAN&gt;But with &lt;/SPAN&gt;&lt;STRONG&gt;ansible_user + ansible_password&lt;/STRONG&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;2022-11-02 17:04:59,426 DEBUG com.checkpoint.management.web_api.core.cxf.interceptor.WebApiInInterceptorLoginValidator.handleMessage:32 [qtp1587849480-88] - Validating 'login' command of the version: [1.8]
2022-11-02 17:04:59,426  INFO org.apache.cxf.interceptor.LoggingInInterceptor.log:250 [qtp1587849480-88] - Inbound Message
----------------------------
ID: 12203
Address: http://127.0.0.1:65456/web_api/login
Encoding: UTF-8
Http-Method: POST
Content-Type: application/json
Headers: {accept-encoding=[identity], Authorization=[Basic YWRtaW46MXFhekBXU1g=], connection=[keep-alive], Content-Length=[41], content-type=[application/json], Host=[127.0.0.1:65456], User-Agent=[Ansible], X-Forwarded-For=[172.19.99.100], X-Forwarded-Host=[172.19.99.253:443], X-Forwarded-Host-Port=[443], X-Forwarded-Server=[172.19.99.253]}
(...)
ID: 12203
Response-Code: 200
Content-Type: application/json
Headers: {Content-Type=[application/json], Date=[Wed, 02 Nov 2022 16:05:00 GMT]}
Payload: {
  "uid" : "2d35b5f9-2b61-4b75-9e6d-8ac8656d195f",
  "sid" : "ad05d22ae40bc55426980e0a93b82433",
  "url" : "https://172.19.99.253:443/web_api",
  "session-timeout" : 600,
  "last-login-was-at" : {
    "posix" : 1667378605905,
    "iso-8601" : "2022-11-02T09:43+0100"
  },
  "api-server-version" : "1.8",
  "user-name" : "admin",
  "user-uid" : "33efce7f-77bb-4874-859b-793b83190f48"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No issues at all &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And of course in $FWDIR/log/api.csv I see:&lt;BR /&gt;2022-11-02,17:07:06 +0100,"Ansible","172.19.99.100","172.19.99.253:443",login,PASSED,855&lt;/P&gt;&lt;P&gt;--&lt;BR /&gt;Best&lt;BR /&gt;Marcin&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 16:09:17 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Ansible-with-api-key/m-p/161052#M7250</guid>
      <dc:creator>marcyn</dc:creator>
      <dc:date>2022-11-02T16:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible with api-key</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Ansible-with-api-key/m-p/161166#M7254</link>
      <description>&lt;P&gt;this feels a little like a weird problem I encountered recently where ansible wasn't sending the domain parameter in the login request. The 'solution' (which I'm not 100% convinced is actually addressing the root of the problem) was to roll back to the previous version of ansible-core (2.13.3 worked for me, 2.13.4 did not - but with a completely different user on the same Ubuntu host both versions worked).&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2022 15:40:13 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Ansible-with-api-key/m-p/161166#M7254</guid>
      <dc:creator>StuartGreen</dc:creator>
      <dc:date>2022-11-03T15:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible with api-key</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Ansible-with-api-key/m-p/161179#M7255</link>
      <description>&lt;P&gt;What version/JHF is the management?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2022 18:13:16 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Ansible-with-api-key/m-p/161179#M7255</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2022-11-03T18:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible with api-key</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Ansible-with-api-key/m-p/161208#M7260</link>
      <description>&lt;P&gt;Hi Stuart and PhoneBoy,&lt;/P&gt;&lt;P&gt;I will try older version of ansible .... it would be strange if that will fix the issue ... but I will give it a try.&lt;/P&gt;&lt;P&gt;Regarding SMS - it's R81.10 Take66 but I can update it (it's lab env.) to Take78 and take a look.&lt;/P&gt;&lt;P&gt;--&lt;BR /&gt;Best&lt;BR /&gt;m.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2022 08:05:02 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Ansible-with-api-key/m-p/161208#M7260</guid>
      <dc:creator>marcyn</dc:creator>
      <dc:date>2022-11-04T08:05:02Z</dc:date>
    </item>
    <item>
      <title>Re: Ansible with api-key</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Ansible-with-api-key/m-p/161216#M7261</link>
      <description>&lt;P&gt;Ok, it looks like mistery is solved !&lt;/P&gt;&lt;P&gt;Below I will write how to solve this issue.&lt;/P&gt;&lt;P&gt;Because I have debian 11 I used repository that is mentioned here:&lt;BR /&gt;&lt;A href="https://docs.ansible.com/ansible/latest/installation_guide/installation_distros.html#installing-ansible-on-debian" target="_blank"&gt;https://docs.ansible.com/ansible/latest/installation_guide/installation_distros.html#installing-ansible-on-debian&lt;/A&gt;&lt;BR /&gt;And from that repository I installed ansible.&lt;/P&gt;&lt;P&gt;It was as you already saw on one of my previous posts version 2.12.9 (core), later I upgraded it to 2.12.10.&lt;/P&gt;&lt;P&gt;Because&amp;nbsp;&lt;a href="https://community.checkpoint.com/t5/user/viewprofilepage/user-id/12391"&gt;@StuartGreen&lt;/a&gt;&amp;nbsp;mentioned version 2.13.3 and 2.13.4 ... which are no present in this repository I decided to uninstall completely ansible and to reinstall it via pip3.&lt;/P&gt;&lt;P&gt;So I ended up with this:&lt;BR /&gt;pip3 install ansible&lt;/P&gt;&lt;P&gt;And it gave me:&lt;BR /&gt;# ansible --version&lt;BR /&gt;ansible [core 2.13.5]&lt;/P&gt;&lt;P&gt;And with this version I have no issue at all with ansible_api_key:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# ansible-playbook playbook_add.yaml

PLAY [playbook] ********************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************
ok: [172.19.99.253]

TASK [add host] ********************************************************************************************************
changed: [172.19.99.253]

TASK [add host to group] ***********************************************************************************************
changed: [172.19.99.253]

TASK [publish] *********************************************************************************************************
changed: [172.19.99.253]

TASK [install policy] **************************************************************************************************
changed: [172.19.99.253]

PLAY RECAP *************************************************************************************************************
172.19.99.253              : ok=5    changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

# tail -n 10 /etc/ansible/hosts
[check_point]
172.19.99.253
[check_point:vars]
ansible_httpapi_use_ssl=True
ansible_httpapi_validate_certs=False
ansible_api_key=xj56ETO+ywCRwaoDgrFTQ==
ansible_network_os=check_point.mgmt.checkpoint&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So case closed ... solution was extremely easy ... if you know that you have to use correct version &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;In Check Point's collection documentation it was only mentioned that ansible verstion have to be greater then 2.9.&lt;/P&gt;&lt;P&gt;So in case someone else has the same issue and is wondering how to solve it =&amp;gt; use different version of ansible, in my case 2.13.5 did the trick.&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.checkpoint.com/t5/user/viewprofilepage/user-id/12391"&gt;@StuartGreen&lt;/a&gt;,&amp;nbsp;&lt;a href="https://community.checkpoint.com/t5/user/viewprofilepage/user-id/37502"&gt;@Omer_Kleinstern&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.checkpoint.com/t5/user/viewprofilepage/user-id/7"&gt;@PhoneBoy&lt;/a&gt;&amp;nbsp;for your feedback.&lt;/P&gt;&lt;P&gt;--&lt;BR /&gt;Best&lt;BR /&gt;Marcin&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2022 10:04:45 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Ansible-with-api-key/m-p/161216#M7261</guid>
      <dc:creator>marcyn</dc:creator>
      <dc:date>2022-11-04T10:04:45Z</dc:date>
    </item>
  </channel>
</rss>

