{"action":"created","comment":{"url":"https://api.github.com/repos/roots/trellis/pulls/comments/35069424","id":35069424,"diff_hunk":"@@ -126,7 +126,7 @@ Outgoing mail is handled by sSMTP. Configure credentials in `group_vars/all`.  S\n \n ## SSL\n \n-Full SSL support is available for your WordPress sites. Our HTTPS implementation has all the best practices for performance and security. (Note: default configuration is HTTPS **only**.) See the [SSL wiki](https://github.com/roots/trellis/wiki/SSL).\n+Full SSL support is available for your WordPress sites. You can also auto-generate *self-signed* certificates for development purpose. Our HTTPS implementation has all the best practices for performance and security. (Note: default configuration is HTTPS **only**.) See the [SSL wiki](https://github.com/roots/trellis/wiki/SSL).","path":"README.md","position":14,"original_position":14,"commit_id":"c2f1b5a9da19d9edc7644c84c17f68492180772f","original_commit_id":"c2f1b5a9da19d9edc7644c84c17f68492180772f","user":{"login":"austinpray","id":2192970,"avatar_url":"https://avatars.githubusercontent.com/u/2192970?v=3","gravatar_id":"","url":"https://api.github.com/users/austinpray","html_url":"https://github.com/austinpray","followers_url":"https://api.github.com/users/austinpray/followers","following_url":"https://api.github.com/users/austinpray/following{/other_user}","gists_url":"https://api.github.com/users/austinpray/gists{/gist_id}","starred_url":"https://api.github.com/users/austinpray/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/austinpray/subscriptions","organizations_url":"https://api.github.com/users/austinpray/orgs","repos_url":"https://api.github.com/users/austinpray/repos","events_url":"https://api.github.com/users/austinpray/events{/privacy}","received_events_url":"https://api.github.com/users/austinpray/received_events","type":"User","site_admin":false},"body":">You can also auto-generate *self-signed* certificates for development purpose.\r\n\r\nTrellis will also auto-generate *self-signed* certificates for development purposes.","created_at":"2015-07-21T04:45:21Z","updated_at":"2015-07-21T04:45:21Z","html_url":"https://github.com/roots/trellis/pull/279#discussion_r35069424","pull_request_url":"https://api.github.com/repos/roots/trellis/pulls/279","_links":{"self":{"href":"https://api.github.com/repos/roots/trellis/pulls/comments/35069424"},"html":{"href":"https://github.com/roots/trellis/pull/279#discussion_r35069424"},"pull_request":{"href":"https://api.github.com/repos/roots/trellis/pulls/279"}}},"pull_request":{"url":"https://api.github.com/repos/roots/trellis/pulls/279","id":40302543,"html_url":"https://github.com/roots/trellis/pull/279","diff_url":"https://github.com/roots/trellis/pull/279.diff","patch_url":"https://github.com/roots/trellis/pull/279.patch","issue_url":"https://api.github.com/repos/roots/trellis/issues/279","number":279,"state":"open","locked":false,"title":"Allow auto-generation of self signed SSL certificate.","user":{"login":"louim","id":923718,"avatar_url":"https://avatars.githubusercontent.com/u/923718?v=3","gravatar_id":"","url":"https://api.github.com/users/louim","html_url":"https://github.com/louim","followers_url":"https://api.github.com/users/louim/followers","following_url":"https://api.github.com/users/louim/following{/other_user}","gists_url":"https://api.github.com/users/louim/gists{/gist_id}","starred_url":"https://api.github.com/users/louim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/louim/subscriptions","organizations_url":"https://api.github.com/users/louim/orgs","repos_url":"https://api.github.com/users/louim/repos","events_url":"https://api.github.com/users/louim/events{/privacy}","received_events_url":"https://api.github.com/users/louim/received_events","type":"User","site_admin":false},"body":"As discussed in #277.\r\n\r\nTLDR: When the SSL \"enabled\" key is set to true while \"key\" and \"cert\" are not provided, a self-signed certificate will be generated and used.\r\n\r\n### How I've done it\r\n1. First get all the already generated self-signed certificates, so we can prevent recreating those that already exists. Certs are named like their `wordress_sites` key instead of the domain to prevent recreating new files each time the domain is changed and to stay consistent with the folder naming conventions.\r\n1. Get the domain name of the certs gathered in step 1.\r\n1. Generate new SSL cert and key for each `wordress_sites` key \"primary\" domain  that is not in the list of domains gathered on step 2 and for which SSL is enabled\r\n1. Assign generated cert and key in nginx config for the site.\r\n\r\n### A word of warning\r\nI encountered some difficulties while preparing this PR. The main one is that if we generate self signed certificates, we need to update them if / when the domain change (I use the first domain provided in the list if the user provide more than one). We also need to take in account that the user can have multiple sites. Handling of `wordress_sites` , which is a `dict` while trying to fetch all generated certificates files (to prevent recreating them on each provisioning) proved to be a hard task. Running `with_items` or  `with_dict` while `register`ing the output will alway return an `array` of results, and I didn't find an efficient way to make it correlate to the `wordress_sites` dict.\r\n\r\nI think It came out OK in the end, but if you have a more elegant solution, or a more efficient way of doing this, I'm all ears!\r\n\r\n### The one problem\r\nThere is only one situation which is unaccounted for in the current situation: if the user has multiples sites configured on the same environment (aka multiples entries in `wordress_sites`) and decide to swap the `site_hosts` between two sites in the same provisioning run, the certs [won't change](https://github.com/roots/trellis/compare/roots:master...louim:add-snake-oil-certs?expand=1#diff-ff830fc010a506c1a47b7aba05cd8bb7R23). \r\nExample: \r\n\r\n* site1 -> *example.dev*, site2 -> **mysite.dev**\r\n\r\nchanged to:\r\n\r\n* site1 -> **mysite.dev**, site2 -> *example.dev*\r\n\r\nI think it's an  edge-case incredibly unlikely to happen, but I wanted to have your opinions on it.","created_at":"2015-07-19T03:27:56Z","updated_at":"2015-07-21T04:45:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e1c13f9fd843ee3bfa12ac3e39f46b3a9138d4f0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/roots/trellis/pulls/279/commits","review_comments_url":"https://api.github.com/repos/roots/trellis/pulls/279/comments","review_comment_url":"https://api.github.com/repos/roots/trellis/pulls/comments{/number}","comments_url":"https://api.github.com/repos/roots/trellis/issues/279/comments","statuses_url":"https://api.github.com/repos/roots/trellis/statuses/c2f1b5a9da19d9edc7644c84c17f68492180772f","head":{"label":"louim:add-snake-oil-certs","ref":"add-snake-oil-certs","sha":"c2f1b5a9da19d9edc7644c84c17f68492180772f","user":{"login":"louim","id":923718,"avatar_url":"https://avatars.githubusercontent.com/u/923718?v=3","gravatar_id":"","url":"https://api.github.com/users/louim","html_url":"https://github.com/louim","followers_url":"https://api.github.com/users/louim/followers","following_url":"https://api.github.com/users/louim/following{/other_user}","gists_url":"https://api.github.com/users/louim/gists{/gist_id}","starred_url":"https://api.github.com/users/louim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/louim/subscriptions","organizations_url":"https://api.github.com/users/louim/orgs","repos_url":"https://api.github.com/users/louim/repos","events_url":"https://api.github.com/users/louim/events{/privacy}","received_events_url":"https://api.github.com/users/louim/received_events","type":"User","site_admin":false},"repo":{"id":34757037,"name":"bedrock-ansible","full_name":"louim/bedrock-ansible","owner":{"login":"louim","id":923718,"avatar_url":"https://avatars.githubusercontent.com/u/923718?v=3","gravatar_id":"","url":"https://api.github.com/users/louim","html_url":"https://github.com/louim","followers_url":"https://api.github.com/users/louim/followers","following_url":"https://api.github.com/users/louim/following{/other_user}","gists_url":"https://api.github.com/users/louim/gists{/gist_id}","starred_url":"https://api.github.com/users/louim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/louim/subscriptions","organizations_url":"https://api.github.com/users/louim/orgs","repos_url":"https://api.github.com/users/louim/repos","events_url":"https://api.github.com/users/louim/events{/privacy}","received_events_url":"https://api.github.com/users/louim/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/louim/bedrock-ansible","description":"Ansible playbooks for a Bedrock based WordPress LEMP app server","fork":true,"url":"https://api.github.com/repos/louim/bedrock-ansible","forks_url":"https://api.github.com/repos/louim/bedrock-ansible/forks","keys_url":"https://api.github.com/repos/louim/bedrock-ansible/keys{/key_id}","collaborators_url":"https://api.github.com/repos/louim/bedrock-ansible/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/louim/bedrock-ansible/teams","hooks_url":"https://api.github.com/repos/louim/bedrock-ansible/hooks","issue_events_url":"https://api.github.com/repos/louim/bedrock-ansible/issues/events{/number}","events_url":"https://api.github.com/repos/louim/bedrock-ansible/events","assignees_url":"https://api.github.com/repos/louim/bedrock-ansible/assignees{/user}","branches_url":"https://api.github.com/repos/louim/bedrock-ansible/branches{/branch}","tags_url":"https://api.github.com/repos/louim/bedrock-ansible/tags","blobs_url":"https://api.github.com/repos/louim/bedrock-ansible/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/louim/bedrock-ansible/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/louim/bedrock-ansible/git/refs{/sha}","trees_url":"https://api.github.com/repos/louim/bedrock-ansible/git/trees{/sha}","statuses_url":"https://api.github.com/repos/louim/bedrock-ansible/statuses/{sha}","languages_url":"https://api.github.com/repos/louim/bedrock-ansible/languages","stargazers_url":"https://api.github.com/repos/louim/bedrock-ansible/stargazers","contributors_url":"https://api.github.com/repos/louim/bedrock-ansible/contributors","subscribers_url":"https://api.github.com/repos/louim/bedrock-ansible/subscribers","subscription_url":"https://api.github.com/repos/louim/bedrock-ansible/subscription","commits_url":"https://api.github.com/repos/louim/bedrock-ansible/commits{/sha}","git_commits_url":"https://api.github.com/repos/louim/bedrock-ansible/git/commits{/sha}","comments_url":"https://api.github.com/repos/louim/bedrock-ansible/comments{/number}","issue_comment_url":"https://api.github.com/repos/louim/bedrock-ansible/issues/comments{/number}","contents_url":"https://api.github.com/repos/louim/bedrock-ansible/contents/{+path}","compare_url":"https://api.github.com/repos/louim/bedrock-ansible/compare/{base}...{head}","merges_url":"https://api.github.com/repos/louim/bedrock-ansible/merges","archive_url":"https://api.github.com/repos/louim/bedrock-ansible/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/louim/bedrock-ansible/downloads","issues_url":"https://api.github.com/repos/louim/bedrock-ansible/issues{/number}","pulls_url":"https://api.github.com/repos/louim/bedrock-ansible/pulls{/number}","milestones_url":"https://api.github.com/repos/louim/bedrock-ansible/milestones{/number}","notifications_url":"https://api.github.com/repos/louim/bedrock-ansible/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/louim/bedrock-ansible/labels{/name}","releases_url":"https://api.github.com/repos/louim/bedrock-ansible/releases{/id}","created_at":"2015-04-28T21:33:49Z","updated_at":"2015-04-28T21:33:49Z","pushed_at":"2015-07-19T16:44:34Z","git_url":"git://github.com/louim/bedrock-ansible.git","ssh_url":"git@github.com:louim/bedrock-ansible.git","clone_url":"https://github.com/louim/bedrock-ansible.git","svn_url":"https://github.com/louim/bedrock-ansible","homepage":"https://roots.io/bedrock/","size":437,"stargazers_count":0,"watchers_count":0,"language":"Shell","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"roots:master","ref":"master","sha":"b489566df97f9234d269c5a1e4c17958ecbed3df","user":{"login":"roots","id":4986074,"avatar_url":"https://avatars.githubusercontent.com/u/4986074?v=3","gravatar_id":"","url":"https://api.github.com/users/roots","html_url":"https://github.com/roots","followers_url":"https://api.github.com/users/roots/followers","following_url":"https://api.github.com/users/roots/following{/other_user}","gists_url":"https://api.github.com/users/roots/gists{/gist_id}","starred_url":"https://api.github.com/users/roots/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roots/subscriptions","organizations_url":"https://api.github.com/users/roots/orgs","repos_url":"https://api.github.com/users/roots/repos","events_url":"https://api.github.com/users/roots/events{/privacy}","received_events_url":"https://api.github.com/users/roots/received_events","type":"Organization","site_admin":false},"repo":{"id":18852165,"name":"trellis","full_name":"roots/trellis","owner":{"login":"roots","id":4986074,"avatar_url":"https://avatars.githubusercontent.com/u/4986074?v=3","gravatar_id":"","url":"https://api.github.com/users/roots","html_url":"https://github.com/roots","followers_url":"https://api.github.com/users/roots/followers","following_url":"https://api.github.com/users/roots/following{/other_user}","gists_url":"https://api.github.com/users/roots/gists{/gist_id}","starred_url":"https://api.github.com/users/roots/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roots/subscriptions","organizations_url":"https://api.github.com/users/roots/orgs","repos_url":"https://api.github.com/users/roots/repos","events_url":"https://api.github.com/users/roots/events{/privacy}","received_events_url":"https://api.github.com/users/roots/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/roots/trellis","description":"Ansible playbooks for a Bedrock based WordPress LEMP app server","fork":false,"url":"https://api.github.com/repos/roots/trellis","forks_url":"https://api.github.com/repos/roots/trellis/forks","keys_url":"https://api.github.com/repos/roots/trellis/keys{/key_id}","collaborators_url":"https://api.github.com/repos/roots/trellis/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/roots/trellis/teams","hooks_url":"https://api.github.com/repos/roots/trellis/hooks","issue_events_url":"https://api.github.com/repos/roots/trellis/issues/events{/number}","events_url":"https://api.github.com/repos/roots/trellis/events","assignees_url":"https://api.github.com/repos/roots/trellis/assignees{/user}","branches_url":"https://api.github.com/repos/roots/trellis/branches{/branch}","tags_url":"https://api.github.com/repos/roots/trellis/tags","blobs_url":"https://api.github.com/repos/roots/trellis/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/roots/trellis/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/roots/trellis/git/refs{/sha}","trees_url":"https://api.github.com/repos/roots/trellis/git/trees{/sha}","statuses_url":"https://api.github.com/repos/roots/trellis/statuses/{sha}","languages_url":"https://api.github.com/repos/roots/trellis/languages","stargazers_url":"https://api.github.com/repos/roots/trellis/stargazers","contributors_url":"https://api.github.com/repos/roots/trellis/contributors","subscribers_url":"https://api.github.com/repos/roots/trellis/subscribers","subscription_url":"https://api.github.com/repos/roots/trellis/subscription","commits_url":"https://api.github.com/repos/roots/trellis/commits{/sha}","git_commits_url":"https://api.github.com/repos/roots/trellis/git/commits{/sha}","comments_url":"https://api.github.com/repos/roots/trellis/comments{/number}","issue_comment_url":"https://api.github.com/repos/roots/trellis/issues/comments{/number}","contents_url":"https://api.github.com/repos/roots/trellis/contents/{+path}","compare_url":"https://api.github.com/repos/roots/trellis/compare/{base}...{head}","merges_url":"https://api.github.com/repos/roots/trellis/merges","archive_url":"https://api.github.com/repos/roots/trellis/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/roots/trellis/downloads","issues_url":"https://api.github.com/repos/roots/trellis/issues{/number}","pulls_url":"https://api.github.com/repos/roots/trellis/pulls{/number}","milestones_url":"https://api.github.com/repos/roots/trellis/milestones{/number}","notifications_url":"https://api.github.com/repos/roots/trellis/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/roots/trellis/labels{/name}","releases_url":"https://api.github.com/repos/roots/trellis/releases{/id}","created_at":"2014-04-16T19:08:33Z","updated_at":"2015-07-21T01:32:55Z","pushed_at":"2015-07-21T01:10:53Z","git_url":"git://github.com/roots/trellis.git","ssh_url":"git@github.com:roots/trellis.git","clone_url":"https://github.com/roots/trellis.git","svn_url":"https://github.com/roots/trellis","homepage":"https://roots.io/trellis/","size":2438,"stargazers_count":347,"watchers_count":347,"language":"Shell","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":132,"mirror_url":null,"open_issues_count":15,"forks":132,"open_issues":15,"watchers":347,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/roots/trellis/pulls/279"},"html":{"href":"https://github.com/roots/trellis/pull/279"},"issue":{"href":"https://api.github.com/repos/roots/trellis/issues/279"},"comments":{"href":"https://api.github.com/repos/roots/trellis/issues/279/comments"},"review_comments":{"href":"https://api.github.com/repos/roots/trellis/pulls/279/comments"},"review_comment":{"href":"https://api.github.com/repos/roots/trellis/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/roots/trellis/pulls/279/commits"},"statuses":{"href":"https://api.github.com/repos/roots/trellis/statuses/c2f1b5a9da19d9edc7644c84c17f68492180772f"}}}}