Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for 'user' argument to su to another user when executing git and R10K #141

Closed
wants to merge 1 commit into from
Closed

Conversation

GeoffWilliams
Copy link
Contributor

I've taken on-board the suggestions from https://github.com/acidprime/r10k/issues/135 and developed this PR to address it.

The patch works by checking for the presence of a user argument. If this is present and matches the regexp ^\w+$, we will try to invoke git or r10k by doing su - $user -c 'COMMAND'.

I've modified the agent to support user on all operations and verified that I still receive output and errors, as you can see from the following console captures:

r10k status

peadmin@xmaster:~$ mco rpc  r10k status user=r10k path=/etc/puppetlabs/puppet/environments/production/modules/ntp -v
Discovering hosts using the mc method for 2 second(s) .... 1

 * [ =========================================================> ] 1 / 1


xmaster.vagrant.vm                      : OK
    {:path=>"/etc/puppetlabs/puppet/environments/production/modules/ntp",     :output=>      "# Not currently on any branch.\nnothing to commit (working directory clean)",     :error=>"",     :status=>0}

r10k deploy_module

peadmin@xmaster:~$ mco rpc r10k deploy_module module_name=ntp user=r10k environment=production
Discovering hosts using the mc method for 2 second(s) .... 1

 * [ =========================================================> ] 1 / 1


xmaster.vagrant.vm                       
            Errors:
   Specific module: ntp
            Output:
            status: 0

r10k sync

peadmin@xmaster:~$ mco rpc  r10k sync user=r10k -v
Discovering hosts using the mc method for 2 second(s) .... 1

 * [ =========================================================> ] 1 / 1


xmaster.vagrant.vm                      : OK
    {:output=>"",     :error=>      "[R10K::Action::Deploy::Environment - ERROR] Command exited with non-zero exit code:\nCommand: git --git-dir /etc/puppetlabs/puppet/environments/production/modules/ruby/.git --work-tree /etc/puppetlabs/puppet/environments/production/modules/ruby remote set-url cache /var/cache/r10k/https---github.com-puppetlabs-puppetlabs-ruby.git\nStderr:\nfatal: No such remote 'cache'\nExit code: 128",     :status=>1}

As you can see, there is a strange error here caused by a partial failure and this gets captured too. I got the same error running r10k on the command line so its legit

Thanks Eli, Brett and Zack for your help figuring this one out.

…and r10k commands; document new option; document how to obtain command output
@acidprime
Copy link
Collaborator

Looks good @GeoffWilliams can you target https://github.com/acidprime/r10k/tree/3.x as I want this functionality in , but may want to refactor a little.

@GeoffWilliams
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants