├── .ansible-lint ├── .gitignore ├── .yamllint ├── LICENSE ├── README.md ├── README_ADVANCED.md ├── defaults └── main.yml ├── files └── systemd │ └── avicontroller.service ├── handlers └── main.yml ├── meta └── main.yml ├── molecule └── default │ ├── Dockerfile.j2 │ ├── molecule.yml │ ├── playbook.yml │ ├── requirements.yml │ └── tests │ └── test_default.py ├── tasks ├── docker │ ├── con_requirements.yml │ ├── custom_repo.yml │ ├── docker_hub.yml │ ├── family │ │ ├── default.yml │ │ └── redhat.yml │ ├── fresh_install.yml │ ├── main.yml │ ├── os │ │ └── default.yml │ ├── package_deploy.yml │ └── services │ │ ├── cleanup.yml │ │ ├── install.yml │ │ └── systemd │ │ ├── check.yml │ │ └── install.yml ├── main.yml └── openshift │ └── main.yml └── templates ├── 16.x └── avicontroller.service.j2 ├── avicontroller.j2 ├── avicontroller.service.j2 ├── csp └── avi_meta_controller.j2 └── default └── avicontroller.j2 /.ansible-lint: -------------------------------------------------------------------------------- 1 | --- 2 | skip_list: 3 | - 305 4 | - 306 5 | - 208 6 | - 106 7 | use_default_rules: true 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.retry 2 | */__pycache__ 3 | *.pyc 4 | -------------------------------------------------------------------------------- /.yamllint: -------------------------------------------------------------------------------- 1 | --- 2 | # Based on ansible-lint config 3 | extends: default 4 | 5 | rules: 6 | braces: {max-spaces-inside: 1, level: error} 7 | brackets: {max-spaces-inside: 1, level: error} 8 | colons: {max-spaces-after: -1, level: error} 9 | commas: {max-spaces-after: -1, level: error} 10 | comments: disable 11 | comments-indentation: disable 12 | document-start: disable 13 | empty-lines: {max: 3, level: error} 14 | hyphens: {level: error} 15 | indentation: disable 16 | key-duplicates: enable 17 | line-length: disable 18 | new-line-at-end-of-file: disable 19 | new-lines: {type: unix} 20 | trailing-spaces: disable 21 | truthy: disable -------------------------------------------------------------------------------- /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 | **⛔️ DEPRECATED: This repo is no longer supported, please consider using** https://github.com/vmware/ansible-collection-alb **instead since** 2 | **this role is migrated to ansible collections.** 3 | 4 | [![Ansible Galaxy](https://img.shields.io/badge/galaxy-avinetworks.avicontroller-blue.svg)](https://galaxy.ansible.com/avinetworks/avicontroller/) 5 | 6 | Using this module you are able to install the Avi Vantage Controlller, to your system. However, minimum requirements must be met. 7 | 8 | > **Warning:** 9 | > This Ansible role is not meant to be ran repeatedly on the host. It's meant for deployment only. Once deployed the configuration for Avi is managed by Avi. 10 | 11 | ## Requirements 12 | 13 | Requires Docker to be installed. We have created `avinetworks.docker` to install Docker on a host. Please run that role first, or manually install Docker. 14 | 15 | ## Role Variables 16 | 17 | ### Setting Deployment type 18 | 19 | | Variable | Required | Default | Comments | 20 | | ----------------- | -------- | -------- | ------------------------------------------------------------------------------------------ | 21 | | `con_deploy_type` | No | `docker` | Sets the type of deployment that should be triggered. Valid options: `docker`, `openshift` | 22 | 23 | ### Standard Parameters 24 | 25 | | Variable | Required | Default | Comments | 26 | | ----------------------- | -------- | ------- | ---------------------------------------------------- | 27 | | `con_skip_requirements` | No | `false` | Skips any requirements for disk space, ram, and cpu. | 28 | 29 | ### Package Deploy Variables 30 | 31 | | Variable | Required | Default | Comments | 32 | | -------------------- | -------- | ---------------------------- | ----------------------------------------- | 33 | | `con_package_deploy` | No | `false` | Set to true to deploy via package | 34 | | `con_package_source` | No | `controller_docker.tgz` | Source location of the docker tgz | 35 | | `con_package_dest` | No | `/tmp/controller_docker.tgz` | Destination location on the remote server | 36 | 37 | ### Docker Hub and Docker Repo Variables 38 | 39 | | Variable | Required | Default | Comments | 40 | | -------------------------- | -------- | ------------------------------------------ | --------------------------------------------------------- | 41 | | `con_docker_repo` | No | `None` | If using a local repository please enter it here. | 42 | | `con_version` | No | `17.2.4-9024-20171127.023607` | Version of the Avi Controller package you want to deploy. | 43 | | `con_image` | No | `avinetworks/controller:{{ con_version }}` | Full name of the controller image. | 44 | | `con_docker_repo_user` | No | `None` | User to be used for repository authentication. | 45 | | `con_docker_repo_password` | No | `None` | Password to be used for repository authentication. | 46 | 47 | ### Docker Deployment Variables 48 | 49 | | Variable | Required | Default | Comments | 50 | | ---------------------------- | -------- | --------------------------------------------------------- | -------------------------------------------------------------------------------------- | 51 | | `con_cores` | No | `{{ ansible_processor_cores * ansible_processor_count }}` | How many cores the controller will use. | 52 | | `con_memory_gb` | No | `{{ ansible_memtotal_mb // 1024 }}` | How much memory the controller will use. | 53 | | `con_destination_disk` | No | `auto-detect based on ansible_mounts largest sized disk` | The disk that the controller data will be installed | 54 | | `con_disk_path` | No | `{{ destination_disk }}opt/avi/controller/data` | The path that the controller data will be installed. | 55 | | `con_disk_gb` | No | `30` | The size of the disk that will be used by controller data. | 56 | | `con_metrics_disk_path` | No | `None` | The path that the controller metric data will be stored. | 57 | | `con_metrics_disk_gb` | No | `None` | The size of the disk that will be used by metric data. | 58 | | `con_logs_disk_path` | No | `None` | The path that the controller log data will be stored. | 59 | | `con_logs_disk_gb` | No | `None` | The size of the disk that will be used by log data. | 60 | | `con_controller_ip` | No | `{{ ansible_default_ipv4.address }}` | The IP address of the controller. | 61 | | `con_dev_name` | No | `auto-detect based on con_controller_ip` | The device name that will be used by the controller. | 62 | | `con_setup_json` | No | `None` | The source location of the setup.json file. Used to auto-configure a controller. | 63 | | `con_setup_json_raw` | No | `None` | Allows a user to input the setup.json data in YAML or JSON format directly in Ansible. | 64 | | `con_fresh_install` | No | `false` | Erases any pre-existing directories associated with the controller. | 65 | | `con_portal_http_port` | No | `80` | Port used for the controllers unsecured web interface. | 66 | | `con_portal_https_port` | No | `443` | Port used for the controllers secured web interface. | 67 | | `con_sysint_port` | No | `8443` | Port to be used by the controller communication interface. | 68 | | `con_ssh_port` | No | `5098` | Port used to connect directly to the controllers ssh port. | 69 | | `con_serviceengine_ssh_port` | No | `5099` | Port used to connect directly to the service engines ssh port. | 70 | | `con_cli_port` | No | `5054` | Port used to access the command line interface of the controller. | 71 | | `con_snmp_port` | No | `161` | UDP port used to access the SNMP service on the controller. | 72 | | `con_mounts_extras` | No | `[]` | Extra mounting points to be used by the controller. | 73 | | `con_env_variables_extras` | No | `[]` | Extra environment variables to be used by the controller. | 74 | | `con_ports_list_extras` | No | `[]` | Extra ports to be used by the controller. | 75 | | `con_force_deploy` | No | `false` | Forces Ansible to run on the host, does not skip tasks. | 76 | 77 | ## Example Playbook 78 | 79 | > **WARNING:** 80 | > Before using this example please make the correct changes required for your server. 81 | > For more information please visit 82 | > It is recommended you adjust these parameters based on the implementation desired. 83 | 84 | ### Docker Deployment Examples 85 | 86 | ```yaml 87 | - hosts: servers 88 | roles: 89 | - role: avinetworks.avicontroller 90 | con_controller_ip: 10.10.27.101 91 | con_cores: 4 # If not specified core count is 4 92 | con_memory_gb: 12 # If not specified memory count is 12 93 | ``` 94 | 95 | The following is an example with minimum parameters. 96 | 97 | ```yaml 98 | - hosts: servers 99 | roles: 100 | - role: avinetworks.avicontroller 101 | ``` 102 | 103 | The following is an example with specific 18.1.2 release 104 | 105 | ```yaml 106 | --- 107 | - hosts: bm 108 | vars: 109 | avi_con_version: 18.1.2-9058-20180623.025526 110 | tasks: 111 | - name: Avi Controller | Setup docker 112 | include_role: 113 | name: avinetworks.docker 114 | become: yes 115 | - name: Avi Controller | Setup Controller 116 | include_role: 117 | name: avinetworks.avicontroller 118 | vars: 119 | con_controller_ip: "xxx" 120 | con_memory_gb: 20 121 | con_cores: 4|int 122 | con_fresh_install: True 123 | con_package_deploy: False 124 | con_version: "{{avi_con_version}}" 125 | con_image: avinetworks/controller:{{ con_version }} 126 | con_disk_gb: 50 127 | ``` 128 | 129 | ## License 130 | 131 | Apache 2.0 132 | 133 | ## Author Information 134 | 135 | [Avi Networks](http://avinetworks.com) 136 | -------------------------------------------------------------------------------- /README_ADVANCED.md: -------------------------------------------------------------------------------- 1 | # avinetworks.avicontroller 2 | 3 | This readme covers the advanced features of this role. These notes are for advanced users or customizing this role to use in unique environments including Development environments. Please use the following with extreme caution. 4 | 5 | ## Role Variables 6 | 7 | ### Parameter Override Variables 8 | However, you are able to provide these parameters another way. Using the following variables. This will allow the user to customize all values. 9 | **!!!BEWARE: USING THIS WILL ERASE DEFAULTS - USE WITH CAUTION!!!** 10 | 11 | 12 | ``` 13 | 14 | con_env_variables_all: 15 | - "CONTAINER_NAME=avicontroller" 16 | - "MANAGEMENT_IP={{ con_controller_ip | string}}" 17 | - "NUM_CPU={{ con_cores }}" 18 | - "NUM_MEMG={{ con_memory_gb }}" 19 | - "DISK_GB={{ con_disk_gb }}" 20 | 21 | con_mounts_all: 22 | - "/:/hostroot/" 23 | - "/var/run/docker.sock:/var/run/docker.sock" 24 | - "{{ con_disk_path }}:/vol/" 25 | 26 | con_ports_list_all: 27 | - "5098:5098" 28 | - "80:80" 29 | - "443:443" 30 | - "8443:8443" 31 | - "5054:5054" 32 | - "161:161/udp" 33 | ``` 34 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # defaults file for avinetworks.avicontroller 3 | 4 | # set the type of deployment 5 | con_deploy_type: docker 6 | 7 | # standard parameters 8 | con_skip_requirements: false 9 | 10 | # parameters for use when deploying as package 11 | con_package_deploy: false 12 | con_package_source: controller_docker.tgz 13 | con_package_dest: /tmp/controller_docker.tgz 14 | 15 | # parameters for use when pulling from docker hub or docker repo 16 | con_docker_repo: ~ 17 | con_docker_repo_user: ~ 18 | con_docker_repo_password: ~ 19 | con_version: 17.2.4-9024-20171127.023607 20 | con_image: "avinetworks/controller:{{ con_version }}" 21 | 22 | # docker deployment parameters 23 | con_force_deploy: false 24 | con_fresh_install: false 25 | con_controller_ip: "{{ ansible_default_ipv4.address }}" 26 | con_cores: "{{ ansible_processor_cores * ansible_processor_count }}" 27 | con_memory_gb: "{{ ansible_memtotal_mb // 1024 }}" 28 | con_destination_disk: "{{ ansible_mounts|sort(reverse=True, attribute='size_total')|map(attribute='mount')|first }}" 29 | con_disk_path: "{{ con_destination_disk }}/opt/avi/controller/data" 30 | con_disk_gb: 30 31 | con_metrics_disk_path: ~ 32 | con_metrics_disk_gb: ~ 33 | con_logs_disk_path: ~ 34 | con_logs_disk_gb: ~ 35 | con_dev_name: ~ 36 | con_setup_json: ~ 37 | con_setup_json_raw: ~ 38 | # If the deploy_type changes we will change the port to match 39 | # because of the limiatations of openshift we can't use 80 in openshift 40 | con_portal_http_port: >- 41 | {%- if con_deploy_type == 'openshift' -%}9080 42 | {%- elif con_deploy_type == 'docker' -%}80 43 | {%- else -%}80 44 | {%- endif -%} 45 | # If the deploy_type changes we will change the port to match 46 | # because of the limiatations of openshift we can't use 443 in openshift 47 | con_portal_https_port: >- 48 | {%- if con_deploy_type == 'openshift' -%}9443 49 | {%- elif con_deploy_type == 'docker' -%}443 50 | {%- else -%}443 51 | {%- endif -%} 52 | con_sysint_port: 8443 53 | con_ssh_port: 5098 54 | con_cli_port: 5054 55 | con_snmp_port: 161 56 | 57 | # Mount variables which are sent to the docker container, these are used in the service templates. 58 | con_mounts_extras: [] 59 | con_mounts_default: 60 | - "/:/hostroot/" 61 | - "/dev:/dev" 62 | - "/var/run/docker.sock:/var/run/docker.sock" 63 | - "{{ (con_deploy_type|lower == 'openshift')| ternary('', '/var/run/fleet.sock:/var/run/fleet.sock') }}" 64 | - "{{ con_disk_path }}:/vol/" 65 | - "{{ (con_metrics_disk_path == None)|ternary('', con_metrics_disk_path ~ ':/vol_metrics/') }}" 66 | - "{{ (con_logs_disk_path == None)|ternary('', con_logs_disk_path ~ ':/vol_logs/') }}" 67 | con_mounts_all: "{{ con_mounts_extras + con_mounts_default }}" 68 | con_mounts_string: "{% for mount_var in con_mounts_all|reject('match', '^$') %} -v {{ mount_var }}{% endfor %}" 69 | 70 | # Environment variables which are sent to the docker container, these are used in the service templates. 71 | con_env_variables_extras: [] 72 | con_env_variables_default: 73 | - "CONTAINER_NAME=avicontroller" 74 | - "MANAGEMENT_IP={{ con_controller_ip|string }}" 75 | - "NUM_CPU={{ con_cores }}" 76 | - "NUM_MEMG={{ con_memory_gb }}" 77 | - "DISK_GB={{ con_disk_gb }}" 78 | - "CNTRL_SSH_PORT={{ con_ssh_port }}" 79 | - "SYSINT_PORT={{ con_sysint_port }}" 80 | - "HTTP_PORT={{ con_portal_http_port }}" 81 | - "HTTPS_PORT={{ con_portal_https_port }}" 82 | - "{{ (con_metrics_disk_gb == None)|ternary('', 'METRICS_DISK_GB=' + con_metrics_disk_gb|string) }}" 83 | - "{{ (con_logs_disk_gb == None)|ternary('', 'LOGS_DISK_GB=' + con_logs_disk_gb|string) }}" 84 | con_env_variables_all: "{{ con_env_variables_extras + con_env_variables_default }}" 85 | con_env_variables_string: "{% for env_var in con_env_variables_all|reject('match', '^$') %} -e {{ env_var }}{% endfor %}" 86 | 87 | con_ports_list_extras: [] 88 | con_ports_list_default: 89 | - "{{ con_ssh_port }}:{{ con_ssh_port }}" 90 | - "{{ con_portal_http_port }}:{{ con_portal_http_port }}" 91 | - "{{ con_portal_https_port }}:{{ con_portal_https_port }}" 92 | - "{{ con_sysint_port }}:{{ con_sysint_port }}" 93 | - "{{ con_cli_port }}:{{ con_cli_port }}" 94 | - "{{ con_snmp_port }}:{{ con_snmp_port }}/udp" 95 | con_ports_list_all: "{{ con_ports_list_extras + con_ports_list_default }}" 96 | con_ports_list_string: "{% for port in con_ports_list_all|reject('match', '^$') %} -p {{ port }}{% endfor %}" 97 | 98 | # !!!! BEWARE: This is to completely override everything passed into the service template for the docker run. DON'T EDIT THIS UNLESS YOU KNOW WHAT YOUR DOING!!!!! 99 | AVI_RUN_PARAMS: "--name=avicontroller{{ con_ports_list_string }} --pids-limit -1 -d --privileged{{ con_env_variables_string }}{{ con_mounts_string }} {{ con_image }}" 100 | AVI_EXECUTABLE: "/usr/sbin/avicontroller" 101 | -------------------------------------------------------------------------------- /files/systemd/avicontroller.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=AVICONTROLLER 3 | After=docker.service 4 | Requires=docker.service 5 | 6 | [Service] 7 | TimeoutStartSec=0 8 | Restart=always 9 | 10 | ExecStart=/usr/sbin/avicontroller start 11 | ExecStop=/usr/sbin/avicontroller stop 12 | 13 | [Install] 14 | WantedBy=multi-user.target 15 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # handlers for avinetworks.avicontroller 3 | - name: Avi Controller | Services | systemd | Daemon reload 4 | systemd: daemon_reload=yes name=avicontroller 5 | when: ansible_version.full is version_compare('2.2', '>=') 6 | 7 | - name: Avi Controller | Services | Restart the avicontroller service 8 | service: name=avicontroller enabled=yes state=restarted 9 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | role_name: avicontroller 4 | author: Avi Networks 5 | description: Deploy's the AVI Vantage Controller 6 | company: Avi Networks 7 | issue_tracker_url: https://github.com/avinetworks/ansible-role-avicontroller/issues 8 | license: Apache-2.0 9 | min_ansible_version: 2.0.0 10 | github_branch: master 11 | platforms: 12 | - name: EL 13 | versions: 14 | - 6 15 | - 7 16 | - name: Ubuntu 17 | versions: 18 | - precise 19 | - trusty 20 | - xenial 21 | galaxy_tags: 22 | - avi 23 | - controller 24 | - loadbalancer 25 | - avinetworks 26 | - avicontroller 27 | - centos 28 | - ubuntu 29 | - mesos 30 | dependencies: [] 31 | -------------------------------------------------------------------------------- /molecule/default/Dockerfile.j2: -------------------------------------------------------------------------------- 1 | # Molecule managed 2 | 3 | {% if item.registry is defined %} 4 | FROM {{ item.registry.url }}/{{ item.image }} 5 | {% else %} 6 | FROM {{ item.image }} 7 | {% endif %} 8 | 9 | RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ 10 | elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \ 11 | elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ 12 | elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \ 13 | elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ 14 | elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi 15 | -------------------------------------------------------------------------------- /molecule/default/molecule.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependency: 3 | name: galaxy 4 | driver: 5 | name: docker 6 | platforms: 7 | - name: instance 8 | image: docker.io/pycontribs/centos:8 9 | pre_build_image: true 10 | lint: | 11 | set -e 12 | yamllint . 13 | ansible-lint 14 | flake8 15 | provisioner: 16 | name: ansible 17 | verifier: 18 | name: testinfra 19 | -------------------------------------------------------------------------------- /molecule/default/playbook.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Converge 3 | hosts: all 4 | become: true 5 | roles: 6 | - role: avinetworks.docker 7 | - role: avinetworks.avicontroller 8 | -------------------------------------------------------------------------------- /molecule/default/requirements.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - src: avinetworks.docker 3 | -------------------------------------------------------------------------------- /molecule/default/tests/test_default.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | import testinfra.utils.ansible_runner 4 | 5 | testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( 6 | os.environ["MOLECULE_INVENTORY_FILE"] 7 | ).get_hosts("all") 8 | 9 | 10 | def test_hosts_file(host): 11 | f = host.file("/etc/hosts") 12 | 13 | assert f.exists 14 | assert f.user == "root" 15 | assert f.group == "root" 16 | -------------------------------------------------------------------------------- /tasks/docker/con_requirements.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # check system against minimum requirements 3 | - name: Avi Controller | Requirements | Check for docker 4 | command: "which docker" 5 | register: docker 6 | changed_when: false 7 | 8 | - name: Avi Controller | Requirements | Get docker version 9 | shell: "docker -v | cut -d ' ' -f 3 | cut -d ',' -f 1" 10 | register: docker_version 11 | changed_when: false 12 | 13 | - name: Avi Controller | Requirements | Check docker version 14 | assert: 15 | that: 16 | - docker_version.stdout is version_compare('1.10.2', '>=') 17 | 18 | - name: Avi Controller | Requirements | Verify con_version not "latest" 19 | assert: 20 | that: 21 | - con_version != "latest" 22 | 23 | - block: 24 | - name: Avi Controller | Requirements | Get the management device name | ip addr 25 | shell: "ip addr show | grep {{ con_controller_ip }} | awk '{print $NF}'" 26 | register: con_mgmt_device 27 | changed_when: false 28 | - name: Avi Controller | Requirements | Set the management device name | ip addr 29 | set_fact: 30 | con_dev_name: "{{ con_mgmt_device.stdout }}" 31 | AVICONTROLLER_DEV_NAME: "{{ con_mgmt_device.stdout }}" 32 | when: con_dev_name == None 33 | 34 | - name: Avi Controller | Requirements | Set max_cores and memory limits of environment 35 | set_fact: 36 | con_max_cores: "{{ ansible_processor_cores * ansible_processor_count * ansible_processor_threads_per_core }}" 37 | con_ansible_memtotal_gb: "{{ ansible_memtotal_mb // 1024 }}" 38 | 39 | - name: Avi Controller | Requirements | Get Ansible processor info 40 | debug: 41 | msg: >- 42 | con_max_cores {{ con_max_cores }} 43 | ansible processor cores {{ ansible_processor_cores }} 44 | count {{ ansible_processor_count }} 45 | threads {{ ansible_processor_threads_per_core }} 46 | when: not con_skip_requirements 47 | 48 | - name: Avi Controller | Requirements | Validate Parameters 49 | assert: 50 | that: 51 | - "ansible_memtotal_mb >= 12288" 52 | - "con_memory_gb|int <= con_ansible_memtotal_gb|int" 53 | - "con_max_cores|int >= 4" 54 | - "con_cores|int <= con_max_cores|int" 55 | when: not con_skip_requirements 56 | 57 | - name: Avi Controller | Requirements | Fresh install steps 58 | include: fresh_install.yml 59 | when: con_fresh_install 60 | 61 | - name: Avi Controller | Requirements | Create directories for controller 62 | file: path="{{ item }}" state=directory mode=0755 63 | when: item != None 64 | with_items: 65 | - "{{ con_disk_path }}" 66 | - "{{ con_metrics_disk_path }}" 67 | - "{{ con_logs_disk_path }}" 68 | 69 | - name: Avi Controller | Requirements | Get disk space on controller disk path 70 | shell: "df {{ con_disk_path }} -BG | grep -iv Used | awk '{print $4}' | sed s/G//g" 71 | changed_when: false 72 | register: con_disk_path_space 73 | when: con_disk_path != None 74 | 75 | - name: Avi Controller | Requirements | Get disk space on controller logs disk path 76 | shell: "df {{ con_logs_disk_path }} -BG | grep -iv Used | awk '{print $4}' | sed s/G//g" 77 | changed_when: false 78 | register: con_logs_disk_path_space 79 | when: con_logs_disk_path != None 80 | 81 | - name: Avi Controller | Requirements | Get disk space on controller metrics disk path 82 | shell: "df {{ con_metrics_disk_path }} -BG | grep -iv Used | awk '{print $4}' | sed s/G//g" 83 | changed_when: false 84 | register: con_metrics_disk_path_space 85 | when: con_metrics_disk_path != None 86 | 87 | - block: 88 | - name: Avi Controller | Requirements | Check if there is enough space for controller disk path 89 | assert: 90 | that: 91 | - con_disk_gb != None 92 | - con_disk_path_space.stdout|int > con_disk_gb|int 93 | when: con_disk_path != None 94 | - name: Avi Controller | Requirements | Check if there is enough space for controller metrics disk path 95 | assert: 96 | that: 97 | - con_metrics_disk_gb != None 98 | - con_metrics_disk_path_space.stdout|int > con_metrics_disk_gb|int 99 | when: con_metrics_disk_path != None 100 | - name: Avi Controller | Requirements | Check if there is enough space for controller logs disk path 101 | assert: 102 | that: 103 | - con_logs_disk_gb != None 104 | - con_logs_disk_path_space.stdout|int > con_logs_disk_gb|int 105 | when: con_logs_disk_path != None 106 | when: not con_skip_requirements 107 | -------------------------------------------------------------------------------- /tasks/docker/custom_repo.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # These steps will allow a user to specify a private docker repository and login to that 3 | # respository to pull docker images. 4 | # 5 | - block: 6 | - name: Avi Controller | Docker | Log into the custom docker repository 7 | shell: "docker login -u {{ con_docker_repo_user }} -p {{ con_docker_repo_password }} {{ con_docker_repo }}" 8 | register: con_docker_repo_login 9 | when: 10 | - con_docker_repo_user != None 11 | - con_docker_repo_password != None 12 | - name: Avi Controller | Docker | Load the image from custom docker repository 13 | shell: "docker pull {{ con_docker_repo }}/{{ con_image }}" 14 | register: con_load_docker_repo 15 | changed_when: "'Status: Image is up to date' not in con_load_docker_repo.stdout" 16 | notify: Avi Controller | Services | Restart the avicontroller service 17 | when: not con_docker_match.stdout or con_version == "latest" 18 | -------------------------------------------------------------------------------- /tasks/docker/docker_hub.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Default docker image pull from the Docker Hub. 3 | 4 | - name: Avi Controller | Docker | Load the image from Docker Hub 5 | shell: "docker pull {{ con_image }}" 6 | register: con_load_docker_hub 7 | changed_when: "'Status: Image is up to date' not in con_load_docker_hub.stdout" 8 | notify: Avi Controller | Services | Restart the avicontroller service 9 | when: not con_docker_match.stdout or con_version == "latest" 10 | -------------------------------------------------------------------------------- /tasks/docker/family/default.yml: -------------------------------------------------------------------------------- 1 | --- 2 | -------------------------------------------------------------------------------- /tasks/docker/family/redhat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Verify if firewalld service is installed/present 3 | - name: Avi Controller | Docker | Family | Verify Firewalld is present 4 | command: systemctl is-enabled firewalld # noqa 303 5 | register: result 6 | failed_when: false 7 | changed_when: false 8 | 9 | # Disable and stop firewalld 10 | - name: Avi Controller | Docker | Family | Disable and stop Firewalld 11 | service: name="firewalld" state="stopped" enabled="no" 12 | when: result.stdout == "enabled" 13 | 14 | # Verify if snmpd service is installed/present and enable 15 | - name: Avi Controller | Docker | Family | Verify snmpd is present 16 | command: systemctl is-enabled snmpd # noqa 303 17 | register: snmpd_result 18 | failed_when: false 19 | changed_when: false 20 | 21 | # Disable and stop snmpd 22 | - name: Avi Controller | Docker | Family | Disable and stop snmpd 23 | service: name="snmpd" state="stopped" enabled="no" 24 | when: snmpd_result.stdout == "enabled" 25 | -------------------------------------------------------------------------------- /tasks/docker/fresh_install.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Avi Controller | Requirements | systemd | Check the avicontroller service exist 3 | stat: path=/etc/systemd/system/avicontroller.service 4 | register: service_status 5 | 6 | - name: Avi Controller | Requirements | systemd | Stop the avicontroller service for fresh install 7 | systemd: daemon_reload=yes name=avicontroller enabled=no state=stopped 8 | when: ansible_service_mgr == 'systemd' and service_status.stat.exists 9 | 10 | - name: Avi Controller | Requirements | Clean directories for fresh install 11 | file: path="{{ item }}" state=absent 12 | when: item != None 13 | with_items: 14 | - "{{ con_disk_path }}" 15 | - "{{ con_metrics_disk_path }}" 16 | - "{{ con_logs_disk_path }}" 17 | -------------------------------------------------------------------------------- /tasks/docker/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Avi Controller | Services | systemd | Check if Avi Controller installed 3 | include: "services/systemd/check.yml" 4 | when: ansible_service_mgr == "systemd" 5 | 6 | - block: 7 | - name: Avi Controller | Check minimum requirements 8 | include: con_requirements.yml 9 | 10 | - name: Avi Controller | Perform specific os tasks 11 | include: "{{ item }}" 12 | with_first_found: 13 | - os/{{ ansible_distribution|lower }}.yml 14 | - os/default.yml 15 | 16 | - name: Avi Controller | Perform specific os family tasks 17 | include: "{{ item }}" 18 | with_first_found: 19 | - family/{{ ansible_os_family|lower }}.yml 20 | - family/default.yml 21 | 22 | - name: Avi Controller | Copy setup.json to controller 23 | copy: src="{{ con_setup_json }}" dest="{{ con_disk_path }}/setup.json" 24 | when: con_setup_json != None 25 | 26 | - name: Avi Controller | Copy setup.json to controller 27 | copy: content="{{ con_setup_json_raw | to_json }}\n" dest="{{ con_disk_path }}/setup.json" 28 | when: con_setup_json_raw != None 29 | 30 | # We must do this step first just in case we need to override defaults from the supplied package 31 | - name: Avi Controller | Docker | Package Deploy 32 | include: package_deploy.yml 33 | when: con_package_deploy 34 | 35 | - name: Avi Controller | Docker | Check if specified image already exists. 36 | shell: "docker images -q {{ con_image }}" 37 | changed_when: false 38 | register: con_docker_match 39 | 40 | - block: 41 | - name: Avi Controller | Docker | Docker Hub 42 | include: docker_hub.yml 43 | when: con_docker_repo == None 44 | - name: Avi Controller | Docker | Custom Repo 45 | include: custom_repo.yml 46 | when: con_docker_repo != None 47 | when: not con_package_deploy 48 | 49 | - name: Avi Controller | Docker | Cleanup 50 | include: services/cleanup.yml 51 | 52 | - name: Avi Controller | Docker | Install the Avi Controller services 53 | include: services/install.yml 54 | when: not avi_installed.stat.exists or con_force_deploy or con_fresh_install 55 | -------------------------------------------------------------------------------- /tasks/docker/os/default.yml: -------------------------------------------------------------------------------- 1 | --- 2 | -------------------------------------------------------------------------------- /tasks/docker/package_deploy.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # This set of tasks is only used when con_package_deploy is true 3 | - name: Avi Controller | Docker | Deploy the image from the package 4 | copy: src={{ con_package_source }} dest={{ con_package_dest }} 5 | 6 | - name: Avi Controller | Docker | Load the image from the package 7 | shell: "docker load -q -i {{ con_package_dest }} | awk -F':' '{print $3}'" 8 | changed_when: false 9 | register: con_load_docker_image 10 | 11 | - name: Set con_version and con_image facts 12 | set_fact: 13 | con_version: "{{ con_load_docker_image.stdout }}" 14 | con_image: "avinetworks/controller:{{ con_load_docker_image.stdout }}" 15 | -------------------------------------------------------------------------------- /tasks/docker/services/cleanup.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Avi Controller | Docker | Cleanup | Get our desired docker image id. 3 | shell: "docker images -q {{ con_image }}" 4 | changed_when: false 5 | register: con_docker_image 6 | 7 | - name: Avi Controller | Docker | Cleanup | Get list of running avicontroller containers 8 | shell: "docker ps -q -f name=avicontroller" 9 | changed_when: false 10 | register: con_running_con_containers 11 | 12 | - name: Avi Controller | Docker | Cleanup | Check if desired version is already running. 13 | shell: "docker ps -q -f ancestor={{ con_docker_image.stdout }}" 14 | changed_when: false 15 | register: con_desired_running 16 | 17 | - name: Avi Controller | Docker | Cleanup | Stop and Remove the container if it's not the desired version. 18 | shell: "docker stop {{ item }} && docker rm -f {{ item }}" 19 | notify: Avi Controller | Services | Restart the avicontroller service 20 | when: 21 | - item not in con_desired_running.stdout_lines 22 | with_items: 23 | - "{{ con_running_con_containers.stdout_lines }}" 24 | 25 | - name: Avi Controller | Docker | Cleanup | Get list of non-matched controller images. 26 | shell: "docker images | grep -v REPOSITORY | grep -v {{ con_version }} | grep avinetworks/controller | awk '{print $3}'" 27 | changed_when: false 28 | register: con_non_matched_images 29 | 30 | - name: Avi Controller | Docker | Cleanup | Remove non-matched controller images. 31 | shell: "docker rmi -f {{ con_non_matched_images.stdout_lines|join(' ') }}" 32 | changed_when: false 33 | when: con_non_matched_images.stdout 34 | -------------------------------------------------------------------------------- /tasks/docker/services/install.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Avi Controller | Services | Install the Avi Controller service file | New 3 | template: src=avicontroller.j2 dest=/usr/sbin/avicontroller mode=0755 4 | notify: Avi Controller | Services | Restart the avicontroller service 5 | 6 | - name: Avi Controller | Services | {{ ansible_service_mgr }} | Install the Avi Controller service | New 7 | include: "{{ ansible_service_mgr }}/install.yml" 8 | 9 | - name: Avi Controller | Services | {{ ansible_service_mgr }} | Start the service since it's not running | 10 | service: name=avicontroller enabled=yes state=started 11 | when: not con_desired_running.stdout 12 | -------------------------------------------------------------------------------- /tasks/docker/services/systemd/check.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Avi Controller | Check if Avi Controller installed 3 | stat: 4 | path: /etc/systemd/system/avicontroller.service 5 | register: avi_installed 6 | -------------------------------------------------------------------------------- /tasks/docker/services/systemd/install.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Avi Controller | Services | systemd | Deploy the avicontroller service 3 | template: 4 | src: avicontroller.service.j2 5 | dest: /etc/systemd/system/avicontroller.service 6 | mode: 0644 7 | register: avicontroller_service 8 | notify: 9 | - Avi Controller | Services | systemd | Daemon reload 10 | - Avi Controller | Services | Restart the avicontroller service 11 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for avinetworks.avicontroller 3 | - name: Check ansible version 4 | when: 5 | - ansible_version.full is version_compare('2.4', '<') 6 | debug: > 7 | msg="This role works best with ansible version 2.4 or greater. 8 | It is recommended to use the latest ansible version for the best experience." 9 | 10 | - name: Avi Controller | Deployment 11 | include: "{{ con_deploy_type|lower }}/main.yml" 12 | -------------------------------------------------------------------------------- /tasks/openshift/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Avi Controller | Docker | Deployment 3 | include: ../docker/main.yml 4 | -------------------------------------------------------------------------------- /templates/16.x/avicontroller.service.j2: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Avi Controller Service 3 | After=docker.service 4 | Requires=docker.service 5 | 6 | [Service] 7 | TimeoutStartSec=0 8 | Restart=always 9 | 10 | ExecStartPre=-/usr/bin/docker rm -f avicontroller 11 | ExecStartPre=/usr/bin/docker run {{ con_docker_run_params }} 12 | ExecStart=/usr/bin/docker wait avicontroller 13 | ExecStop=-/usr/bin/docker stop avicontroller 14 | ExecStop=-/bin/bash -c "ip addr del $(ip addr | grep {{ con_dev_name }}:1 | awk '{print $2}') dev {{ con_dev_name }}" 15 | ExecStopPost=-/usr/bin/docker rm -f avicontroller 16 | 17 | [Install] 18 | WantedBy=multi-user.target 19 | -------------------------------------------------------------------------------- /templates/avicontroller.j2: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Usage: avicontroller [options] ARG1 4 | ## Description: This script manages and provides manage of the Avi Controller service. 5 | ## docker is alias to the container platform i.e to either docker or podman 6 | 7 | container=avicontroller 8 | logfile="/var/log/${container}.log" 9 | 10 | write_log() { 11 | echo $1 2>&1 | tee -a ${logfile} 12 | } 13 | 14 | populate_container_platform() 15 | { 16 | # Default container platform is docker 17 | cont_plat="docker" 18 | cont_plat_sock="/var/run/docker.sock" 19 | 20 | # Possible values for $distribution which we support 21 | # "ubuntu" (or) "ol" (or) "rhel" (or) "centos" 22 | distribution=$(grep "^ID=" /etc/os-release | cut -d"=" -f2 | sed 's/"//g') 23 | 24 | # Possible known values for $version which we support 25 | # On Ubuntu: 26 | # version = "16.04" (or) "18.04" (or) "20.04" 27 | # On RHEL / OL / CENTOS: 28 | # version = "7.*" (or) "8.*" 29 | version=$(grep "^VERSION_ID=" /etc/os-release | cut -d"=" -f2 | sed 's/"//g') 30 | 31 | # cont_plat is podman only on OL / RHEL / CENTOS 8.* 32 | if [[ $distribution == "ol" || $distribution == "centos" || $distribution == "rhel" ]]; then 33 | if [[ $version =~ 8.* ]]; then 34 | cont_plat="podman" 35 | cont_plat_sock="/run/podman/podman.sock" 36 | fi 37 | fi 38 | write_log "[`date`] Setting cont_plat to $cont_plat as distribution=$distribution ($version)" 39 | } 40 | 41 | wait_till_service_starts() 42 | { 43 | service=$1 44 | write_log "[`date`] Waiting to check if ${service}.service is active" 45 | while [[ $(systemctl is-active ${service}.service) != "active" ]] 46 | do 47 | sleep 1 48 | done 49 | write_log "[`date`] ${service}.service is active" 50 | } 51 | 52 | container_running() { 53 | ${cont_plat} ps -f name=${container} | grep -q ${container} 54 | } 55 | 56 | container_exists() { 57 | ${cont_plat} ps -a -f name=${container} | grep -q ${container} 58 | } 59 | 60 | start_container() { 61 | write_log "[`date`] Starting the ${container} container" 62 | ${cont_plat} run ${controller_docker_run_params} 63 | if [ $? -eq 0 ]; then 64 | write_log "[`date`] Service ${container} running..." 65 | else 66 | write_log "[`date`] Failed to start the ${container} container" 67 | exit 1 68 | fi 69 | } 70 | 71 | stop_container() { 72 | ${cont_plat} stop ${container} 73 | if [ $? -eq 0 ]; then 74 | write_log "[`date`] Stopped the ${container} container" 75 | else 76 | exit 1 77 | fi 78 | } 79 | 80 | remove_container() { 81 | write_log "[`date`] Removing existing ${container} container" 82 | ${cont_plat} rm -f ${container} 83 | if [ $? -eq 0 ]; then 84 | write_log "[`date`] Removed existing ${container} container" 85 | else 86 | write_log "[`date`] Failed to remove existing ${container} container" 87 | fi 88 | } 89 | 90 | prestart() { 91 | # Clean up any running or existing avicontroller containers 92 | write_log "[`date`] Performing ${container} pre-start step." 93 | remove_container 94 | start_container 95 | } 96 | 97 | start() { 98 | prestart 99 | ${cont_plat} wait ${container} 100 | } 101 | 102 | stop() { 103 | # Stopping the docker/podman process if running 104 | controller_pid=`${cont_plat} inspect $container | grep '\"Pid\"' | awk '{print $2}' | sed s/,//` 105 | stop_var="fstrim /proc/$controller_pid/root" 106 | ${stop_var} 107 | write_log "[`date`] Freed the blocks of ${controller_pid}..." 108 | if container_running; then 109 | write_log "[`date`] Service ${container} stopping..." 110 | stop_container 111 | else 112 | write_log "[`date`] Service ${container} already stopped" 113 | fi 114 | poststop 115 | } 116 | 117 | poststop() { 118 | if $(ip addr | grep -q {{ AVICONTROLLER_DEV_NAME }}:avivip); then 119 | /bin/bash -c "ip addr del $(ip addr | grep {{ AVICONTROLLER_DEV_NAME }}:avivip | awk '{print $2}') dev {{ AVICONTROLLER_DEV_NAME }}" 120 | if [ $? -eq 0 ]; then 121 | write_log "[`date`] Successfuly removed the cluster vip interface." 122 | fi 123 | elif $(ip addr | grep -q {{ AVICONTROLLER_DEV_NAME }}:1); then 124 | /bin/bash -c "ip addr del $(ip addr | grep {{ AVICONTROLLER_DEV_NAME }}:1 | awk '{print $2}') dev {{ AVICONTROLLER_DEV_NAME }}" 125 | if [ $? -eq 0 ]; then 126 | write_log "[`date`] Successfuly removed the cluster vip interface." 127 | fi 128 | fi 129 | 130 | if container_exists; then 131 | remove_container 132 | fi 133 | } 134 | 135 | restart() { 136 | stop 137 | start 138 | } 139 | 140 | reload() { 141 | restart 142 | } 143 | 144 | status() { 145 | if container_running; then 146 | echo "${container} running..." 147 | else 148 | echo "${container} stopped" 149 | fi 150 | } 151 | 152 | 153 | case "$1" in 154 | start|stop|status|restart|reload) 155 | populate_container_platform 156 | wait_till_service_starts ${cont_plat} 157 | controller_docker_run_params="{{ AVI_RUN_PARAMS }}" 158 | $1 159 | ;; 160 | *) 161 | echo $"Usage: $0 {start|stop|status|restart|reload}" 162 | exit 2 163 | esac 164 | 165 | exit $? -------------------------------------------------------------------------------- /templates/avicontroller.service.j2: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=AviCONTROLLER 3 | Requires=proc-sys-fs-binfmt_misc.mount 4 | 5 | 6 | [Service] 7 | TimeoutStartSec=0 8 | Restart=always 9 | 10 | ExecStart={{ AVI_EXECUTABLE }} start 11 | ExecStop={{ AVI_EXECUTABLE }} stop 12 | 13 | [Install] 14 | WantedBy=multi-user.target -------------------------------------------------------------------------------- /templates/csp/avi_meta_controller.j2: -------------------------------------------------------------------------------- 1 | {% for key,value in con_csp_meta_options.iteritems() %} 2 | {% if value != '' %} 3 | {% set myvalue = con_csp_meta_config.update({ key: value }) %} 4 | {% endif %} 5 | {% endfor %} 6 | {{ con_csp_meta_config | to_nice_yaml }} 7 | -------------------------------------------------------------------------------- /templates/default/avicontroller.j2: -------------------------------------------------------------------------------- 1 | # Defaults file for avicontroller service used by /usr/sbin/avicontroller 2 | 3 | ### Set common variables ### 4 | 5 | # If you would like to change the location of the log file, you can modify the setting here. 6 | AVICONTROLLER_LOGFILE="/var/log/avicontroller.log" 7 | 8 | # The following value is the management device that the controller will use. 9 | # This interface is managed by the service and is used when working with clusters 10 | # to properly shut down the sub-interface when a new master is chosen. 11 | AVICONTROLLER_DEV_NAME="{{ con_dev_name }}" 12 | 13 | # If you'd like to modify the run parameters that are supplied to the service 14 | # you can take full control here. When starting the controller we will use 15 | # /usr/bin/docker run ${AVICONTROLLER_DOCKER_RUN_PARAMS} so anything you put in 16 | # here will be supplied in that manner. 17 | AVICONTROLLER_DOCKER_RUN_PARAMS="{{ con_docker_run_params }}" 18 | --------------------------------------------------------------------------------