Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
Tai_Bui
Participant

ansible.module_utils.connection.ConnectionError: string indices must be integers

Hi,

I just rebuilt my Ubuntu and re-installed all modules that I had before for my lab. I know my playbook worked previously but not sure why not this time.

 

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.module_utils.connection.ConnectionError: string indices must be integers
fatal: [checkpoint]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/osboxes/.ansible/tmp/ansible-local-4258683ilf5oi0/ansible-tmp-1624393456.3348339-425981-7450313037159/AnsiballZ_cp_mgmt_network.py\", line 100, in <module>\n    _ansiballz_main()\n  File \"/home/osboxes/.ansible/tmp/ansible-local-4258683ilf5oi0/ansible-tmp-1624393456.3348339-425981-7450313037159/AnsiballZ_cp_mgmt_network.py\", line 92, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/osboxes/.ansible/tmp/ansible-local-4258683ilf5oi0/ansible-tmp-1624393456.3348339-425981-7450313037159/AnsiballZ_cp_mgmt_network.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_network', init_globals=dict(_module_fqn='ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_network', _modlib_path=modlib_path),\n  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_cp_mgmt_network_payload_tpg00l8b/ansible_cp_mgmt_network_payload.zip/ansible_collections/check_point/mgmt/plugins/modules/cp_mgmt_network.py\", line 225, in <module>\n  File \"/tmp/ansible_cp_mgmt_network_payload_tpg00l8b/ansible_cp_mgmt_network_payload.zip/ansible_collections/check_point/mgmt/plugins/modules/cp_mgmt_network.py\", line 220, in main\n  File \"/tmp/ansible_cp_mgmt_network_payload_tpg00l8b/ansible_cp_mgmt_network_payload.zip/ansible_collections/check_point/mgmt/plugins/module_utils/checkpoint.py\", line 265, in api_call\n  File \"/tmp/ansible_cp_mgmt_network_payload_tpg00l8b/ansible_cp_mgmt_network_payload.zip/ansible_collections/check_point/mgmt/plugins/module_utils/checkpoint.py\", line 65, in send_request\n  File \"/tmp/ansible_cp_mgmt_network_payload_tpg00l8b/ansible_cp_mgmt_network_payload.zip/ansible/module_utils/connection.py\", line 195, in __rpc__\nansible.module_utils.connection.ConnectionError: string indices must be integers\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

 

Here is my host.yml

---
firewall:
 hosts:
  checkpoint:
    ckp_sms_ngen ansible_host: 10.10.10.2
    ansible_httpapi_use_ssl: True
    ansible_httpapi_validate: False
    ansible_user: admin
    ansible_network_os: check_point.mgmt.checkpoint

 

Here is my playbook

---


- hosts: checkpoint
  connection: httpapi

  tasks:
   - name: Adding Site1 VL 10
     cp_mgmt_network:
      name: Site1-VL10-Nets
      state: present
      subnet: 10.10.10.0
      subnet_mask: 255.255.255.0
      comments: Network
      auto_publish_session: yes

   - name: Adding Site1 VL 20
     cp_mgmt_network:
      name: Site1-VL20-Nets
      state: present
      subnet: 10.10.20.0
      subnet_mask: 255.255.255.0
      comments: Desktop
      auto_publish_session: yes

   - name: Adding Site1 VL 30
     cp_mgmt_network:
      name: Site1-VL30-Nets
      state: present
      subnet: 10.10.30.0
      subnet_mask: 255.255.255.0
      comments: Secure
      auto_publish_session: yes

   - name: Adding Site2 VL 10
     cp_mgmt_network:
      name: Site2-VL10-Nets
      state: present
      subnet: 10.20.10.0
      subnet_mask: 255.255.255.0
      comments: Network
      auto_publish_session: yes

   - name: Adding Site2 VL 20
     cp_mgmt_network:
      name: Site2-VL20-Nets
      state: present
      subnet: 10.20.20.0
      subnet_mask: 255.255.255.0
      comments: Network
      auto_publish_session: yes

   - name: Adding Site2 VL 30
     cp_mgmt_network:
      name: Site2-VL30-Nets
      state: present
      subnet: 10.20.30.0
      subnet_mask: 255.255.255.0
      comments: Secure
      auto_publish_session: yes

   - name: Adding Site3 VL 10
     cp_mgmt_network:
      name: Site3-VL10-Nets
      state: present
      subnet: 10.30.10.0
      subnet_mask: 255.255.255.0
      comments: Network
      auto_publish_session: yes

   - name: Adding Site3 VL 20
     cp_mgmt_network:
      name: Site3-VL20-Nets
      state: present
      subnet: 10.30.20.0
      subnet_mask: 255.255.255.0
      comments: Desktop
      auto_publish_session: yes

   - name: Adding Site3 VL 30
     cp_mgmt_network:
      name: Site3-VL10-Nets
      state: present
      subnet: 10.30.30.0
      subnet_mask: 255.255.255.0
      comments: Secure
      auto_publish_session: yes

 

 

 

 

 

