# Import\_tasks results in fatal error: "shared connection closed"

**URL:** <https://forum.ansible.com/t/import-tasks-results-in-fatal-error-shared-connection-closed/4922>\
**Category:** Get Help\
**Tags:** playbook\
**Created:** [April 12, 2024, 10:12am UTC](https://forum.ansible.com/t/import-tasks-results-in-fatal-error-shared-connection-closed/4922 "2024-04-12T10:12:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wnelis](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wnelis/32/2880_2.png) [@wnelis](https://forum.ansible.com/u/wnelis)\
**Post date:** [April 12, 2024, 10:12am UTC](https://forum.ansible.com/t/import-tasks-results-in-fatal-error-shared-connection-closed/4922/1 "2024-04-12T10:12:46Z")

</div>

A group of tasks is used twice in a play, therefore they are placed in a separate file and invoked using ‘import\_tasks’. However, the result is, in all variations I’ve tried:

```auto
TASK [linux-common : Include Xymon client configuration tasks] *************************************
fatal: [kapitein]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 192.168.0.110 closed.\r\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 0}

```

There are no problems with the (SSH) connection. The ansible server is running on Linux Mint 20.1, ansible version 2.9.6, python version 3.8.10. The playbook is:

```auto
---
- name: Jardinera configuration
  hosts: Linux
  roles:
  - { role: linux-locale, when: "'Linux' in group_names" }
  - { role: raspberry-pi-common, when: "'RaspberryPi' in group_names" }
  - { role: vision-common, when: "'Vision' in group_names" }
  - { role: linux-common, when: "'Linux' in group_names" }
  - { role: linux-zram, when: "'Linux' in group_names" }
  - { role: jardinera-common, when: "'Linux' in group_names" }

 - import_playbook: playbook.kapitein.yaml
 - import_playbook: playbook.plant0.yaml

```

The import\_tasks is located in role linux-common. The relevant part of the tasks file in this role is:

```auto
- name: Include Xymon client configuration tasks
  ansible.builtin.import_tasks:
    file: "~/ansible/{{ jardinera_path }}tasks.xymon.client.yaml"
  when: "'XymonProxy' in group_names or 'XymonServer' in group_names"

```

with variable ‘jardinera\_path’ containing “jardinera/”. The start of file ‘tasks.xymon.client.yaml’ is:

```auto
---
- name: Add user xymon to groups adm and video
  user:
    name: xymon
    groups: adm,video
    append: true
  when: "'Xymon' in group_names"

```

If the contents of file `tasks.xymon.client.yaml’ is included in the tasks section of the role, it just works.  
What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [April 12, 2024, 11:10am UTC](https://forum.ansible.com/t/import-tasks-results-in-fatal-error-shared-connection-closed/4922/2 "2024-04-12T11:10:14Z")

</div>

`import_tasks` doesn’t works across roles, you need to user the [import role module](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/import_role_module.html), for example:

```yaml
- name: Include Xymon client configuration tasks from the linux-common role
  ansible.builtin.import_role:
    name: linux-common
    tasks_from: "~/ansible/{{ jardinera_path }}tasks.xymon.client.yaml"
  when: ( "XymonProxy" in group_names ) or ( "XymonServer" in group_names )

```

---

<div class="post-metadata">

**Author:** ![wnelis](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wnelis/32/2880_2.png) [@wnelis](https://forum.ansible.com/u/wnelis)\
**Post date:** [April 12, 2024, 12:46pm UTC](https://forum.ansible.com/t/import-tasks-results-in-fatal-error-shared-connection-closed/4922/3 "2024-04-12T12:46:01Z")

</div>

> [@chris](#):
>
> `import_tasks` doesn’t works _across_ roles,

Thanks, that was something I did not find in the documentation. The tasks file is therefore moved to sub-directory …/roles/linux-common/tasks/ and the absolute path-name is changed to be only the file-name. This moves the tasks file into the same role, which is also shown in URL [https://docs.ansible.com/ansible/latest/playbook\_guide/playbooks\_reuse\_roles.html](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_reuse_roles.html). However, running the play results in the same error.

Then the syntax was adjusted to match the aforementioned URL, and after changing

```auto
  ansible.builtin.import_tasks:
    file: tasks.xymon.client.yaml

```

into

```auto
  import_tasks: tasks.xymon.client.yaml

```

it works. I do not know why removing ‘syntactic sugar’ makes it work.

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [April 12, 2024, 12:51pm UTC](https://forum.ansible.com/t/import-tasks-results-in-fatal-error-shared-connection-closed/4922/4 "2024-04-12T12:51:50Z")

</div>

Perhaps you might be better off using the [include\_tasks module](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/include_tasks_module.html#ansible-collections-ansible-builtin-include-tasks-module), the difference between `import` and `include` might be the issue here?

See [the documentation on re-using files and roles](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_reuse.html#id4).

---

<div class="post-metadata">

**Author:** ![wnelis](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wnelis/32/2880_2.png) [@wnelis](https://forum.ansible.com/u/wnelis)\
**Post date:** [April 12, 2024, 1:12pm UTC](https://forum.ansible.com/t/import-tasks-results-in-fatal-error-shared-connection-closed/4922/5 "2024-04-12T13:12:24Z")

</div>

Using ‘include\_tasks’ i.s.o. ‘import\_tasks’ with the extended syntax does result in the original fatal error: “shared connection closed”. Using ‘include\_tasks’ i.s.o. ‘import\_tasks’ with the minimal syntax works.

I’ve tried ‘include\_taks’ earlier, without any difference. In my use case the major difference between ‘include\_tasks’ and ‘import\_tasks’ is when the when-clause is evaluated.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [May 12, 2024, 1:12pm UTC](https://forum.ansible.com/t/import-tasks-results-in-fatal-error-shared-connection-closed/4922/6 "2024-05-12T13:12:33Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
