# Is it safe to use Ansible to run playbooks on untrusted hosts?

**URL:** <https://forum.ansible.com/t/is-it-safe-to-use-ansible-to-run-playbooks-on-untrusted-hosts/4043>\
**Category:** Get Help\
**Tags:** security\
**Created:** [February 25, 2024, 6:41am UTC](https://forum.ansible.com/t/is-it-safe-to-use-ansible-to-run-playbooks-on-untrusted-hosts/4043 "2024-02-25T06:41:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexA](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@AlexA](https://forum.ansible.com/u/AlexA)\
**Post date:** [February 25, 2024, 6:41am UTC](https://forum.ansible.com/t/is-it-safe-to-use-ansible-to-run-playbooks-on-untrusted-hosts/4043/1 "2024-02-25T06:41:50Z")

</div>

Hi guys! I’m considering creating a simple service that helps users set up some software on servers. I’d like to use Ansible for this, but I’m not very familiar with Ansible. The plan is to load the inventory and SSH keys dynamically for each user, connect and run my playbooks.

They questions I have about this is:

- Is this completely safe to do, or is there any chance of compromise of the machine that connects to the servers?
- Exactly what data does Ansible share with the servers it connects to?

I really appreciate if someone with good knowledge of this can answer or point me in a direction where I can find the answers. Thanks! 🙂

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [February 25, 2024, 3:58pm UTC](https://forum.ansible.com/t/is-it-safe-to-use-ansible-to-run-playbooks-on-untrusted-hosts/4043/2 "2024-02-25T15:58:52Z")

</div>

It should be safe, assuming you don’t do things to compromise that (for example, you could use the return value of a module executed on a remote server to write files to paths on the controller that are provided by the module’s result - that would allow the remote server to overwrite arbitrary files the user running ansible on the controller has access to).

Besides that, it should not be possible. I’m using _should_ here, since it is always possible that there are bugs. There could be bugs in SSH that allows the remote host to do something bad on hosts connecting to it, there could be a bug in ansible-core that allows remote hosts to do something like that (one such bug has been found in the past and got fixed - I found [1968412 – (CVE-2021-3583) CVE-2021-3583 ansible: Template Injection through yaml multi-line strings with ansible facts used in template.](https://bugzilla.redhat.com/show_bug.cgi?id=1968412) and [Path Traversal in Ansible · CVE-2020-1735 · GitHub Advisory Database · GitHub](https://github.com/advisories/GHSA-gfr2-qpxh-qj9m), I think that were the most from the last years). There could be more not yet found bugs in the modules/plugins you are using that allow such things to happen.

And obviously, you always have to care about which data you actually send to a remote system. Modules are by default executed on the remote system (if you don’t use `delegate_to: localhost` or the `local` connection), so if you pass on secret data as a module parameter to be run on a remote system, the remote system could intercept that secret. If it’s a secret the remote system knows anyway or is allowed to know, that’s not a problem. But for example if you need to update a DNS entry and you run the DNS update module on the remote machine instead of localhost, your DNS credentials could get hold of by the remote machine. (The only exception is if the module must be run on the remote machine as otherwise the API cannot be reached, for whtaever reason - but then you have to make sure you trust that remote machine enough to pass the information there.)

So, to bome back to your two questions:

1. Connecting to other machines is **never** completely safe. There’s always the chance of bugs not yet found that allow the remote side to exploit you.

2. Generally if you run a module on a remote, the module’s code and the task parameters are sent to the remote machine, and the module is executed there with these parameters.
