<p>The &quot;translation&quot; happens in the Ansible task executor, which takes information about a module and pushes executable code to the target.</p>
<p>From <a href="https://docs.ansible.com/ansible/latest/dev_guide/overview_architecture.html#modules" rel="nofollow noreferrer">the documentation</a>:</p>
<blockquote>
<p>Ansible works by connecting to your nodes and pushing out scripts called “Ansible modules” to them.</p>
</blockquote>
<p>So to answer your question:</p>
<blockquote>
<p>I assume this is on the Ansible node, that is, where the Ansible command is executed?</p>
</blockquote>
<p><strong>yes</strong>, this happens on the controller (the node where the <code>ansible</code> command is executed).</p>
<p>Based on the configuration of the controller, it knows where to look for modules. This is set by <a href="https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-module-path" rel="nofollow noreferrer">the <code>ANSIBLE_LIBRARY</code></a> environment variable, or relevant section in the configuration file.</p>
<p>The <a href="https://github.com/ansible/ansible/blob/44dcfde9b84177e7dfede11ab287789c577b82b5/lib/ansible/executor/task_executor.py#L402" rel="nofollow noreferrer"><code>_execute()</code></a> method of the Ansible task executor class is the place to look for how this happens.</p>
<p>In terms of what happens in detail, from what I can tell from the executor class, Ansible</p>
<ol>
<li>Creates a task queue manager with the list of tasks (handling loops, etc)</li>
<li>for each task creates a task executor script based on the module type, pulling in all of the relevant context for that task (module variables, connection variables, magic variables)</li>
<li>Creates a connection to the remote target <a href="https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/connection.py" rel="nofollow noreferrer">see the <code>connection.py</code> library</a></li>
<li>Creates a pickle of the executable and writes it to the remote target (see<a href="https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/connection.py#L47" rel="nofollow noreferrer"> <code>write_to_file_descriptor()</code></a>)</li>
</ol>
<p>Part of the connection is determining the remote interpreter (python/powershell, etc) and the task executor takes care of ensuring that the remove interpreter for the module's execution environment is actually present (if, not, an error is raised).</p>

CC BY-SA 4.0
2023-02-01T20:52:54.480Z
Thank you, this was the answer I was looking for (waves hand, LOL)
Chris F
CC BY-SA 4.0
2023-01-29T08:45:51.900Z
2023-01-29T09:00:13.217Z
2023-01-29T09:00:13.217Z
Bruce Becker
<p>When running Ansible scripts, where does the translation from Ansible DSL to Python(Linux) or Powershell(Windows) happen? I assume this is on the Ansible node, that is, where the Ansible command is executed?</p>
<p><strong>NOTE</strong>: I'm NOT asking how to use Ansible itself, or how it works from a tooling perspective - I've been using it for years so I know how it works from that point of view.</p>
<p>TIA</p>

<ansible>
Where does Ansible DSL get translated to either Powershell or Python?
Chris F
# Where does Ansible DSL get translated to either Powershell or Python?

(Asked by: username_0 on 2023-01-10)

When running Ansible scripts, where does the translation from Ansible DSL to Python(Linux) or Powershell(Windows) happen? I assume this is on the Ansible node, that is, where the Ansible command is executed?

**NOTE**: I'm NOT asking how to use Ansible itself, or how it works from a tooling perspective - I've been using it for years so I know how it works from that point of view.

TIA

**Tags:** ansible


---

## 1 answers

### Answer by username_1 on 2023-01-29. Score: 1 | Accepted answer

The "translation" happens in the Ansible task executor, which takes information about a module and pushes executable code to the target.

From [the documentation](https://docs.ansible.com/ansible/latest/dev_guide/overview_architecture.html#modules):

> Ansible works by connecting to your nodes and pushing out scripts called “Ansible modules” to them.

So to answer your question:

> I assume this is on the Ansible node, that is, where the Ansible command is executed?

**yes**, this happens on the controller (the node where the `ansible` command is executed).

Based on the configuration of the controller, it knows where to look for modules. This is set by [the `ANSIBLE_LIBRARY`](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-module-path) environment variable, or relevant section in the configuration file.

The [`_execute()`](https://github.com/ansible/ansible/blob/44dcfde9b84177e7dfede11ab287789c577b82b5/lib/ansible/executor/task_executor.py#L402) method of the Ansible task executor class is the place to look for how this happens.

In terms of what happens in detail, from what I can tell from the executor class, Ansible

1. Creates a task queue manager with the list of tasks (handling loops, etc)
2. for each task creates a task executor script based on the module type, pulling in all of the relevant context for that task (module variables, connection variables, magic variables)
3. Creates a connection to the remote target [see the `connection.py` library](https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/connection.py)
4. Creates a pickle of the executable and writes it to the remote target (see [`write_to_file_descriptor()`](https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/connection.py#L47))

Part of the connection is determining the remote interpreter (python/powershell, etc) and the task executor takes care of ensuring that the remove interpreter for the module's execution environment is actually present (if, not, an error is raised).

> **Comments:**
> **username_0**: Thank you, this was the answer I was looking for (waves hand, LOL)  

---

