G
G
gpfspam2020-02-24 15:06:53
Ansible
gpfspam, 2020-02-24 15:06:53

Ansible. How to use another module in a module?

Hello everyone, I'm trying to figure out Ansible

There is a simple task of iterating playbooks from tasks/
Let's say I pass its own path to each *.yml and return the result {{ register }} to the main playbook.

tasks:
  - include: "{{ item }}"
    vars:
     name_task: "{{ item} }"
    with_fileglob:
        - tasks/*.yml


How can I process this result further without leaving the loop?
For example, write to the file file.log

- local_action:
       module: copy
       content: "register.stdout_lines|join('\n') }}"
       dest: "file.log"


Of course, I can add this module in each *.yml file, but I would like to describe it once in a cycle.

As a result, if I put everything together, I get an error

tasks:
  - include: "{{ item }}"
    vars:
     name_task: "{{ item} }"
    local_action:
     module: copy
     content: "{{ register.stdout_lines|join('\n') }}"
     dest: "file.log"
    with_fileglob:
        - tasks/*.yml

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MaxKozlov, 2020-02-24
@MaxKozlov

you can try to use block
or nested include_tasks
And if there is no requirement that the output file be replenished immediately after execution, then register for a loop creates an array of data, which can be written at the end

P
Puma Thailand, 2020-02-25
@opium

According to the task, it is clear that you have an initially incorrect task and the solution of the
Cars is all known, they are not generated, so you don’t need to look for them there somehow, just rewrite them once

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question