help debugging calling import_playbook

I need help getting more information on why an import_ playbook fails please…

During a play (play 1) I’m (ansible.builtin.template) sucessfully templating out another play (play 2) and variables file and using trying to call them later in play 1, but that import fails

import_playbook: $LINUX_PLAYBOOKS/paperless/{{play_filename}}
but I get

fatal: [nott]: FAILED! => changed=false
module_stderr: |-
Shared connection to nott.mont closed.
module_stdout: “”
msg: |-
MODULE FAILURE
See stdout/stderr for the exact error
rc: 0

Using debugger: on failed or register and debug var doesn’t give any more useful information

ok: [nott] =>
playoutput:
changed: false
failed: true
module_stderr: |-
Shared connection to nott.mont closed.
module_stdout: “”
msg: |-
MODULE FAILURE
See stdout/stderr for the exact error
rc: 0

Worth noting that the subject of play1 and play2 is, in this case, the server itself, though the play is intended to be used on other machines as well.

Running play2 directly works ok

running play1 with -vvvvv does show a broken pipe in the ssh commands but I can certainly ssh into the server from itself and play1 works successfully up to the point of that import_playbook

debug1: auto-mux: Trying existing master
debug2: fd 3 setting O_NONBLOCK
debug2: mux_client_hello_exchange: master version 4
debug3: mux_client_forwards: request forwardings: 0 local, 0 remote
debug3: mux_client_request_session: entering
debug3: mux_client_request_alive: entering
debug3: mux_client_request_alive: done pid = 72692
debug3: mux_client_request_session: session request sent
debug1: mux_client_request_session: master session id: 2
debug3: mux_client_read_packet: read header failed: Broken pipe
debug2: Received exit status from master 0
Shared connection to nott.mont closed.
module_stdout: “”
msg: |-
MODULE FAILURE
See stdout/stderr for the exact error
rc: 0
…ignoring

This fails even if the previous files exist so I don’t think it’s that - I’ve confirmed so the files exist on disk and it’s the same result whether the play is run either with those files existing, or not.

I’ve tried meta reset connection just before this

Appreciate this may not be the best way to do this but I’m interested to see what’s going on now and what I’m missing.

Scratching my head, apologies if this isn’t clear - finding it hard to explain this one

The import would not fail with connection issues, no connection is
involved, what is failing is a task, but you are not providing enough
output to determine which task it is.

Thanks Brian

Not quite sure I understand, it’s the output I’m trying to get (more of) to understand why it’s failing.

In case it helps at all

Here’s the play 2 created that it fails on. This is fine to run directly through ansible-playbook, just not through that play1

  • hosts: nott
    become: yes
    vars_files:
  • /$LINUX_PLAYBOOKS/paperless/mont_nott_vars.yml
    tasks:
    roles:

- geerlingguy.postgresql

  • paperless-ng

- geerlingguy.nginx

Here’s the section of play 1

post_tasks:

  • name: run the play - $LINUX_PLAYBOOKS/paperless/{{play_filename}}
    import_playbook: $LINUX_PLAYBOOKS/paperless/{{play_filename}}
    register: playoutput
    ignore_errors: yes

delegate_to: 127.0.0.1

become: yes

debugger: on_failed

  • name: get debug output
    debug:
    var: playoutput

Does that help, or is there something else I can run to get more detail from that mysterious " See stdout/stderr for the exact error"
That’s what the debug var playoutput should provide isn’t it ??

Perhpas I have a misunderstanding here

When you say " no connection is involved"

If I’m right it is possible to ssh from a server to itself - shown by a new shell and the ability to exit back to the previous shell - or am I mistaken and it’s somehow ignoring that

Is this not what ansible is doing if you run a playbook on the same server (without delegate_to or local connection)?

That would seem to be what’s happening from the ssh output (broken pipe) but I may be completely turned around in my understanding here (?)

When I say 'no connection is involved' it is in the act of importing a
playbook, this is a 'LOCAL ACTION' that has nothing to do with a
remote, so if it fails it will not give a connection error.

One of many issues with your play is that you are trying to import a
playbook inside a play, this does not work and you should get a
specific error message, your connection issue might be making the play
fail before you get there and that is another problem, but again, not
enough info to debug with. You also cannot register the result of an
import or include nor ignore import errors.

Also, you cannot use env vars like this $LINUX_PLAYBOOKS, use the 'env' lookup

OK, thanks Brian, that gives me some things to go on and I’m clearly in need of going back and starting again to avoid this spaghetti.

Didn’t know about the env variable rather than using those paths so will go that route and that alone has been very helpful.

Thanks for your patience, just learning.