├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── Vagrantfile ├── ansible.cfg ├── defaults └── main.yml ├── handlers └── main.yml ├── meta └── main.yml ├── tasks ├── config.yml ├── install.yml ├── install │ ├── Debian.yml │ └── RedHat.yml ├── main.yml └── service.yml ├── templates └── etc │ ├── ipsec.conf.j2 │ └── ipsec.secrets.j2 ├── tests ├── test_config.yml ├── test_defaults.yml └── test_vagrant.yml └── vars ├── Debian.yml └── RedHat.yml /.gitignore: -------------------------------------------------------------------------------- 1 | *.swa 2 | *.swp 3 | *.swo 4 | 5 | vagrant 6 | .vagrant 7 | 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: python 3 | python: "2.7" 4 | 5 | notifications: 6 | webhooks: https://galaxy.ansible.com/api/v1/notifications/ 7 | 8 | before_install: 9 | - sudo apt-get update -qq 10 | 11 | install: 12 | - sudo pip install ansible==2.3.0.0 13 | 14 | script: 15 | # Test functionality with default values 16 | - ansible-playbook tests/test_defaults.yml -i localhost, --syntax-check 17 | - ansible-playbook tests/test_defaults.yml -i localhost, --connection=local --sudo 18 | 19 | # vi:ts=2:sw=2:et:ft=yaml 20 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 2017-05-24: 0.1.1 4 | 5 | - Amazon linux is not supported due to package dependency issues 6 | - Fixed ipsec.conf typo (`config` instead of `conn`) 7 | - Fixed binary prefix for Debian like systems 8 | - Skip handlers on the first run of the role (based on package installation) 9 | - Don't expand booleans 10 | 11 | ## 2017-05-23: 0.1.0 12 | 13 | - Initial release 14 | 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ansible role for StrongSwan 2 | 3 | [![Build Status](https://travis-ci.org/torian/ansible-role-strongswan.svg)](https://travis-ci.org/torian/ansible-role-strongswan) 4 | 5 | An Ansible Role that installs and configures StrongSwan on Red Hat/CentOS or Debian/Ubuntu. 6 | 7 | ## Tested On 8 | 9 | * EL / Centos (7 / 6) 10 | * Ubuntu (Xenial / Trusty / Precise) 11 | 12 | 13 | ## Role Variables 14 | 15 | Defaults defined in `defaults/main.yml`: 16 | 17 | ``` 18 | strongswan_config_file: {{strongswan_prefix}}/ipsec.conf 19 | strongswan_secrets_file: {{strongswan_prefix}}/ipsec.secrets 20 | ``` 21 | 22 | The var `strongswan_prefix` is defined based on `ansible_os_family`. 23 | 24 | The `ipsec.conf` file is configured through the following vars (and their default values): 25 | 26 | ``` 27 | strongswan_config_setup: 28 | uniqueids: yes 29 | charonstart: yes 30 | charondebug: '' 31 | 32 | strongswan_conn_default: {} 33 | 34 | strongswan_conns: {} 35 | ``` 36 | 37 | Secrets are specified using `strongswan_secrets`. It is a list where each 38 | element might contain the following attributes: 39 | ``` 40 | left: Optional - Any valid ID selector 41 | right: Optional - Any valid ID selector 42 | type: Optional (defaults to PSK) - any valid secret type 43 | credential: Required - Connection's credentials 44 | ``` 45 | 46 | ## Usage 47 | 48 | The vars used for the `config setup` and `conn %default` sections are a hash that accept 49 | any valid configuration option for strongswan. An example: 50 | 51 | ``` 52 | strongswan_conn_default: 53 | type: tunnel 54 | ikelifetime: 1h 55 | lifetime: 30m 56 | left: 1.2.3.4 57 | ``` 58 | 59 | Connections are configured with `strongswan_conns` hash: 60 | 61 | ``` 62 | strongswan_conns: 63 | conn1: 64 | right: 2.3.4.5 65 | rightsubnet: 2.3.4.0/24 66 | ike: aes256-sha1-modp1024 67 | esp: aes256-sha1-modp1024 68 | auto: start 69 | 70 | conn2: 71 | right: 3.4.5.6 72 | rightsubnet: 3.4.5.0/24 73 | auto: route 74 | ``` 75 | 76 | Setting up secrets can be done in the following way: 77 | 78 | ``` 79 | strongswan_secrets: 80 | - left: 1.2.3.4 81 | right: 2.3.4.5 82 | type: PSK 83 | credentials: '"super wooper passw0rd"' 84 | 85 | - right: 3.4.5.6 86 | type: RSA 87 | credentials: cert.pem 88 | ``` 89 | 90 | The double quotes inside the simple ones is meant to escape any special chars. 91 | 92 | `RSA` private keys (or any secret type that requires a key file) might be specified 93 | through `strongswan_private_keys` (TODO): 94 | 95 | ``` 96 | strongswan_private_keys: 97 | - filename: cert.pem 98 | key: | 99 | --- begin your key --- 100 | --- end your key --- 101 | - filename: more_secure.pem 102 | key: "{{var_from_a_vault}}" 103 | ``` 104 | 105 | ## License 106 | 107 | See [License](LICENSE) 108 | 109 | 110 | ## Author Information 111 | 112 | This role was created in 2017 by Emiliano Castagnari. 113 | 114 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | VAGRANTFILE_API_VERSION = '2' 2 | 3 | ANSIBLE_VERSION = "2.3.0.0" 4 | 5 | ANSIBLE_ROLE = 'ansible-role-strongswan' 6 | 7 | EPEL_REPO_6 = ''' 8 | [epel] 9 | name = EPEL 6 - \$basearch 10 | baseurl = http://mirror.globo.com/epel/6/\$basearch 11 | enabled = 1 12 | gpgcheck = 0 13 | ''' 14 | 15 | EPEL_REPO_7 = ''' 16 | [epel] 17 | name = EPEL 7 - \$basearch 18 | baseurl = http://mirror.globo.com/epel/7/\$basearch 19 | enabled = 1 20 | gpgcheck = 0 21 | ''' 22 | 23 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 24 | 25 | config.vm.provider :virtualbox do |vb| 26 | vb.gui = false 27 | vb.customize [ 'modifyvm', :id, '--memory', '512' ] 28 | vb.customize [ 'modifyvm', :id, '--nictype1', 'virtio' ] 29 | vb.customize [ 'modifyvm', :id, '--natdnshostresolver1', 'on' ] 30 | vb.customize [ 'modifyvm', :id, '--natdnsproxy1', 'on' ] 31 | end 32 | 33 | config.vm.define 'ubuntu-xenial' do |ubuntu_x| 34 | ubuntu_x.vm.box = 'ubuntu/xenial64' 35 | #ubuntu_x.vm.hostname = 'ubuntu-xenial' 36 | 37 | ubuntu_x.vm.provision 'shell', inline: 'apt-get update' 38 | ubuntu_x.vm.provision 'shell', inline: 'apt-get install -y -qq python-pip libffi-dev libssl-dev python-dev' 39 | ubuntu_x.vm.provision 'shell', inline: "pip install -q ansible==#{ANSIBLE_VERSION} jinja2" 40 | ubuntu_x.vm.provision 'shell', inline: "ln -sf /vagrant /vagrant/#{ANSIBLE_ROLE}" 41 | 42 | ubuntu_x.vm.provision 'ansible_local' do |ansible| 43 | ansible.playbook = 'tests/test_vagrant.yml' 44 | end 45 | 46 | end 47 | 48 | config.vm.define 'ubuntu-trusty' do |ubuntu_t| 49 | ubuntu_t.vm.box = 'ubuntu/trusty64' 50 | ubuntu_t.vm.hostname = 'ubuntu-trusty' 51 | 52 | ubuntu_t.vm.provision 'shell', inline: 'apt-get update' 53 | ubuntu_t.vm.provision 'shell', inline: 'apt-get install -y -qq python-pip libffi-dev libssl-dev python-dev' 54 | ubuntu_t.vm.provision 'shell', inline: "pip install -q ansible==#{ANSIBLE_VERSION} ansible-lint jinja2" 55 | ubuntu_t.vm.provision 'shell', inline: "ln -sf /vagrant /vagrant/#{ANSIBLE_ROLE}" 56 | 57 | ubuntu_t.vm.provision 'ansible_local' do |ansible| 58 | ansible.playbook = 'tests/test_vagrant.yml' 59 | ansible.extra_vars = { 60 | } 61 | end 62 | 63 | end 64 | 65 | config.vm.define 'ubuntu-precise' do |ubuntu_p| 66 | ubuntu_p.vm.box = 'ubuntu/precise64' 67 | ubuntu_p.vm.hostname = 'ubuntu-precise' 68 | 69 | ubuntu_p.vm.provision 'shell', inline: 'apt-get update' 70 | ubuntu_p.vm.provision 'shell', inline: 'apt-get install -y -qq python-pip libffi-dev libssl-dev python-dev' 71 | ubuntu_p.vm.provision 'shell', inline: "pip install -q ansible==#{ANSIBLE_VERSION} ansible-lint jinja2" 72 | ubuntu_p.vm.provision 'shell', inline: "ln -sf /vagrant /vagrant/#{ANSIBLE_ROLE}" 73 | 74 | ubuntu_p.vm.provision 'ansible_local' do |ansible| 75 | ansible.playbook = 'tests/test_vagrant.yml' 76 | ansible.extra_vars = { 77 | } 78 | end 79 | 80 | end 81 | 82 | config.vm.define 'centos-7' do |centos7| 83 | centos7.vm.box = 'centos/7' 84 | centos7.vm.hostname = 'centos-7' 85 | 86 | centos7.vm.provision 'shell', inline: 'yum install -y ca-certificates' 87 | centos7.vm.provision 'shell', inline: "echo \"#{EPEL_REPO_7}\" > /etc/yum.repos.d/epel.repo" 88 | centos7.vm.provision 'shell', inline: 'yum install -y python-pip python-devel gcc libffi-devel openssl-devel' 89 | centos7.vm.provision 'shell', inline: "pip install -q pip --upgrade" 90 | centos7.vm.provision 'shell', inline: "pip install -q ansible==#{ANSIBLE_VERSION} ansible-lint jinja2" 91 | centos7.vm.provision 'shell', inline: "ln -sf /vagrant /vagrant/#{ANSIBLE_ROLE}" 92 | 93 | centos7.vm.provision 'ansible_local' do |ansible| 94 | ansible.playbook = 'tests/test_vagrant.yml' 95 | ansible.extra_vars = { 96 | } 97 | end 98 | end 99 | 100 | config.vm.define 'centos-6' do |centos6| 101 | centos6.vm.box = "puppetlabs/centos-6.6-64-nocm" 102 | centos6.vm.hostname = 'centos-6' 103 | 104 | centos6.vm.provision 'shell', inline: 'yum install -y ca-certificates' 105 | centos6.vm.provision 'shell', inline: "echo \"#{EPEL_REPO_6}\" > /etc/yum.repos.d/epel.repo" 106 | centos6.vm.provision 'shell', inline: 'yum install -y python-pip python-devel gcc libffi-devel openssl-devel' 107 | centos6.vm.provision 'shell', inline: "pip install -q pip --upgrade" 108 | centos6.vm.provision 'shell', inline: "pip install -q ansible==#{ANSIBLE_VERSION} ansible-lint jinja2" 109 | 110 | centos6.vm.provision 'ansible_local' do |ansible| 111 | ansible.playbook = 'tests/test_vagrant.yml' 112 | ansible.extra_vars = { 113 | } 114 | end 115 | end 116 | 117 | end 118 | 119 | # vi:ts=2:sw=2:et:ft=ruby: 120 | -------------------------------------------------------------------------------- /ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | roles_path=../ 3 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | strongswan_config_file: "{{strongswan_prefix}}/ipsec.conf" 4 | 5 | strongswan_secrets_file: "{{strongswan_prefix}}/ipsec.secrets" 6 | 7 | strongswan_config_setup: 8 | uniqueids: 'yes' 9 | charonstart: 'yes' 10 | charondebug: '' 11 | 12 | # strongswan_conn_default: Defaults for connections 13 | # This will populate the default conn (%default) 14 | # An example can be: 15 | # 16 | # strongswan_conn_default: 17 | # type: tunnel 18 | # ikelifetime: 1h 19 | # lifetime: 30m 20 | # left: 1.2.3.4 21 | # 22 | strongswan_conn_default: {} 23 | 24 | # strongswan_conns: Dict to specify connections 25 | # Each key represents the name of a connection. The subelemets that the 26 | # connection has is any valid directive for a connection 27 | # 28 | # strongswan_conns: 29 | # conn1: 30 | # right: 2.3.4.5 31 | # rightsubnet: 2.3.4.0/24 32 | # ike: aes256-sha1-modp1024 33 | # esp: aes256-sha1-modp1024 34 | # auto: start 35 | # 36 | strongswan_conns: {} 37 | 38 | # strongswan_secrets: List of secrets to define 39 | # A list that contains the following attributes: 40 | # left: Optional - Any valid ID selector 41 | # right: Optional - Any valid ID selector 42 | # type: Optional (defaults to PSK) - any valid secret type 43 | # credential: Required - Connection's credentials 44 | # 45 | # strongswan_secrets: 46 | # - left: 1.2.3.4 47 | # right: 2.3.4.5 48 | # type: PSK 49 | # credentials: '"some private PSK here"' 50 | # 51 | 52 | strongswan_secrets: [] 53 | 54 | # vi:ts=2:sw=2:et:ft=yaml 55 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: ipsec reload 4 | command: > 5 | {{strongswan_ipsec_bin}} reload 6 | when: not (_strongswan_pkgs|changed) 7 | 8 | - name: ipsec secrets reload 9 | command: > 10 | {{strongswan_ipsec_bin}} rereadsecrets 11 | when: not (_strongswan_pkgs|changed) 12 | 13 | 14 | # vi:ts=2:sw=2:et:ft=yaml 15 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: Emiliano Castagnari 4 | description: Ansible role for StrongSwan 5 | license: Apache 6 | min_ansible_version: 2.3 7 | platforms: 8 | - name: EL 9 | versions: 10 | - 6 11 | - 7 12 | - name: Debian 13 | versions: 14 | - wheezy 15 | - name: Ubuntu 16 | versions: 17 | - precise 18 | - trusty 19 | - xenial 20 | 21 | galaxy_tags: 22 | - system 23 | - security 24 | 25 | dependencies: [] 26 | -------------------------------------------------------------------------------- /tasks/config.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Strongswan ipsec.conf 4 | template: 5 | src: etc/ipsec.conf.j2 6 | dest: "{{strongswan_config_file}}" 7 | owner: "root" 8 | group: "root" 9 | mode: "0644" 10 | notify: ipsec reload 11 | 12 | - name: Strongswan ipsec.secrets 13 | template: 14 | src: etc/ipsec.secrets.j2 15 | dest: "{{strongswan_secrets_file}}" 16 | owner: "root" 17 | group: "root" 18 | mode: "0640" 19 | notify: ipsec secrets reload 20 | 21 | # vi:ts=2:sw=2:et:ft=yaml 22 | -------------------------------------------------------------------------------- /tasks/install.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - include: "install/{{ansible_os_family}}.yml" 4 | 5 | - name: Strongswan packages 6 | package: 7 | name: "{{item}}" 8 | state: present 9 | with_items: "{{strongswan_packages}}" 10 | register: _strongswan_pkgs 11 | 12 | # vi:ts=2:sw=2:et:ft=yaml 13 | -------------------------------------------------------------------------------- /tasks/install/Debian.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | # vi:ts=2:sw=2:et:ft=yaml 4 | -------------------------------------------------------------------------------- /tasks/install/RedHat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: EPEL Repository (RedHat) 4 | yum: 5 | name: "{{strongswan_epel_url}}" 6 | state: present 7 | 8 | # vi:ts=2:sw=2:et:ft=yaml 9 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Include OS Family vars 4 | include_vars: "{{ansible_os_family}}.yml" 5 | tags: always 6 | 7 | - include: install.yml 8 | tags: strongswan_install 9 | 10 | - include: config.yml 11 | tags: strongswan_config 12 | 13 | - include: service.yml 14 | tags: strongswan_service 15 | 16 | # vi:ts=2:sw=2:et:ft=yaml 17 | -------------------------------------------------------------------------------- /tasks/service.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Enable Strongswan at boot 4 | service: 5 | name: strongswan 6 | enabled: true 7 | state: started 8 | 9 | # vi:ts=2:sw=2:et:ft=yaml 10 | -------------------------------------------------------------------------------- /templates/etc/ipsec.conf.j2: -------------------------------------------------------------------------------- 1 | # << Ansible managed file >> 2 | # {{strongswan_config_file}} - strongSwan IPsec configuration file 3 | 4 | config setup 5 | {% for k,v in strongswan_config_setup.items() %} 6 | {{k}}={{v}} 7 | {% endfor %} 8 | 9 | conn %default 10 | {% for k,v in strongswan_conn_default.items() %} 11 | {{k}}={{v}} 12 | {% endfor %} 13 | 14 | {% for conn,conn_settings in strongswan_conns.items() %} 15 | conn {{conn}} 16 | {% for k,v in conn_settings.items() %} 17 | {{k}}={{v}} 18 | {% endfor %} 19 | 20 | {% endfor %} 21 | 22 | -------------------------------------------------------------------------------- /templates/etc/ipsec.secrets.j2: -------------------------------------------------------------------------------- 1 | # << Ansible managed file >> 2 | # {{strongswan_secrets_file}} - strongSwan IPsec secrets file 3 | 4 | {% for s in strongswan_secrets %} 5 | {{s.left|default()}} {{s.right|default()}} : {{s.type|default('PSK')}} {{s.credentials}} 6 | {% endfor %} 7 | 8 | -------------------------------------------------------------------------------- /tests/test_config.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Defaults 4 | hosts: localhost 5 | remote_user: root 6 | 7 | vars: 8 | - strongswan_config_setup: 9 | uniqueids: yes 10 | charondebug: 'ike 2, knl 3, cfg 0' 11 | - strongswan_conn_default: 12 | left: "{{ansible_default_ipv4.address}}" 13 | leftsourceip: "{{ansible_default_ipv4.address}}" 14 | leftsubnet: 10.0.0.0/16 15 | type: tunnel 16 | keyexchange: ikev2 17 | - strongswan_conns: 18 | conn1: 19 | right: 1.2.3.4 20 | rightsubnet: 2.3.4.0/24 21 | ike: aes256-sha1-modp1024 22 | esp: aes256-sha1-modp1024 23 | auto: route 24 | - strongswan_secrets: 25 | - left: "{{ansible_default_ipv4.address}}" 26 | right: 1.2.3.4 27 | type: PSK 28 | credentials: '"super wooper dooper secret"' 29 | 30 | roles: 31 | - { role: ansible-role-strongswan, become: true } 32 | 33 | # vi:ts=2:sw=2:et:ft=yaml 34 | -------------------------------------------------------------------------------- /tests/test_defaults.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Defaults 4 | hosts: localhost 5 | remote_user: root 6 | 7 | roles: 8 | - { role: ansible-role-strongswan, become: true } 9 | 10 | # vi:ts=2:sw=2:et:ft=yaml 11 | -------------------------------------------------------------------------------- /tests/test_vagrant.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Defaults 4 | hosts: all 5 | become: true 6 | 7 | vars: 8 | - strongswan_config_setup: 9 | uniqueids: yes 10 | charondebug: 'ike 2, knl 3, cfg 0' 11 | - strongswan_conn_default: 12 | left: "{{ansible_default_ipv4.address}}" 13 | leftsourceip: "{{ansible_default_ipv4.address}}" 14 | leftsubnet: 10.0.0.0/16 15 | type: tunnel 16 | keyexchange: ikev2 17 | - strongswan_conns: 18 | conn1: 19 | right: 1.2.3.4 20 | rightsubnet: 2.3.4.0/24 21 | ike: aes256-sha1-modp1024 22 | esp: aes256-sha1-modp1024 23 | auto: route 24 | - strongswan_secrets: 25 | - left: "{{ansible_default_ipv4.address}}" 26 | right: 1.2.3.4 27 | type: PSK 28 | credentials: '"super wooper dooper secret"' 29 | 30 | roles: 31 | - { role: ansible-role-strongswan, become: true } 32 | 33 | # vi:ts=2:sw=2:et:ft=yaml 34 | -------------------------------------------------------------------------------- /vars/Debian.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | strongswan_packages: 4 | - strongswan 5 | 6 | strongswan_prefix: /etc 7 | 8 | strongswan_ipsec_bin: /usr/sbin/ipsec 9 | 10 | # vi:ts=2:sw=2:et:ft=yaml 11 | -------------------------------------------------------------------------------- /vars/RedHat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | strongswan_packages: 4 | - strongswan 5 | 6 | strongswan_prefix: /etc/strongswan 7 | 8 | strongswan_ipsec_bin: /sbin/strongswan 9 | 10 | strongswan_os_major: "{{ansible_distribution_major_version}}" 11 | # CentOS: "{{ansible_distribution_major_version}}" 12 | # RedHat: "{{ansible_distribution_major_version}}" 13 | # Amazon: 6 14 | 15 | strongswan_epel_baseurl: "https://dl.fedoraproject.org" 16 | strongswan_epel_package: "epel-release-latest-{{strongswan_os_major[ansible_distribution]}}.noarch.rpm" 17 | strongswan_epel_url: "{{strongswan_epel_baseurl}}/pub/epel/{{strongswan_epel_package}}" 18 | 19 | # vi:ts=2:sw=2:et:ft=yaml 20 | --------------------------------------------------------------------------------