{"action":"created","issue":{"url":"https://api.github.com/repos/roots/trellis/issues/268","labels_url":"https://api.github.com/repos/roots/trellis/issues/268/labels{/name}","comments_url":"https://api.github.com/repos/roots/trellis/issues/268/comments","events_url":"https://api.github.com/repos/roots/trellis/issues/268/events","html_url":"https://github.com/roots/trellis/pull/268","id":93927470,"number":268,"title":"Conditionally copy .env into web root","user":{"login":"fullyint","id":7338513,"avatar_url":"https://avatars.githubusercontent.com/u/7338513?v=3","gravatar_id":"","url":"https://api.github.com/users/fullyint","html_url":"https://github.com/fullyint","followers_url":"https://api.github.com/users/fullyint/followers","following_url":"https://api.github.com/users/fullyint/following{/other_user}","gists_url":"https://api.github.com/users/fullyint/gists{/gist_id}","starred_url":"https://api.github.com/users/fullyint/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fullyint/subscriptions","organizations_url":"https://api.github.com/users/fullyint/orgs","repos_url":"https://api.github.com/users/fullyint/repos","events_url":"https://api.github.com/users/fullyint/events{/privacy}","received_events_url":"https://api.github.com/users/fullyint/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-07-09T01:24:47Z","updated_at":"2015-07-09T10:30:34Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/roots/trellis/pulls/268","html_url":"https://github.com/roots/trellis/pull/268","diff_url":"https://github.com/roots/trellis/pull/268.diff","patch_url":"https://github.com/roots/trellis/pull/268.patch"},"body":"closes #261\r\n`.env` was always being created (in `/tmp`) when `env` vars changed in `group_vars/development`. However, `.env` was only being copied into web root if there wasn't already an `.env` file there.\r\n\r\nWith these changes, `.env` will always be copied into place if a new `.env` is created, any time `env` vars are changed in `group_vars/development`. Still idempotent.\r\n\r\n---------\r\nEdit: The next several comments were reacting to these original PR changes:\r\n```diff\r\n - name: Create .env file\r\n   template: src=\"env.j2\"\r\n             dest=\"/tmp/{{ item.key }}.env\"\r\n             owner=\"{{ web_user }}\"\r\n             group=\"{{ web_group }}\"\r\n   with_dict: wordpress_sites\r\n+  register: env\r\n \r\n - name: Copy .env file into web root\r\n-  command: creates=\"{{ www_root }}/{{ item.key }}/current/.env\" cp /tmp/{{ item.key }}.env {{ www_root }}/{{ item.key }}/current/.env\r\n+  command: cp /tmp/{{ item.key }}.env {{ www_root }}/{{ item.key }}/current/.env\r\n   with_dict: wordpress_sites\r\n+  when: env.changed\r\n```"},"comment":{"url":"https://api.github.com/repos/roots/trellis/issues/comments/119903331","html_url":"https://github.com/roots/trellis/pull/268#issuecomment-119903331","issue_url":"https://api.github.com/repos/roots/trellis/issues/268","id":119903331,"user":{"login":"fullyint","id":7338513,"avatar_url":"https://avatars.githubusercontent.com/u/7338513?v=3","gravatar_id":"","url":"https://api.github.com/users/fullyint","html_url":"https://github.com/fullyint","followers_url":"https://api.github.com/users/fullyint/followers","following_url":"https://api.github.com/users/fullyint/following{/other_user}","gists_url":"https://api.github.com/users/fullyint/gists{/gist_id}","starred_url":"https://api.github.com/users/fullyint/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fullyint/subscriptions","organizations_url":"https://api.github.com/users/fullyint/orgs","repos_url":"https://api.github.com/users/fullyint/repos","events_url":"https://api.github.com/users/fullyint/events{/privacy}","received_events_url":"https://api.github.com/users/fullyint/received_events","type":"User","site_admin":false},"created_at":"2015-07-09T10:30:34Z","updated_at":"2015-07-09T10:30:34Z","body":"@austinpray and science have prevailed, transforming this PR from \"seems right,\" to \"yeah, that's it.\"\r\n\r\n**Debrief.** The above test results mystified me till I caught my mistaken assumption that the template module would check the `env` vars against the `.env` file in the web root. But of course, the template module only checks the `env` vars against the file it creates, which is actually in `/tmp`. \r\n\r\n- Tests above start by provisioning: **create** original `.env` file (correct `env` values), **copy** it to web root\r\n- Change `env` values, reprovision: **create** works, but **copy** never runs -- the original problem to solve\r\n- Switch to original PR code, reprovision: **create** skips because `.env` in `/tmp` already matches modified `env` vars (leftover from steps above), **copy** skips too -- PR made it conditional on **create**\r\n- Change to completely new `env` values, reprovision: fullyint code runs both the **create** and **copy**\r\n- For science, directly edit web root `.env` so it differs from `env` vars, reprovision: **create** doesn't run because `env` vars still match the `.env` file in `/tmp`, and thus **copy** doesn't run. Problem persists.\r\n\r\n**Moving on.** I revised the PR to run **copy** any time the `env` vars differ from the `.env` file in the web root. The tasks will continue to ensure that `/tmp` always has a `.env` file matching the `env` vars (**creating** one if necessary), and now will always **copy** it to the web root if it differs from what is in the web root.\r\n\r\nIn the beginning, @swalkinshaw casually said: \"could do a local rsync,\" and that's where I ended up. I switched the **copy** task to use rsync, but it still uses the command module because I couldn't manage to adapt the synchronize or copy modules to have both src and dest on the remote server. The command module always runs, but the task remains idempotent, only `changed_when` the file is actually synced.  "}}