mitogen-hq / mitogen

Distributed self-replicating programs in Python
https://mitogen.networkgenomics.com/
BSD 3-Clause "New" or "Revised" License
2.34k stars 199 forks source link

feat(ansible): Handle templated `ssh_user` #1116

Closed setpill closed 3 weeks ago

setpill commented 1 month ago

ansible-mitogen does not handle templated values in ssh_user .

Original context from !956 :

[..] this does fix the ssh_common_args, but I am running also into the issue that a templated ssh_user is not correctly handled.

Originally posted by @setpill in https://github.com/mitogen-hq/mitogen/issues/956#issuecomment-2225208105

setpill commented 1 month ago

Usecase: in our environment we have ansible roles that have tasks that need to be executed by different users. For legacy and security reasons we cannot assume these users to have fixed names, so we need to provide them in variable form.

Let's say for example that a role executes some tasks as build_user and some tasks as deploy_user. We would then have a task (block) in the form of:

- name: Build something
  vars:
    ansible_user: "{{ build_user }}"
    ansible_password: "{{ build_pass }}"
    ansible_sudo_pass: "{{ build_pass }}"
  block:
    - [..]

Ansible-mitogen is not currently a drop-in replacement for this scenario, as it will not template these variables and pass the literal string {{ build_user }} as the SSH user, which fails.

moreati commented 1 month ago

Ansible-mitogen is not currently a drop-in replacement for this scenario, as it will not template these variables and pass the literal string {{ build_user }} as the SSH user, which fails.

I'm investigating 2 Mitogen bugs that are probably affecting your playbook

  1. Many of the ansible_* (connection) variables don't get templated (varies issues already filed)
  2. For the few that are templated, anything in a play's vars: block is ignored.
setpill commented 1 month ago

Thanks for your great work! Mitogen really is a much faster engine for ansible, would be awesome to get it closer to that "drop-in replacement" ideal :)