0 Kudos
2 Replies
PhoneBoy
Admin
Admin

So what happens when you run the playbook with -vvv as suggested by the error message?

0 Kudos
Art_Zalenekas
Employee
Employee

If you look carefully, your YML based inventory has an additional string ckp_sms_ngen that should not be present. In that section, you need to provide var: value .

---
firewall:
 hosts:
  checkpoint:
    ansible_host: 10.10.10.2
    ansible_httpapi_use_ssl: True
    ansible_httpapi_validate: False
    ansible_user: admin
    ansible_network_os: check_point.mgmt.checkpoint

Additionally, for the sake of readability, I would have a host-based host_var with all the values of networks as a var, and then use one task to loop over the networks var of that particular host. Also, don't publish on each and one task, but rather notify a handler for publish to call the cp_mgmt_publish module.

host_vars/checkpoint.yml

networks:
  - name: Site1-VL10-Nets
    state: present
    subnet: 10.10.10.0
    subnet_mask: 255.255.255.0
    comments: Network
  - name: Site1-VL20-Nets
    state: present
    subnet: 10.10.20.0
    subnet_mask: 255.255.255.0
    comments: Desktop
  - name: Site1-VL30-Nets
    state: present
    subnet: 10.10.30.0
    subnet_mask: 255.255.255.0
    comments: Secure
  - name: Site2-VL10-Nets
    state: present
    subnet: 10.20.10.0
    subnet_mask: 255.255.255.0
    comments: Network
  - name: Site2-VL20-Nets
    state: present
    subnet: 10.20.20.0
    subnet_mask: 255.255.255.0
    comments: Network
  - name: Site2-VL30-Nets
    state: present
    subnet: 10.20.30.0
    subnet_mask: 255.255.255.0
    comments: Secure
  - name: Site3-VL10-Nets
    state: present
    subnet: 10.30.10.0
    subnet_mask: 255.255.255.0
    comments: Network
  - name: Site3-VL20-Nets
    state: present
    subnet: 10.30.20.0
    subnet_mask: 255.255.255.0
    comments: Desktop
  - name: Site3-VL30-Nets
    state: present
    subnet: 10.30.30.0
    subnet_mask: 255.255.255.0
    comments: Secure

 Then in the playbook call:

---
- name: Test Playbook
  hosts: checkpoint
  gather_facts: false
  connection: httpapi
  collections:
    - check_point.mgmt
  tasks:
    - name: Add network object
      cp_mgmt_network:
        name: '{{ item.name }}'
        state: '{{ item.state }}'
        subnet: '{{ item.subnet }}'
        subnet_mask: '{{ item.subnet_mask }}'
        comments: '{{ item.comments }}'
      loop: '{{ networks }}'
      notify: publish

  handlers:
    - name: publish
      cp_mgmt_publish:

This way your playbook stays clean, quick, short, and your host (SMS/CMA) based host_var inventory file has data that it needs. Now you can manage the variable data file and leave the playbook file alone. Feel free to change the variable names as you see fit. I hope that helps!

 

Kind regards,
Arturas Zalenekas