# Ruby\_block as a specific user

**URL:** <https://discourse.chef.io/t/ruby-block-as-a-specific-user/9064>\
**Category:** Chef Infra (archive)\
**Created:** [August 2, 2016, 11:59pm UTC](https://discourse.chef.io/t/ruby-block-as-a-specific-user/9064 "2016-08-02T23:59:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![trg](https://avatars.discourse-cdn.com/v4/letter/t/50afbb/32.png) [@trg](https://discourse.chef.io/u/trg)\
**Post date:** [August 2, 2016, 11:59pm UTC](https://discourse.chef.io/t/ruby-block-as-a-specific-user/9064/1 "2016-08-02T23:59:43Z")

</div>

any way possible to do this? try an execute that notifies a ruby\_block still no dice.

---

<div class="post-metadata">

**Author:** ![coderanger](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/coderanger/32/5_2.png) [@coderanger](https://discourse.chef.io/u/coderanger)\
**Post date:** [August 3, 2016, 12:01am UTC](https://discourse.chef.io/t/ruby-block-as-a-specific-user/9064/2 "2016-08-03T00:01:37Z")

</div>

A `ruby_block` resource just runs its code, users don’t enter in to it. If you want to do a fork+setuid dance in your code, that’s up to you (also that won’t work on Windows).

---

<div class="post-metadata">

**Author:** ![trg](https://avatars.discourse-cdn.com/v4/letter/t/50afbb/32.png) [@trg](https://discourse.chef.io/u/trg)\
**Post date:** [August 3, 2016, 12:03am UTC](https://discourse.chef.io/t/ruby-block-as-a-specific-user/9064/3 "2016-08-03T00:03:29Z")

</div>

its ok since its not for windows. I am trying to figure out if its at all possible to run this guy as a specific user.

Chef::Resource::OsxProfile.new(identifier, run\_context)

Mac OS X profiles have two contexts. System and User.

---

<div class="post-metadata">

**Author:** ![trg](https://avatars.discourse-cdn.com/v4/letter/t/50afbb/32.png) [@trg](https://discourse.chef.io/u/trg)\
**Post date:** [August 3, 2016, 12:05am UTC](https://discourse.chef.io/t/ruby-block-as-a-specific-user/9064/4 "2016-08-03T00:05:54Z")

</div>

oh wait…didnt read you reply properly.

Process.fork do  
Process.uid = u.uid  
block.call(user)  
end

wonder if this will work…

---

<div class="post-metadata">

**Author:** ![coderanger](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/coderanger/32/5_2.png) [@coderanger](https://discourse.chef.io/u/coderanger)\
**Post date:** [August 3, 2016, 12:07am UTC](https://discourse.chef.io/t/ruby-block-as-a-specific-user/9064/5 "2016-08-03T00:07:24Z")

</div>

That’s a Chef resource, you don’t run them from `ruby_block` resources 🙂 More to the point the `osx_profile` resource doesn’t support installing a profile as any user other than the one running Chef. If you want to improve this it would have to be in Chef’s code, not your recipe.

---

<div class="post-metadata">

**Author:** ![trg](https://avatars.discourse-cdn.com/v4/letter/t/50afbb/32.png) [@trg](https://discourse.chef.io/u/trg)\
**Post date:** [August 3, 2016, 12:08am UTC](https://discourse.chef.io/t/ruby-block-as-a-specific-user/9064/6 "2016-08-03T00:08:49Z")

</div>

sorry just a terminology mistake. still getting my head around chef (im not a ruby guy)

do you know if the osx\_profile resource generates the actual profile on disk anywhere before processing?

---

<div class="post-metadata">

**Author:** ![trg](https://avatars.discourse-cdn.com/v4/letter/t/50afbb/32.png) [@trg](https://discourse.chef.io/u/trg)\
**Post date:** [August 3, 2016, 12:19am UTC](https://discourse.chef.io/t/ruby-block-as-a-specific-user/9064/7 "2016-08-03T00:19:05Z")

</div>

dont worry found it.

-mode-cache/cache/
