{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/908","labels_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/908/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/908/comments","events_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/908/events","html_url":"https://github.com/ansible/ansible-modules-extras/issues/908","id":104338371,"number":908,"title":"win_environment changes don't take into effect until after user logout","user":{"login":"synapticarbors","id":589279,"avatar_url":"https://avatars.githubusercontent.com/u/589279?v=3","gravatar_id":"","url":"https://api.github.com/users/synapticarbors","html_url":"https://github.com/synapticarbors","followers_url":"https://api.github.com/users/synapticarbors/followers","following_url":"https://api.github.com/users/synapticarbors/following{/other_user}","gists_url":"https://api.github.com/users/synapticarbors/gists{/gist_id}","starred_url":"https://api.github.com/users/synapticarbors/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/synapticarbors/subscriptions","organizations_url":"https://api.github.com/users/synapticarbors/orgs","repos_url":"https://api.github.com/users/synapticarbors/repos","events_url":"https://api.github.com/users/synapticarbors/events{/privacy}","received_events_url":"https://api.github.com/users/synapticarbors/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-01T19:36:18Z","updated_at":"2015-09-01T20:40:20Z","closed_at":null,"body":"Issue Type:\r\n\r\n- Bug Report\r\n\r\nAnsible Version: \r\n\r\n```\r\nansible 1.9.2\r\n  configured module search path = None\r\n```\r\n\r\nI attempted to test this off of the latest `devel` branch, but I was getting WinRM ssl errors that weren't resolved using the callback plugin that has been mentioned on the Google Group, and which works for `v1.9.2`.\r\n\r\nAnsible Configuration:\r\n\r\n```\r\n[defaults]\r\ncallback_plugins=<path stuff>/test-ansible/callback_plugins\r\n```\r\n\r\nEnvironment:\r\n\r\nRunning Ansible off of OSX 10.9.6, targeting a Windows server 2012 R2 \r\n\r\nSummary:\r\n\r\nThe `win_environment` module appears to successfully set an environment variable, but the env variable is not visible on the target machine until the user logs out and then logs back in. \r\n\r\nSteps To Reproduce:\r\n\r\nI copied the `win_environment` module (both `.py` and `.ps1` files) into `./library` since they are only available in v2 (see above). I then use that module in a task to set an environment variable as:\r\n\r\n```\r\n---\r\n- name: Test ansible\r\n  hosts: windows\r\n  remote_user: deploy\r\n  tasks:\r\n    - name: Set ABC environment variable\r\n      win_environment:\r\n          state: present\r\n          name: 'ABC'\r\n          value: \"{{ abc }}\"\r\n          level: User\r\n```\r\n\r\n\r\nExpected Results:\r\n\r\nI expect that given a fresh powershell that `$env:ABC` will be the value provided in the playbook. \r\n\r\nActual Results:\r\n\r\nIf `ABC` is not set on the target machine, I get a result as:\r\n\r\n```\r\nok: [win_machine] => {\"before_value\": \"null\", \"changed\": true, \"level\": \"user\", \"name\": \"ABC\", \"value\": \"xxx\"}\r\n```\r\n\r\nSwitching over to an RDP on `win_machine`, `ABC` is not set. Re-running the ansible play, I get:\r\n\r\n```\r\nok: [win_machine] => {\"before_value\": \"xxx\", \"changed\": false, \"level\": \"user\", \"name\": \"ABC\", \"value\": \"xxx\"}\r\n```\r\n\r\nso, the new value is being stored somewhere. \r\n\r\n\r\nIf on the Windows machine I run either `setx ABC yyy` from a command prompt or `[Environment]::SetEnvironmentVariable('ABC', 'yyy', 'User')` from the powershell, and then re-run the ansible task on my OSX machine, I get:\r\n\r\n```\r\nok: [win_machine] => {\"before_value\": \"yyy\", \"changed\": true, \"level\": \"user\", \"name\": \"ABC\", \"value\": \"xxx\"}\r\n```\r\n\r\nHowever, again, the change isn't reflected on the machine after starting up a new powershell terminal. The only way to get the value pushed by Ansible to be reflected on the user machine is to log the user off and then log them back on. This doesn't seem to be the correct behavior, or at least not what I'd anticipate given how running similar commands locally on the target machine in a script behaves. \r\n\r\nIt seems like the Windows machine is holding the values that Ansible pushed in some sort of temporary registry that doesn't get flushed until a logout. Restarting the WinRM service doesn't seem to effect things. I can run a script on the Windows machine that just contains:\r\n\r\n```\r\n[Environment]::SetEnvironmentVariable('ABC', 'xxx', 'User')\r\n```\r\n\r\nand that takes hold immediately once you fire up a new powershell. "},"comment":{"url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/comments/136854807","html_url":"https://github.com/ansible/ansible-modules-extras/issues/908#issuecomment-136854807","issue_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/908","id":136854807,"user":{"login":"jhawkesworth","id":8440323,"avatar_url":"https://avatars.githubusercontent.com/u/8440323?v=3","gravatar_id":"","url":"https://api.github.com/users/jhawkesworth","html_url":"https://github.com/jhawkesworth","followers_url":"https://api.github.com/users/jhawkesworth/followers","following_url":"https://api.github.com/users/jhawkesworth/following{/other_user}","gists_url":"https://api.github.com/users/jhawkesworth/gists{/gist_id}","starred_url":"https://api.github.com/users/jhawkesworth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jhawkesworth/subscriptions","organizations_url":"https://api.github.com/users/jhawkesworth/orgs","repos_url":"https://api.github.com/users/jhawkesworth/repos","events_url":"https://api.github.com/users/jhawkesworth/events{/privacy}","received_events_url":"https://api.github.com/users/jhawkesworth/received_events","type":"User","site_admin":false},"created_at":"2015-09-01T20:40:20Z","updated_at":"2015-09-01T20:40:20Z","body":"Interesting... my playbooks haven't had cause to use User level yet.\r\nDid a bit of digging and I think it may need a code change to broadcast a setting change event - see https://social.msdn.microsoft.com/Forums/windows/en-US/ce540c7d-a113-4f39-956e-0af6bc91abd3/force-updaterefresh-of-windows-start-menu?forum=winforms \r\n\r\nHowever, it looks like its up to other applications to notice and react to the setting change event so won't know till its implemented if it will fix.  "}}