{"action":"created","issue":{"url":"https://api.github.com/repos/chef/chef/issues/4233","labels_url":"https://api.github.com/repos/chef/chef/issues/4233/labels{/name}","comments_url":"https://api.github.com/repos/chef/chef/issues/4233/comments","events_url":"https://api.github.com/repos/chef/chef/issues/4233/events","html_url":"https://github.com/chef/chef/issues/4233","id":120288695,"number":4233,"title":"knife is relying on environment variable PWD","user":{"login":"kzw","id":1887879,"avatar_url":"https://avatars.githubusercontent.com/u/1887879?v=3","gravatar_id":"","url":"https://api.github.com/users/kzw","html_url":"https://github.com/kzw","followers_url":"https://api.github.com/users/kzw/followers","following_url":"https://api.github.com/users/kzw/following{/other_user}","gists_url":"https://api.github.com/users/kzw/gists{/gist_id}","starred_url":"https://api.github.com/users/kzw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kzw/subscriptions","organizations_url":"https://api.github.com/users/kzw/orgs","repos_url":"https://api.github.com/users/kzw/repos","events_url":"https://api.github.com/users/kzw/events{/privacy}","received_events_url":"https://api.github.com/users/kzw/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-03T22:43:49Z","updated_at":"2015-12-04T00:25:30Z","closed_at":"2015-12-04T00:25:30Z","body":"The following behavior of knife is unacceptable when called from other interpreters.  My usage is in trying to come up with some mock for knife output when it is executed from python script.  But the behavior is similar when it is called from ruby.\r\n\r\nHere is the problem demostrated in ruby.  Python case is similar and discussed briefly at the bottom\r\n```\r\nirb(main):014:0> Dir.pwd\r\n=> \"/private/tmp\"\r\nirb(main):015:0>\r\nirb(main):015:0> Dir.chdir('/Users/kzwin/chef-repo') { system('pwd') }\r\n/Users/kzwin/chef-repo\r\n=> true\r\nDir.chdir('/Users/kzwin/chef-repo') { system('knife role -z list') }\r\n\r\n=> true\r\nENV['PWD'] = '/Users/kzwin/chef-repo'\r\nDir.chdir('/Users/kzwin/chef-repo') { system('knife role -z list') }\r\nroles1\r\nrole2\r\nmyrole\r\n.\r\n.\r\n.\r\n```\r\n\r\nIn python, I would like to to use `subprocess.call` or `subprocess.Popen`.  This API has the ability to set the `cwd` of the command to process.  Setting this `cwd` option to anything does not seem to have any affect on `knife`.  Only setting environment variable `PWD` does the trick.\r\n\r\nCan someone explain this behavior?  And possibly make it do the right thing?"},"comment":{"url":"https://api.github.com/repos/chef/chef/issues/comments/161832954","html_url":"https://github.com/chef/chef/issues/4233#issuecomment-161832954","issue_url":"https://api.github.com/repos/chef/chef/issues/4233","id":161832954,"user":{"login":"danielsdeleo","id":37162,"avatar_url":"https://avatars.githubusercontent.com/u/37162?v=3","gravatar_id":"","url":"https://api.github.com/users/danielsdeleo","html_url":"https://github.com/danielsdeleo","followers_url":"https://api.github.com/users/danielsdeleo/followers","following_url":"https://api.github.com/users/danielsdeleo/following{/other_user}","gists_url":"https://api.github.com/users/danielsdeleo/gists{/gist_id}","starred_url":"https://api.github.com/users/danielsdeleo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielsdeleo/subscriptions","organizations_url":"https://api.github.com/users/danielsdeleo/orgs","repos_url":"https://api.github.com/users/danielsdeleo/repos","events_url":"https://api.github.com/users/danielsdeleo/events{/privacy}","received_events_url":"https://api.github.com/users/danielsdeleo/received_events","type":"User","site_admin":false},"created_at":"2015-12-04T00:25:30Z","updated_at":"2015-12-04T00:25:30Z","body":"This is intentional. When you are relying on the path-based directory lookup, and you symlink a directory inside of that path, `Dir.pwd` reads the \"real\" path instead of the symlinked thing, which breaks the lookup. Eg., you have:\r\n\r\n* `~/my-chef-workspace/my-org` which is a real directory\r\n* `~/my-chef-workspace/my-org/.chef/knife.rb` which is the config you want to use\r\n* `~/my-chef-workspace/my-org/chef-repo` which is a symlink to somewhere else\r\n\r\nIf you `cd ~/my-chef-workspace/my-org/chef-repo` and run `knife whatever`, it should use the config `~/my-chef-workspace/my-org/.chef/knife.rb` The only way knife can do this is by inspecting `PWD`.\r\n\r\n"}}