teemtee / tmt

Test Management Tool
MIT License
78 stars 117 forks source link

`remote_user` ansible key not working when ansible playbook is called by tmt #2965

Open majamassarini opened 1 month ago

majamassarini commented 1 month ago

If I run the ansible playbook below in the prepare step of a locally virtual provisioned tmt machine I always get root as an output.

[...]
  prepare:
    - how: shell
      script: 'adduser -m packit'
    - how: ansible
      playbook: whoami.yml
      extra-args: '-vvv'
---
- name: whoami
  remote_user: packit
  hosts: all
  tasks:
    - name: Whoami
      ansible.builtin.command: whoami
      changed_when: False

If I change the remote_user key with the become_user key then I get the packit user. Unfortunately I can't use the become_user directive because I need a full working systemd environment for the packit user and this could be achieved logging into packit directly through ssh.

LecrisUT commented 1 month ago

Does remote_user work when connection: local? Maybe can try ansible_user instead of remote_user? https://github.com/teemtee/tmt/blob/ae941d11c9783b211fbf3bb0b5ad535da68a83d3/tmt/steps/provision/local.py#L55-L63

It should work when provision: container?

https://github.com/teemtee/tmt/blob/ae941d11c9783b211fbf3bb0b5ad535da68a83d3/tmt/steps/provision/podman.py#L269-L274

majamassarini commented 1 month ago

Does remote_user work when connection: local? Maybe can try ansible_user instead of remote_user?

I can't use ansible_user is not recognized by my ansible version.

And as far as I can understand the above playbook is called with this command:

ansible-playbook -vvv --ssh-common-args '-oForwardX11=no -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oConnectionAttempts=5 -oConnectTimeout=60 -oServerAliveInterval=5 -oServerAliveCountMax=60 -oIdentitiesOnly=yes -p10028 -i /var/tmp/tmt/prova/plans/deployment/local/provision/default-0/id_ecdsa -oPasswordAuthentication=no -S/run/user/1000/tmt/tmp51rub2tx' -i root@127.0.0.1, /home/maja/deployment/playbooks/oc-cluster-setup.yml

I don't see the -c option used here.

It should work when provision: container?

I didn't try it.

LecrisUT commented 1 month ago

Found it, seems to be in the generic ssh guest.

https://github.com/teemtee/tmt/blob/ae941d11c9783b211fbf3bb0b5ad535da68a83d3/tmt/steps/provision/__init__.py#L1481-L1484

I think the issue here is that cli would always have priority. If tmt can learn to use inventory file, host, group files, it should give better control