Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-37063

Run ansible as another user on jenkins server

    Details

    • Similar Issues:

      Description

      Could you improve support of sudo directly on jenkins server, please?
      For example: If you are running jenkins under jenkinsuser and if you want to run ansible as another user, there is no way to accomplish that.
      Solution would be add arbitrary string before ansible executable in ansible plugin and edit sudoers like >

      /etc/sudoers
      jenkinsuser ALL=(anotheruser)NOPASSWD:/usr/bin/ansible-playbook /tmp/* -i /tmp/* * --private-key /home/anotheruser/.ssh/id_rsa_ansible *

      final command would be
      sudo -u anotheruser-i /bin/bash -l -c '/usr/bin/ansible-playbook /tmp/playbook.yml -i /tmp/inventory -f 5 --private-key /home/anotheruser/.ssh/id_rsa_ansible -vvvv'

      Thanks

        Attachments

          Activity

          Hide
          michaelcresswell Michael Cresswell added a comment -

          The best way to run ansible from Jenkins as another user would be to setup an executor running as the desired user and executing jobs on it.

          Show
          michaelcresswell Michael Cresswell added a comment - The best way to run ansible from Jenkins as another user would be to setup an executor running as the desired user and executing jobs on it.

            People

            • Assignee:
              acien1951 Acien1951 Acien1951
              Reporter:
              acien1951 Acien1951 Acien1951
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: