├── .travis.yml ├── CHANGES.rst ├── COPYRIGHT ├── LICENSE ├── README.md ├── defaults └── main.yml ├── docs ├── changelog.rst ├── copyright.rst ├── getting-started.rst ├── includes │ └── all.rst ├── index.rst ├── introduction.rst └── playbooks │ └── gitlab_runner.yml ├── meta ├── ansigenome.yml └── main.yml ├── tasks └── main.yml └── templates ├── etc ├── ansible │ └── facts.d │ │ └── gitlab_runner.fact.j2 ├── gitlab-runner │ ├── ansible.json.j2 │ └── config.toml.j2 └── sudoers.d │ └── gitlab-runner-vagrant-lxc.j2 └── lookup └── gitlab_runner__shell_tags.j2 /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | sudo: True 4 | language: 'python' 5 | python: '2.7' 6 | 7 | virtualenv: 8 | system_site_packages: true 9 | 10 | before_install: True 11 | install: True 12 | 13 | script: 14 | - 'git clone --depth 1 https://github.com/nickjj/rolespec' 15 | - 'cd rolespec ; bin/rolespec -r https://github.com/debops/test-suite' 16 | 17 | notifications: 18 | webhooks: 19 | - 'https://galaxy.ansible.com/api/v1/notifications/' 20 | -------------------------------------------------------------------------------- /CHANGES.rst: -------------------------------------------------------------------------------- 1 | Changelog 2 | ========= 3 | 4 | .. include:: includes/all.rst 5 | 6 | **debops.gitlab_runner** 7 | 8 | This project adheres to `Semantic Versioning `__ 9 | and `human-readable changelog `__. 10 | 11 | The current role maintainer_ is drybjed. 12 | 13 | 14 | `debops.gitlab_runner master`_ - unreleased 15 | ------------------------------------------- 16 | 17 | .. _debops.gitlab_runner master: https://github.com/debops/ansible-gitlab_runner/compare/v0.3.1...master 18 | 19 | 20 | `debops.gitlab_runner v0.3.1`_ - 2018-02-27 21 | ------------------------------------------- 22 | 23 | .. _debops.gitlab_runner v0.3.1: https://github.com/debops/ansible-gitlab_runner/compare/v0.3.0...v0.3.1 24 | 25 | Changed 26 | ~~~~~~~ 27 | 28 | - Change the APT package name to ``gitlab-runner``. [oussemos] 29 | 30 | 31 | `debops.gitlab_runner v0.3.0`_ - 2017-10-13 32 | ------------------------------------------- 33 | 34 | .. _debops.gitlab_runner v0.3.0: https://github.com/debops/ansible-gitlab_runner/compare/v0.2.0...v0.3.0 35 | 36 | Added 37 | ~~~~~ 38 | 39 | - Add support for `Vagrant LXC `_ 40 | provider when LXC is configured on a compatible host. [drybjed_] 41 | 42 | Changed 43 | ~~~~~~~ 44 | 45 | - Switch from GitLab API v1 to GitLab API v4 for Runner management. [drybjed_] 46 | 47 | 48 | `debops.gitlab_runner v0.2.0`_ - 2017-08-16 49 | ------------------------------------------- 50 | 51 | .. _debops.gitlab_runner v0.2.0: https://github.com/debops/ansible-gitlab_runner/compare/v0.1.2...v0.2.0 52 | 53 | Added 54 | ~~~~~ 55 | 56 | - Add improved autoscaling off-peak support. [azman0101] 57 | 58 | - Add a separate list of tags defined for shell executors that describe the 59 | host in a greater detail. [drybjed_] 60 | 61 | Changed 62 | ~~~~~~~ 63 | 64 | - Fixed Ansible warnings during task execution. [drybjed_] 65 | 66 | - Update APT cache before first package installation. [azman0101, drybjed_] 67 | 68 | - Convert the Ansible local facts to a Python script. The GitLab Runner state 69 | is stored in a separate, secure JSON file. [drybjed_] 70 | 71 | - Redesign the list of default GitLab Runner executors. The role will create 72 | a 'shell' executor, unless Docker is detected in which case the 'shell' 73 | executor will be disabled. Two Docker executors will be created, one 74 | privileged and one unprivileged, with respective tags. [drybjed_] 75 | 76 | - If Docker is detected, the ``gitlab-runner`` user will be added to the 77 | ``docker`` group to allow access to Docker containers. [drybjed_] 78 | 79 | - On hosts with Docker executors, number of concurrent jobs will depend on 80 | number of vCPUs available. Hosts with 'shell' executor will be allowed to run 81 | only 1 job at a time. [drybjed_] 82 | 83 | - The default 'shell' and privileged Docker executors will not be allowed to 84 | run untagged jobs for security reasons. The default unprivileged Docker 85 | executor can still run untagged jobs. [drybjed_] 86 | 87 | Fixed 88 | ~~~~~ 89 | 90 | - Fixed an error with missing Ansible facts breaking GitLab Runner registration. [drybjed_] 91 | 92 | 93 | `debops.gitlab_runner v0.1.2`_ - 2016-10-05 94 | ------------------------------------------- 95 | 96 | .. _debops.gitlab_runner v0.1.2: https://github.com/debops/ansible-gitlab_runner/compare/v0.1.1...v0.1.2 97 | 98 | Changed 99 | ~~~~~~~ 100 | 101 | - Added distributed cache bucket location configuration key. [sidewinder12s] 102 | 103 | 104 | `debops.gitlab_runner v0.1.1`_ - 2016-08-12 105 | ------------------------------------------- 106 | 107 | .. _debops.gitlab_runner v0.1.1: https://github.com/debops/ansible-gitlab_runner/compare/v0.1.0...v0.1.1 108 | 109 | Changed 110 | ~~~~~~~ 111 | 112 | - Add 201 as successful HTTP status on register. [bfabio] 113 | 114 | - Update documentation and Changelog. [drybjed_] 115 | 116 | 117 | debops.gitlab_runner v0.1.0 - 2016-04-11 118 | ---------------------------------------- 119 | 120 | Added 121 | ~~~~~ 122 | 123 | - Initial release. [drybjed_] 124 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | debops.gitlab_runner - Manage GitLab Runner instances using Ansible 2 | 3 | Copyright (C) 2016 Maciej Delmanowski 4 | Copyright (C) 2016 DebOps https://debops.org/ 5 | 6 | This Ansible role is part of DebOps. 7 | 8 | DebOps is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License version 3, as 10 | published by the Free Software Foundation. 11 | 12 | DebOps is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with DebOps. If not, see https://www.gnu.org/licenses/. 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | 676 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## [![DebOps project](http://debops.org/images/debops-small.png)](http://debops.org) gitlab_runner 2 | 3 | 5 | 6 | [![Travis CI](http://img.shields.io/travis/debops/ansible-gitlab_runner.svg?style=flat)](http://travis-ci.org/debops/ansible-gitlab_runner) 7 | [![test-suite](http://img.shields.io/badge/test--suite-ansible--gitlab__runner-blue.svg?style=flat)](https://github.com/debops/test-suite/tree/master/ansible-gitlab_runner/) 8 | [![Ansible Galaxy](http://img.shields.io/badge/galaxy-debops.gitlab_runner-660198.svg?style=flat)](https://galaxy.ansible.com/debops/gitlab_runner/) 9 | 10 | 11 | [GitLab Runner](https://gitlab.com/gitlab-org/gitlab-ci-multi-runner) is 12 | a service written in Go which is used by the [GitLab CI](https://about.gitlab.com/gitlab-ci/) 13 | to execute software builds on remote hosts. It supports builds executed by 14 | local shell, over SSH or in a Docker containers. 15 | 16 | The `debops.gitlab_runner` Ansible role will allow you to install and manage 17 | GitLab Runner on Debian and Ubuntu hosts. You can use it to create multiple 18 | Runner instances, each one with distinct configuration. The role will 19 | automatically register the Runners in GitLab CI management host if a required 20 | registration token is supplied. 21 | 22 | ### Installation 23 | 24 | This role requires at least Ansible `v2.0.0`. To install it, run: 25 | 26 | ```Shell 27 | ansible-galaxy install debops.gitlab_runner 28 | ``` 29 | 30 | ### Documentation 31 | 32 | More information about `debops.gitlab_runner` can be found in the 33 | [official debops.gitlab_runner documentation](http://docs.debops.org/en/latest/ansible/roles/ansible-gitlab_runner/docs/). 34 | 35 | 36 | 37 | ### Are you using this as a standalone role without DebOps? 38 | 39 | You may need to include missing roles from the [DebOps common 40 | playbook](https://github.com/debops/debops-playbooks/blob/master/playbooks/common.yml) 41 | into your playbook. 42 | 43 | [Try DebOps now](https://github.com/debops/debops) for a complete solution to run your Debian-based infrastructure. 44 | 45 | 46 | 47 | 48 | 49 | ### Authors and license 50 | 51 | `gitlab_runner` role was written by: 52 | 53 | - Maciej Delmanowski | [e-mail](mailto:drybjed@gmail.com) | [Twitter](https://twitter.com/drybjed) | [GitHub](https://github.com/drybjed) 54 | 55 | License: [GPLv3](https://tldrlegal.com/license/gnu-general-public-license-v3-%28gpl-3%29) 56 | 57 | *** 58 | 59 | This role is part of the [DebOps](http://debops.org/) project. README generated by [ansigenome](https://github.com/nickjj/ansigenome/). 60 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # .. vim: foldmarker=[[[,]]]:foldmethod=marker 3 | 4 | # debops.gitlab_runner default variables [[[ 5 | # ========================================== 6 | 7 | # .. contents:: Sections 8 | # :local: 9 | 10 | 11 | # Package installation [[[ 12 | # ------------------------ 13 | 14 | # .. envvar:: gitlab_runner__apt_upstream [[[ 15 | # 16 | # Enable configuration of upstream GitLab Runner repository. Currently it's the 17 | # only source of the required packages, but if you have downloaded them into 18 | # your own APT repository, you can disable upstream using this variable. 19 | gitlab_runner__apt_upstream: True 20 | 21 | # ]]] 22 | # .. envvar:: gitlab_runner__apt_key [[[ 23 | # 24 | # GPG key which signs the upstream APT repository package list. 25 | gitlab_runner__apt_key: '1A4C919DB987D435939638B914219A96E15E78F4' 26 | 27 | # ]]] 28 | # .. envvar:: gitlab_runner__apt_repo [[[ 29 | # 30 | # APT ``sources.list`` configuration of the upstream GitLab Runner repository. 31 | gitlab_runner__apt_repo: 'deb https://packages.gitlab.com/runner/gitlab-runner/{{ ansible_distribution | lower }}/ {{ ansible_distribution_release }} main' 32 | 33 | # ]]] 34 | # .. envvar:: gitlab_runner__base_packages [[[ 35 | # 36 | # List of APT packages which will be installed by the role. 37 | gitlab_runner__base_packages: 38 | - 'gitlab-runner' 39 | - '{{ "vagrant-lxc" if gitlab_runner__vagrant_lxc|bool else [] }}' 40 | 41 | # ]]] 42 | # .. envvar:: gitlab_runner__packages [[[ 43 | # 44 | # List of additional APT packages to install with GitLab Runner. 45 | gitlab_runner__packages: [] 46 | # ]]] 47 | # ]]] 48 | # User, group, home directory [[[ 49 | # ------------------------------- 50 | 51 | # .. envvar:: gitlab_runner__user [[[ 52 | # 53 | # System user account which will be used to run GitLab Runner jobs. 54 | gitlab_runner__user: 'gitlab-runner' 55 | 56 | # ]]] 57 | # .. envvar:: gitlab_runner__group [[[ 58 | # 59 | # System group which will be used to run GitLab Runner jobs. 60 | gitlab_runner__group: 'gitlab-runner' 61 | 62 | # ]]] 63 | # .. envvar:: gitlab_runner__additional_groups [[[ 64 | # 65 | # List of additional groups to which add the GitLab Runner user account, 66 | # specified as dictionaries. Missing groups will be added automatically. 67 | # Dictionary keys used by this variable: 68 | # 69 | # - ``name``: required, name of the group. 70 | # 71 | # - ``system``: optional, bool. If ``True``, the group will be a system group. 72 | # 73 | # System groups have GID < 1000. If ``system`` key is not specified, the value 74 | # of :envvar:`gitlab_runner__system` is used instead. 75 | gitlab_runner__additional_groups: [] 76 | 77 | # ]]] 78 | # .. envvar:: gitlab_runner__system [[[ 79 | # 80 | # If ``True``, the created user and groups will have UID and GID < 1000 and 81 | # will be considered "local" user and groups. 82 | gitlab_runner__system: True 83 | 84 | # ]]] 85 | # .. envvar:: gitlab_runner__home [[[ 86 | # 87 | # Home directory of the GitLab Runner user. 88 | gitlab_runner__home: '{{ (ansible_local.root.home 89 | if (ansible_local|d() and ansible_local.root|d() and 90 | ansible_local.root.home|d()) 91 | else "/var/local") + "/" + gitlab_runner__user }}' 92 | 93 | # ]]] 94 | # .. envvar:: gitlab_runner__comment [[[ 95 | # 96 | # Comment or GECOS field set on the GitLab Runner account. 97 | gitlab_runner__comment: 'GitLab Runner' 98 | 99 | # ]]] 100 | # .. envvar:: gitlab_runner__shell [[[ 101 | # 102 | # Default shell used by the GitLab Runner user account. 103 | gitlab_runner__shell: '/bin/bash' 104 | # ]]] 105 | # ]]] 106 | # Global configuration [[[ 107 | # ------------------------ 108 | 109 | # .. envvar:: gitlab_runner__concurrent [[[ 110 | # 111 | # Global number of jobs that can run concurrently on all configured runners. 112 | gitlab_runner__concurrent: '{{ ansible_processor_vcpus 113 | if (ansible_local|d() and ansible_local.docker|d() and 114 | (ansible_local.docker.installed|d()) | bool) 115 | else "1" }}' 116 | 117 | # ]]] 118 | # .. envvar:: gitlab_runner__domain [[[ 119 | # 120 | # The default domain used in different places of the role. 121 | gitlab_runner__domain: '{{ ansible_domain if ansible_domain else ansible_hostname }}' 122 | 123 | # ]]] 124 | # .. envvar:: gitlab_runner__fqdn [[[ 125 | # 126 | # The Fully Qualified Domain Name of the GitLab Runner host. 127 | gitlab_runner__fqdn: '{{ ansible_fqdn }}' 128 | 129 | # ]]] 130 | # .. envvar:: gitlab_runner__api_fqdn [[[ 131 | # 132 | # Fully Qualified Domain Name of the GitLab CI host which will control the 133 | # runner operation. 134 | gitlab_runner__api_fqdn: 'code.{{ gitlab_runner__domain }}' 135 | 136 | # ]]] 137 | # .. envvar:: gitlab_runner__api_url [[[ 138 | # 139 | # The HTTP API endpoint of the GitLab CI server. 140 | # The role will check if the API server is available before trying to use it. 141 | gitlab_runner__api_url: 'https://{{ gitlab_runner__api_fqdn }}/' 142 | 143 | # ]]] 144 | # .. envvar:: gitlab_runner__api_token [[[ 145 | # 146 | # The personal GitLab API access token used for API operations, for example 147 | # removal of existing Runners. This is not a Runner registration token. You can 148 | # generate an access token in GitLab "User Settings", "Access Tokens" 149 | # configuration page. 150 | gitlab_runner__api_token: '' 151 | 152 | # ]]] 153 | # .. envvar:: gitlab_runner__executor [[[ 154 | # 155 | # Default "executor" used by the runners. 156 | gitlab_runner__executor: 'shell' 157 | 158 | # ]]] 159 | # .. envvar:: gitlab_runner__token [[[ 160 | # 161 | # The GitLab CI registration token used to register the runners in GitLab. 162 | # See :ref:`gitlab_runner__token` for more details. 163 | gitlab_runner__token: '{{ lookup("env", "GITLAB_RUNNER_TOKEN") }}' 164 | 165 | # ]]] 166 | # .. envvar:: gitlab_runner__environment [[[ 167 | # 168 | # A set of custom environment variables added to each GitLab Runner. 169 | # See :ref:`gitlab_runner__environment` for more details. 170 | gitlab_runner__environment: {} 171 | # ]]] 172 | # ]]] 173 | # GitLab Runner tags [[[ 174 | # ---------------------- 175 | 176 | # .. envvar:: gitlab_runner__shell_tags [[[ 177 | # 178 | # List of tags automatically generated by the role, based on Ansible facts. 179 | # These tags are used with shell executors. 180 | gitlab_runner__shell_tags: '{{ lookup("template", 181 | "lookup/gitlab_runner__shell_tags.j2") }}' 182 | 183 | # ]]] 184 | # .. envvar:: gitlab_runner__default_tags [[[ 185 | # 186 | # List of default tags applied to the Runner at registration in GitLab CI. 187 | gitlab_runner__default_tags: [ 'managed-by-debops' ] 188 | 189 | # ]]] 190 | # .. envvar:: gitlab_runner__tags [[[ 191 | # 192 | # List of global tags applied to the Runner at registration in GitLab CI. 193 | gitlab_runner__tags: [] 194 | 195 | # ]]] 196 | # .. envvar:: gitlab_runner__group_tags [[[ 197 | # 198 | # List of tags applied to the Runner at registration in GitLab CI based on an 199 | # inventory group. 200 | gitlab_runner__group_tags: [] 201 | 202 | # ]]] 203 | # .. envvar:: gitlab_runner__host_tags [[[ 204 | # 205 | # List of per-host tags applied to the Runner at registration in GitLab CI. 206 | gitlab_runner__host_tags: [] 207 | 208 | # ]]] 209 | # .. envvar:: gitlab_runner__combined_tags [[[ 210 | # 211 | # Combined list of system-wide tags for easier use in the role tasks. 212 | gitlab_runner__combined_tags: '{{ gitlab_runner__default_tags 213 | + gitlab_runner__tags 214 | + gitlab_runner__group_tags 215 | + gitlab_runner__host_tags }}' 216 | # ]]] 217 | # ]]] 218 | # GitLab Runner instances [[[ 219 | # --------------------------- 220 | 221 | # GitLab Runner instances are configured as separate dictionary entries. Each 222 | # entry supports keys of the same name as most of the default variables with 223 | # ``gitlab_runner__`` stripped, for example ``item.docker_volumes`` instead of 224 | # :envvar:`gitlab_runner__docker_volumes`. If a key is not specified, a default value 225 | # will be used if configured on the role level. 226 | 227 | # An instance requires at least an ``item.name`` key, which is used as the 228 | # Runner instance description. The ``item.state`` key can be used to delete an 229 | # instance, when it's set to ``absent``. 230 | 231 | # .. envvar:: gitlab_runner__default_instances [[[ 232 | # 233 | # List of default GitLab Runner instances. 234 | gitlab_runner__default_instances: 235 | 236 | - name: '{{ ansible_hostname + "-shell" }}' 237 | executor: 'shell' 238 | run_untagged: False 239 | state: '{{ "absent" 240 | if (ansible_local|d() and ansible_local.docker|d() and 241 | (ansible_local.docker.installed|d()) | bool) 242 | else "present" }}' 243 | 244 | - name: '{{ ansible_hostname + "-docker" }}' 245 | executor: 'docker' 246 | tags: [ 'docker' ] 247 | state: '{{ "present" 248 | if (ansible_local|d() and ansible_local.docker|d() and 249 | (ansible_local.docker.installed|d()) | bool) 250 | else "absent" }}' 251 | 252 | - name: '{{ ansible_hostname + "-docker-root" }}' 253 | executor: 'docker' 254 | concurrent: '{{ ansible_processor_vcpus }}' 255 | docker_privileged: True 256 | run_untagged: False 257 | tags: [ 'docker-privileged' ] 258 | state: '{{ "present" 259 | if (ansible_local|d() and ansible_local.docker|d() and 260 | (ansible_local.docker.installed|d()) | bool) 261 | else "absent" }}' 262 | 263 | # ]]] 264 | # .. envvar:: gitlab_runner__instances [[[ 265 | # 266 | # Global list of GitLab Runner instances. 267 | gitlab_runner__instances: [] 268 | 269 | # ]]] 270 | # .. envvar:: gitlab_runner__group_instances [[[ 271 | # 272 | # List of GitLab Runner instances in Ansible host group. 273 | gitlab_runner__group_instances: [] 274 | 275 | # ]]] 276 | # .. envvar:: gitlab_runner__host_instances [[[ 277 | # 278 | # List of GitLab Runner instances on a particular host. 279 | gitlab_runner__host_instances: [] 280 | # ]]] 281 | # ]]] 282 | # Custom file upload [[[ 283 | # ---------------------- 284 | 285 | # .. envvar:: gitlab_runner__custom_files [[[ 286 | # 287 | # List of custom files to upload to GitLab Runner host. Each entry is 288 | # a dictionary with keys the same as the ``copy`` module options. 289 | # This list is meant to be configured for all hosts. 290 | gitlab_runner__custom_files: [] 291 | 292 | # ]]] 293 | # .. envvar:: gitlab_runner__group_custom_files [[[ 294 | # 295 | # List of custom files to upload to GitLab Runner host. Each entry is 296 | # a dictionary with keys the same as the ``copy`` module options. 297 | # This list is meant to be configured for a group of hosts. 298 | gitlab_runner__group_custom_files: [] 299 | 300 | # ]]] 301 | # .. envvar:: gitlab_runner__host_custom_files [[[ 302 | # 303 | # List of custom files to upload to GitLab Runner host. Each entry is 304 | # a dictionary with keys the same as the ``copy`` module options. 305 | # This list is meant to be configured for specific hosts. 306 | gitlab_runner__host_custom_files: [] 307 | # ]]] 308 | # ]]] 309 | # Shell executor configuration [[[ 310 | # -------------------------------- 311 | 312 | # These variables control what features are configured on the GitLab Runner 313 | # host to use by the shell executor. 314 | 315 | # .. envvar:: gitlab_runner__vagrant_lxc [[[ 316 | # 317 | # Enable or disable support for Vagrant LXC plugin (configuration of this 318 | # support also implies installation of :command:`vagrant` on the GitLab Runner 319 | # host). Enabling Vagrant LXC will give limited :command:`sudo` access for the 320 | # GitLab Runner UNIX account to allow access to LXC commands. 321 | gitlab_runner__vagrant_lxc: '{{ True 322 | if (ansible_local|d() and ansible_local.lxc|d() and 323 | (ansible_local.lxc.installed|d())|bool and 324 | (ansible_distribution_release not in 325 | [ "wheezy", "jessie", "precise", "trusty" ])) 326 | else False }}' 327 | # ]]] 328 | # ]]] 329 | # SSH key and host management [[[ 330 | # ------------------------------- 331 | 332 | # .. envvar:: gitlab_runner__ssh_generate [[[ 333 | # 334 | # Generate ``~/.ssh/id_rsa`` SSH private and public key if it doesn't exist. 335 | # The generated SSH key does not contain a passhprase so that it can be used 336 | # non-interactively by ``gitlab-runner`` daemon. 337 | gitlab_runner__ssh_generate: False 338 | 339 | # ]]] 340 | # .. envvar:: gitlab_runner__ssh_generate_bits [[[ 341 | # 342 | # Size of the generated SSH key. 343 | gitlab_runner__ssh_generate_bits: '4096' 344 | 345 | # ]]] 346 | # .. envvar:: gitlab_runner__ssh_install_to [[[ 347 | # 348 | # List of hosts which should have the ``gitlab-runner`` SSH key installed using 349 | # a ``delegate_to`` Ansible mechanism and ``authorized_key`` module. Each entry 350 | # is a dictionary with keys: 351 | # 352 | # - ``host``: the host address, it should be accessible to Ansible Controller 353 | # 354 | # - ``user``: user account which should will have the SSH key installed 355 | # 356 | # - ``options``: SSH ``authorized_keys`` options to set for a given key 357 | # 358 | gitlab_runner__ssh_install_to: [] 359 | 360 | # ]]] 361 | # .. envvar:: gitlab_runner__ssh_known_hosts [[[ 362 | # 363 | # List of host names which SSH host fingerprints should be scanned and added to 364 | # the ``~/.ssh/known_hosts`` file of the ``gitlab-runner`` account. This should 365 | # allow ``git clone`` commands over SSH. 366 | gitlab_runner__ssh_known_hosts: [ '{{ gitlab_runner__fqdn }}' ] 367 | # ]]] 368 | # ]]] 369 | # SSH executor configuration [[[ 370 | # ------------------------------ 371 | 372 | # You should refer to `SSH executor documentation `_ 373 | # for information about what can be configured and the required syntax. 374 | 375 | # .. envvar:: gitlab_runner__ssh_host [[[ 376 | # 377 | # FQDN host where SSH executor should connect to, unless overridden in the 378 | # runner instance configuration. 379 | gitlab_runner__ssh_host: '' 380 | 381 | # ]]] 382 | # .. envvar:: gitlab_runner__ssh_port [[[ 383 | # 384 | # Port to use by the SSH executor. 385 | gitlab_runner__ssh_port: '22' 386 | 387 | # ]]] 388 | # .. envvar:: gitlab_runner__ssh_user [[[ 389 | # 390 | # Username which the SSH executor should use to connect to the remote host. 391 | gitlab_runner__ssh_user: '' 392 | 393 | # ]]] 394 | # .. envvar:: gitlab_runner__ssh_identity_file [[[ 395 | # 396 | # Absolute path to the SSH identity file stored on the remote host which should 397 | # be used by the SSH executor to connect to the ssh host. 398 | gitlab_runner__ssh_identity_file: '' 399 | 400 | # ]]] 401 | # .. envvar:: gitlab_runner__ssh_password [[[ 402 | # 403 | # Password which should be used by the SSH executor to connect to the host. 404 | # This password is only used for SSH authentication, normally you should use an 405 | # identity file instead. 406 | gitlab_runner__ssh_password: '' 407 | # ]]] 408 | # ]]] 409 | # Docker executor configuration [[[ 410 | # --------------------------------- 411 | 412 | # You should referer to the `Doccker executor documentation `_ 413 | # for information about what can be configured and what's the specific syntax 414 | # of each option. 415 | 416 | # .. envvar:: gitlab_runner__docker_host [[[ 417 | # 418 | # Specify the FQDN hostname of the remote Docker host. If nothing is specified, 419 | # local Docker instance is used. 420 | gitlab_runner__docker_host: '' 421 | 422 | # ]]] 423 | # .. envvar:: gitlab_runner__docker_tls_cert_path [[[ 424 | # 425 | # Path to a directory with X.509 certificate, private key and CA certificate 426 | # used to authenticate to a remote Docker instance. 427 | gitlab_runner__docker_tls_cert_path: '' 428 | 429 | # ]]] 430 | # .. envvar:: gitlab_runner__docker_image [[[ 431 | # 432 | # Name of the Docker image to use for containers. 433 | gitlab_runner__docker_image: 'debian' 434 | 435 | # ]]] 436 | # .. envvar:: gitlab_runner__docker_privileged [[[ 437 | # 438 | # Enable or disable execution of Docker containers in privileged mode. 439 | gitlab_runner__docker_privileged: False 440 | 441 | # ]]] 442 | # .. envvar:: gitlab_runner__docker_disable_cache [[[ 443 | # 444 | # Enable or disable use of cache by Docker. 445 | gitlab_runner__docker_disable_cache: False 446 | 447 | # ]]] 448 | # .. envvar:: gitlab_runner__docker_cache_dir [[[ 449 | # 450 | # Directory with Docker cache data. 451 | gitlab_runner__docker_cache_dir: '' 452 | 453 | # ]]] 454 | # .. envvar:: gitlab_runner__docker_cap_add [[[ 455 | # 456 | # Specify list of POSIX capabilities to add to a container. 457 | gitlab_runner__docker_cap_add: [] 458 | 459 | # ]]] 460 | # .. envvar:: gitlab_runner__docker_cap_drop [[[ 461 | # 462 | # Specify list of POSIX capabilities to drop from a container. 463 | gitlab_runner__docker_cap_drop: [ 'NET_ADMIN', 'SYS_ADMIN', 'DAC_OVERRIDE' ] 464 | 465 | # ]]] 466 | # .. envvar:: gitlab_runner__docker_devices [[[ 467 | # 468 | # List of devices to add to a Docker container. 469 | gitlab_runner__docker_devices: [] 470 | 471 | # ]]] 472 | # .. envvar:: gitlab_runner__docker_extra_hosts [[[ 473 | # 474 | # List of additional :file:`/etc/hosts` entries to set in a Docker container. 475 | gitlab_runner__docker_extra_hosts: [] 476 | 477 | # ]]] 478 | # .. envvar:: gitlab_runner__docker_links [[[ 479 | # 480 | # List of other containers to link to a given container. 481 | gitlab_runner__docker_links: [] 482 | 483 | # ]]] 484 | # .. envvar:: gitlab_runner__docker_services [[[ 485 | # 486 | # List of other services enabled in a container. 487 | gitlab_runner__docker_services: [] 488 | 489 | # ]]] 490 | # .. envvar:: gitlab_runner__docker_volumes [[[ 491 | # 492 | # List of volumes mounted in a container. 493 | gitlab_runner__docker_volumes: [] 494 | 495 | # ]]] 496 | # .. envvar:: gitlab_runner__docker_allowed_images [[[ 497 | # 498 | # Specify a wildcard list of images which can be listed in a :file:`.gitlab-ci.yml` 499 | # file and are allowed to be used. 500 | gitlab_runner__docker_allowed_images: [] 501 | 502 | # ]]] 503 | # .. envvar:: gitlab_runner__docker_allowed_services [[[ 504 | # 505 | # Specify a wildcard list of services which can be listed in 506 | # a :file:`.gitlab-ci.yml` file and are allowed to be used. 507 | gitlab_runner__docker_allowed_services: [] 508 | # ]]] 509 | # ]]] 510 | # Docker Machine and autoscaling [[[ 511 | # ---------------------------------- 512 | 513 | # You should referer to the `GitLab Runner autoscaling documentation `_ 514 | # for information about what can be configured and what's the specific syntax 515 | # of each option. 516 | 517 | # .. envvar:: gitlab_runner__machine_idle_count [[[ 518 | # 519 | # Number of machines, that need to be created and waiting in Idle state. 520 | gitlab_runner__machine_idle_count: '{{ ansible_processor_cores }}' 521 | 522 | # ]]] 523 | # .. envvar:: gitlab_runner__machine_idle_time [[[ 524 | # 525 | # Time (in seconds) for machine to be in Idle state before it is removed. 526 | gitlab_runner__machine_idle_time: '600' 527 | 528 | # ]]] 529 | # .. envvar:: gitlab_runner__machine_max_builds [[[ 530 | # 531 | # Builds count after which machine will be removed. 532 | gitlab_runner__machine_max_builds: '100' 533 | 534 | # ]]] 535 | # .. envvar:: gitlab_runner__machine_name [[[ 536 | # 537 | # Name of the machine. It must contain ``%s``, which will be replaced with 538 | # a unique machine identifier. 539 | gitlab_runner__machine_name: 'auto-scale-%s.{{ gitlab_runner__domain }}' 540 | 541 | # ]]] 542 | # .. envvar:: gitlab_runner__machine_driver [[[ 543 | # 544 | # Docker Machine "driver" to use. You should refer to `Docker Machine 545 | # documentation `_ for more 546 | # information about supported drivers. 547 | gitlab_runner__machine_driver: 'generic' 548 | 549 | # ]]] 550 | # .. envvar:: gitlab_runner__machine_offpeakperiods [[[ 551 | # 552 | # Autoscale can be configured with the support for Off Peak time mode periods. 553 | # Time periods when the scheduler is in the OffPeak mode.You should refer 554 | # to `Gitlab Runner Advanced configuration documentation 555 | # `_ for more 556 | # information about OffPeakPeriods syntax. 557 | gitlab_runner__machine_offpeakperiods: ["* * 0-7,19-23 * * mon-fri *", "* * * * * sat,sun *"] 558 | 559 | # ]]] 560 | # .. envvar:: gitlab_runner__machine_offpeakidlecount [[[ 561 | # 562 | # Like IdleCount, but for Off Peak time periods. 563 | gitlab_runner__machine_offpeakidlecount: 0 564 | 565 | # ]]] 566 | # .. envvar:: gitlab_runner__machine_offpeakidletime [[[ 567 | # 568 | # Like IdleTime, but for Off Peak time mperiods. 569 | gitlab_runner__machine_offpeakidletime: 1200 570 | 571 | # ]]] 572 | # .. envvar:: gitlab_runner__machine_options [[[ 573 | # 574 | # List of options to pass to Docker Machine. See the GitLab Runner autoscaling 575 | # documentation for more details. 576 | gitlab_runner__machine_options: [] 577 | # ]]] 578 | # ]]] 579 | # Distributed cache configuration [[[ 580 | # ----------------------------------- 581 | 582 | # You should referer to the `GitLab Runner cache documentation `_ 583 | # for information about what can be configured and what's the specific syntax 584 | # of each option. 585 | 586 | # .. envvar:: gitlab_runner__cache [[[ 587 | # 588 | # Enable the support for distributed cache. 589 | gitlab_runner__cache: False 590 | 591 | # ]]] 592 | # .. envvar:: gitlab_runner__cache_type [[[ 593 | # 594 | # Select the cache type. Currently only ``s3`` is supported. 595 | gitlab_runner__cache_type: 's3' 596 | 597 | # ]]] 598 | # .. envvar:: gitlab_runner__cache_server_address [[[ 599 | # 600 | # Specify the cache server address. 601 | gitlab_runner__cache_server_address: '' 602 | 603 | # ]]] 604 | # .. envvar:: gitlab_runner__cache_access_key [[[ 605 | # 606 | # Specify the cache access key. 607 | gitlab_runner__cache_access_key: '' 608 | 609 | # ]]] 610 | # .. envvar:: gitlab_runner__cache_secret_key [[[ 611 | # 612 | # Specify the cache secret key. 613 | gitlab_runner__cache_secret_key: '' 614 | 615 | # ]]] 616 | # .. envvar:: gitlab_runner__cache_bucket_name [[[ 617 | # 618 | # Name of the S3 bucket to use for the cache. 619 | gitlab_runner__cache_bucket_name: '' 620 | 621 | # ]]] 622 | # .. envvar:: gitlab_runner__cache_bucket_location [[[ 623 | # 624 | # Cache bucket location 625 | gitlab_runner__cache_bucket_location: '' 626 | 627 | # ]]] 628 | # .. envvar:: gitlab_runner__cache_insecure [[[ 629 | # 630 | # Enable or disable connections to the S3 service over HTTP instead of HTTPS. 631 | gitlab_runner__cache_insecure: False 632 | # ]]] 633 | 634 | # .. envvar:: gitlab_runner__run_untagged [[[ 635 | # 636 | # Enable or disable running untagged jobs. 637 | gitlab_runner__run_untagged: True 638 | # ]]] 639 | # ]]] 640 | # ]]] 641 | -------------------------------------------------------------------------------- /docs/changelog.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../CHANGES.rst 2 | -------------------------------------------------------------------------------- /docs/copyright.rst: -------------------------------------------------------------------------------- 1 | Copyright 2 | ========= 3 | 4 | .. literalinclude:: ../COPYRIGHT 5 | -------------------------------------------------------------------------------- /docs/getting-started.rst: -------------------------------------------------------------------------------- 1 | Getting started 2 | =============== 3 | 4 | .. contents:: 5 | :local: 6 | 7 | .. _gitlab_runner__token: 8 | 9 | GitLab CI registration token 10 | ---------------------------- 11 | 12 | To register a Runner with your GitLab CI instance, you need to provide 13 | a registration token. It can be found on the ``https:///admin/runners`` 14 | page of your GitLab installation. 15 | 16 | The registration token is generated randomly on each GitLab startup, and 17 | unfortunately cannot be accessed using an API. Therefore, the easiest way to 18 | provide it to the role is to store it in an environment variable. The 19 | ``debops.gitlab_runner`` checks the value ofthe ``$GITLAB_RUNNER_TOKEN`` system 20 | variable and uses the token found there. 21 | 22 | The registration token is required to perform changes on the GitLab server 23 | itself, ie. registration and removal of Runners. It's not required for the role 24 | to manage the Runners on the host - the Runner tokens are saved in local 25 | Ansible facts and reused if necessary. 26 | 27 | An example way to run ``debops`` so that the role registers the Runners in 28 | GitLab CI: 29 | 30 | .. code-block:: console 31 | 32 | GITLAB_RUNNER_TOKEN= debops service/gitlab_runner 33 | 34 | To change the environment variable that holds the registration token, or save 35 | the token in Ansible inventory, you can use the :envvar:`gitlab_runner__token` 36 | variable. 37 | 38 | Initial configuration 39 | --------------------- 40 | 41 | By default, ``debops.gitlab_runner`` will configure a single Runner instance 42 | which uses a shell executor. If a Docker installation is detected via Ansible 43 | local facts, the role will disable the shell executor and configure two Docker 44 | executors - one unprivileged, and one privileged. The executors will have a set 45 | of tags that identify them, shell executors will have additional tags that 46 | describe the host's architecture, OS release, etc. 47 | 48 | If the ``debops.lxc`` role has been used to configure LXC support on a Debian 49 | Stretch or Ubuntu Xenial host, the ``debops.gitlab_runner`` will install the 50 | ``vagrant-lxc`` package and configure :command:`sudo` support for it. Using 51 | a shell executor you cn start and stop Vagrant Boxes using LXC containers and 52 | execute commands inside them. 53 | 54 | The Runner instances can be configured with variables specified as the keys of 55 | the dictionary that holds the specific Runner configuration. If any required 56 | keys are not specified, the value of the global variable will be used instead. 57 | 58 | Some of the variables will be added togeher (Docker volumes, for example), so 59 | that you can define a list of global values included in all of the Runner 60 | instances. 61 | 62 | .. _gitlab_runner__environment: 63 | 64 | Environment variables 65 | --------------------- 66 | 67 | You can use :envvar:`gitlab_runner__environment` default variable to specify a custom 68 | set of environment variables to configure in a GitLab Runner instance. You can 69 | use the global variable, or set the environment at the instance level by 70 | specifying it as ``item.environment`` variable. 71 | 72 | The environment variables can be specified in a different ways: 73 | 74 | - a single variable as a string: 75 | 76 | .. code-block:: yaml 77 | 78 | gitlab_runner__environment: 'VARIABLE=value' 79 | 80 | 81 | - a list of environment variables: 82 | 83 | .. code-block:: yaml 84 | 85 | gitlab_runner__environment: 86 | - 'VARIABLE1=value1' 87 | - 'VARIABLE2=value2' 88 | 89 | 90 | - a YAML dictionary with variable names as keys and their values as values: 91 | 92 | .. code-block:: yaml 93 | 94 | gitlab_runner__environment: 95 | VARIABLE1: 'value1' 96 | VARIABLE2: 'value2' 97 | 98 | 99 | Different specifications cannot be mixed together. 100 | 101 | 102 | Example inventory 103 | ----------------- 104 | 105 | To install GitLab Runner service on a host, it needs to be added to the 106 | ``[debops_service_gitlab_runner]`` inventory host group: 107 | 108 | .. code-block:: none 109 | 110 | [debops_service_gitlab_runner] 111 | hostname 112 | 113 | 114 | Example playbook 115 | ---------------- 116 | 117 | Here's an example playbook that can be used to enable and manage the GitLab 118 | Runner service on a set of hosts: 119 | 120 | .. literalinclude:: playbooks/gitlab_runner.yml 121 | :language: yaml 122 | -------------------------------------------------------------------------------- /docs/includes/all.rst: -------------------------------------------------------------------------------- 1 | .. include:: includes/global.rst 2 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. _debops.gitlab_runner: 2 | 3 | Ansible role: debops.gitlab_runner 4 | ================================== 5 | 6 | .. toctree:: 7 | :maxdepth: 2 8 | 9 | introduction 10 | getting-started 11 | defaults 12 | copyright 13 | changelog 14 | 15 | .. 16 | Local Variables: 17 | mode: rst 18 | ispell-local-dictionary: "american" 19 | End: 20 | -------------------------------------------------------------------------------- /docs/introduction.rst: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============ 3 | 4 | `GitLab Runner `_ is 5 | a service written in Go which is used by the `GitLab CI `_ 6 | to execute software builds on remote hosts. It supports builds executed by 7 | local shell, over SSH or in a Docker containers. 8 | 9 | The ``debops.gitlab_runner`` Ansible role will allow you to install and manage 10 | GitLab Runner on Debian and Ubuntu hosts. You can use it to create multiple 11 | Runner instances, each one with distinct configuration. The role will 12 | automatically register the Runners in GitLab CI management host if a required 13 | registration token is supplied. 14 | 15 | Installation 16 | ~~~~~~~~~~~~ 17 | 18 | This role requires at least Ansible ``v2.0.0``. To install it, run: 19 | 20 | .. code-block:: console 21 | 22 | ansible-galaxy install debops.gitlab_runner 23 | 24 | .. 25 | Local Variables: 26 | mode: rst 27 | ispell-local-dictionary: "american" 28 | End: 29 | -------------------------------------------------------------------------------- /docs/playbooks/gitlab_runner.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Configure GitLab Runner service 4 | hosts: [ 'debops_service_gitlab_runner' ] 5 | become: True 6 | 7 | environment: '{{ inventory__environment | d({}) 8 | | combine(inventory__group_environment | d({})) 9 | | combine(inventory__host_environment | d({})) }}' 10 | 11 | roles: 12 | 13 | - role: debops.gitlab_runner 14 | tags: [ 'role::gitlab_runner' ] 15 | -------------------------------------------------------------------------------- /meta/ansigenome.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | ansigenome_info: 4 | galaxy_url: 'https://galaxy.ansible.com/debops/gitlab_runner/' 5 | github_url: "https://github.com/debops/ansible-gitlab_runner" 6 | git_branch: "master" 7 | 8 | travis: True 9 | 10 | license_url: 'https://tldrlegal.com/license/gnu-general-public-license-v3-(gpl-3)' 11 | 12 | authors: 13 | - name: 'Maciej Delmanowski' 14 | url: '' 15 | email: 'drybjed@gmail.com' 16 | twitter: 'drybjed' 17 | github: 'drybjed' 18 | 19 | synopsis: | 20 | [GitLab Runner](https://gitlab.com/gitlab-org/gitlab-ci-multi-runner) is 21 | a service written in Go which is used by the [GitLab CI](https://about.gitlab.com/gitlab-ci/) 22 | to execute software builds on remote hosts. It supports builds executed by 23 | local shell, over SSH or in a Docker containers. 24 | 25 | The `debops.gitlab_runner` Ansible role will allow you to install and manage 26 | GitLab Runner on Debian and Ubuntu hosts. You can use it to create multiple 27 | Runner instances, each one with distinct configuration. The role will 28 | automatically register the Runners in GitLab CI management host if a required 29 | registration token is supplied. 30 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | dependencies: [] 4 | 5 | galaxy_info: 6 | 7 | author: 'Maciej Delmanowski' 8 | description: 'Manage GitLab Runner instances' 9 | company: 'DebOps' 10 | license: 'GPL-3.0' 11 | min_ansible_version: '2.0.0' 12 | 13 | platforms: 14 | 15 | - name: 'Ubuntu' 16 | versions: [ 'all' ] 17 | 18 | - name: 'Debian' 19 | versions: [ 'all' ] 20 | 21 | galaxy_tags: 22 | - development 23 | - gitlab 24 | - git 25 | - docker 26 | - ssh 27 | - ci 28 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Create required groups 4 | group: 5 | name: '{{ item.name if item.name|d() else item }}' 6 | system: '{{ item.system|bool if item.system is defined else gitlab_runner__system | bool }}' 7 | state: 'present' 8 | with_flattened: 9 | - '{{ gitlab_runner__group }}' 10 | - '{{ gitlab_runner__additional_groups }}' 11 | 12 | - name: Create gitlab-runner user 13 | user: 14 | name: '{{ gitlab_runner__user }}' 15 | group: '{{ gitlab_runner__group }}' 16 | groups: '{{ gitlab_runner__additional_groups | map(attribute="name") | list | join(",") }}' 17 | append: True 18 | home: '{{ gitlab_runner__home }}' 19 | system: '{{ gitlab_runner__system | bool }}' 20 | comment: '{{ gitlab_runner__comment }}' 21 | shell: '{{ gitlab_runner__shell }}' 22 | state: 'present' 23 | generate_ssh_key: '{{ gitlab_runner__ssh_generate | bool }}' 24 | ssh_key_bits: '{{ gitlab_runner__ssh_generate_bits }}' 25 | 26 | - name: Allow Docker access for gitlab-runner user 27 | user: 28 | name: '{{ gitlab_runner__user }}' 29 | groups: 'docker' 30 | append: True 31 | when: (ansible_local|d() and ansible_local.docker|d() and 32 | (ansible_local.docker.installed|d()) | bool) 33 | 34 | - name: Copy custom files to GitLab Runner host 35 | copy: 36 | src: '{{ item.src | d(omit) }}' 37 | content: '{{ item.content | d(omit) }}' 38 | dest: '{{ item.dest }}' 39 | owner: '{{ item.owner | d(omit) }}' 40 | group: '{{ item.group | d(omit) }}' 41 | mode: '{{ item.mode | d(omit) }}' 42 | directory_mode: '{{ item.directory_mode | d(omit) }}' 43 | follow: '{{ item.follow | d(omit) }}' 44 | force: '{{ item.force | d(omit) }}' 45 | with_flattened: 46 | - '{{ gitlab_runner__custom_files }}' 47 | - '{{ gitlab_runner__group_custom_files }}' 48 | - '{{ gitlab_runner__host_custom_files }}' 49 | when: ((item.src|d() or item.content|d()) and item.dest|d()) 50 | 51 | - name: Make sure APT can access HTTPS repositories 52 | apt: 53 | name: '{{ item }}' 54 | state: 'present' 55 | install_recommends: False 56 | update_cache: True 57 | cache_valid_time: '{{ ansible_local.core.cache_valid_time 58 | if (ansible_local|d() and ansible_local.core|d() and 59 | ansible_local.core.cache_valid_time|d()) 60 | else "86400" }}' 61 | with_items: [ 'apt-transport-https', 'openssl', 'ca-certificates' ] 62 | 63 | - name: Add gitlab-runner APT key 64 | apt_key: 65 | id: '{{ gitlab_runner__apt_key }}' 66 | keyserver: '{{ ansible_local.core.keyserver 67 | if (ansible_local|d() and ansible_local.core|d() and 68 | ansible_local.core.keyserver) 69 | else "hkp://pool.sks-keyservers.net" }}' 70 | state: 'present' 71 | when: gitlab_runner__apt_upstream|bool 72 | 73 | - name: Configure gitlab-runner APT repository 74 | apt_repository: 75 | repo: '{{ gitlab_runner__apt_repo }}' 76 | state: 'present' 77 | update_cache: True 78 | when: gitlab_runner__apt_upstream|bool 79 | 80 | - name: Install gitlab-runner packages 81 | apt: 82 | name: '{{ item }}' 83 | state: 'present' 84 | install_recommends: False 85 | with_flattened: 86 | - '{{ gitlab_runner__base_packages }}' 87 | - '{{ gitlab_runner__packages }}' 88 | 89 | - name: Check if GitLab service is available 90 | uri: 91 | url: '{{ gitlab_runner__api_url }}' 92 | register: gitlab_runner__register_api 93 | when: gitlab_runner__api_url|d() and gitlab_runner__api_url 94 | failed_when: False 95 | no_log: True 96 | 97 | - name: Register new GitLab Runners 98 | uri: 99 | url: '{{ (item.api_url | d(gitlab_runner__api_url)) + "api/v4/runners" }}' 100 | method: 'POST' 101 | body: 'token={{ item.token | d(gitlab_runner__token) }}&description={{ item.name | urlencode }}&tag_list={{ ((item.tags|d([]) + (gitlab_runner__shell_tags if (item.executor == "shell") else []) + gitlab_runner__combined_tags) | unique | join(",")) | urlencode }}&run_untagged={{ item.run_untagged | d(gitlab_runner__run_untagged) }}' 102 | status_code: '200,201' 103 | register: gitlab_runner__register_new_instances 104 | with_flattened: 105 | - '{{ gitlab_runner__default_instances }}' 106 | - '{{ gitlab_runner__instances }}' 107 | - '{{ gitlab_runner__group_instances }}' 108 | - '{{ gitlab_runner__host_instances }}' 109 | when: (gitlab_runner__register_api.status|d() and gitlab_runner__register_api.status == 200 and 110 | (item.token | d() or gitlab_runner__token) and item.name and 111 | (item.state is undefined or item.state != 'absent') and 112 | (ansible_local is undefined or 113 | (ansible_local|d() and (ansible_local.gitlab_runner is undefined or 114 | (ansible_local.gitlab_runner|d() and ansible_local.gitlab_runner.instances is defined and 115 | item.name not in ansible_local.gitlab_runner.instances))))) 116 | 117 | - name: Generate GitLab Runner configuration files 118 | template: 119 | src: 'etc/gitlab-runner/{{ item }}.j2' 120 | dest: '/etc/gitlab-runner/{{ item }}' 121 | owner: 'root' 122 | group: 'root' 123 | mode: '0600' 124 | with_items: [ 'config.toml', 'ansible.json' ] 125 | 126 | - name: Delete GitLab Runners if requested 127 | uri: 128 | url: '{{ (item.0.api_url | d(gitlab_runner__api_url)) + "api/v4/runners/" + item.1.id | string }}' 129 | method: 'DELETE' 130 | headers: 131 | 'PRIVATE-TOKEN': '{{ gitlab_runner__api_token }}' 132 | with_together: 133 | - '{{ gitlab_runner__default_instances + gitlab_runner__instances + gitlab_runner__group_instances + gitlab_runner__host_instances }}' 134 | - '{{ ansible_local.gitlab_runner.instance_tokens if (ansible_local|d() and ansible_local.gitlab_runner|d() and ansible_local.gitlab_runner.instance_tokens|d()) else [] }}' 135 | when: (gitlab_runner__register_api.status|d() and gitlab_runner__register_api.status == 200 and 136 | gitlab_runner__api_token and item.0.name|d() and item.1.name|d() and item.0.name == item.1.name and 137 | (item.0.state|d() and item.0.state == 'absent')) 138 | failed_when: False 139 | no_log: True 140 | 141 | - name: Get the SSH key from the remote host 142 | slurp: 143 | src: '~{{ gitlab_runner__user }}/.ssh/id_rsa.pub' 144 | register: gitlab_runner__register_ssh_key 145 | when: gitlab_runner__ssh_generate|bool 146 | 147 | - name: Distribute SSH key to other hosts 148 | authorized_key: 149 | key: '{{ gitlab_runner__register_ssh_key.content | b64decode | trim }}' 150 | user: '{{ item.user }}' 151 | state: 'present' 152 | key_options: '{{ item.options | d() }}' 153 | delegate_to: '{{ item.host }}' 154 | become: '{{ item.become | d(True) }}' 155 | with_items: '{{ gitlab_runner__ssh_install_to }}' 156 | when: gitlab_runner__ssh_generate|bool and item.user|d() and item.host|d() 157 | 158 | - name: Make sure that the ~/.ssh directory exists 159 | file: 160 | path: '{{ gitlab_runner__home }}/.ssh' 161 | state: 'directory' 162 | owner: '{{ gitlab_runner__user }}' 163 | group: '{{ gitlab_runner__group }}' 164 | mode: '0700' 165 | when: gitlab_runner__ssh_known_hosts|d() 166 | 167 | - name: Make sure the ~/.ssh/known_hosts file exists 168 | copy: 169 | content: '' 170 | dest: '{{ gitlab_runner__home }}/.ssh/known_hosts' 171 | owner: '{{ gitlab_runner__user }}' 172 | group: '{{ gitlab_runner__group }}' 173 | mode: '0644' 174 | force: False 175 | when: gitlab_runner__ssh_known_hosts|d() 176 | 177 | - name: Get list of already scanned host fingerprints 178 | shell: ssh-keygen -f {{ gitlab_runner__home }}/.ssh/known_hosts -F {{ item }} | grep -q '^# Host {{ item }} found' 179 | with_items: '{{ gitlab_runner__ssh_known_hosts }}' 180 | when: gitlab_runner__ssh_known_hosts|d() 181 | register: gitlab_runner__register_known_hosts 182 | changed_when: False 183 | failed_when: False 184 | 185 | - name: Scan SSH fingerprints of specified hosts 186 | shell: 'ssh-keyscan -H -T 10 {{ item.item }} >> {{ gitlab_runner__home + "/.ssh/known_hosts" }}' 187 | with_items: '{{ gitlab_runner__register_known_hosts.results }}' 188 | when: gitlab_runner__ssh_known_hosts and item is defined and item.rc > 0 189 | failed_when: False 190 | 191 | - name: Configure Vagrant LXC sudo access 192 | template: 193 | src: 'etc/sudoers.d/gitlab-runner-vagrant-lxc.j2' 194 | dest: '/etc/sudoers.d/gitlab-runner-vagrant-lxc' 195 | owner: 'root' 196 | group: 'root' 197 | mode: '0440' 198 | when: gitlab_runner__vagrant_lxc|bool 199 | 200 | - name: Make sure that Ansible fact directory exists 201 | file: 202 | path: '/etc/ansible/facts.d' 203 | state: 'directory' 204 | owner: 'root' 205 | group: 'root' 206 | mode: '0755' 207 | 208 | - name: Save GitLab Runner local facts 209 | template: 210 | src: 'etc/ansible/facts.d/gitlab_runner.fact.j2' 211 | dest: '/etc/ansible/facts.d/gitlab_runner.fact' 212 | owner: 'root' 213 | group: 'root' 214 | mode: '0755' 215 | -------------------------------------------------------------------------------- /templates/etc/ansible/facts.d/gitlab_runner.fact.j2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # {{ ansible_managed }} 4 | 5 | from __future__ import print_function 6 | from json import load, loads, dumps 7 | from sys import exit 8 | import os 9 | 10 | output = {} 11 | state_file = '/etc/gitlab-runner/ansible.json' 12 | 13 | if os.path.isfile(state_file): 14 | try: 15 | fh = open(state_file) 16 | output = load(fh) 17 | except Exception: 18 | pass 19 | 20 | output['installed'] = True 21 | 22 | print(dumps(output, sort_keys=True, indent=2)) 23 | -------------------------------------------------------------------------------- /templates/etc/gitlab-runner/ansible.json.j2: -------------------------------------------------------------------------------- 1 | {% set gitlab_runner__tpl_instances = [] %} 2 | {% set gitlab_runner__tpl_instance_tokens = [] %} 3 | {% if gitlab_runner__register_new_instances|d() and gitlab_runner__register_new_instances.results %} 4 | {% for item in gitlab_runner__register_new_instances.results %} 5 | {% if item.item.name|d() and item.json|d() and item.json.id|d() and item.json.token|d() %} 6 | {% set _ = gitlab_runner__tpl_instances.append(item.item.name) %} 7 | {% set _ = gitlab_runner__tpl_instance_tokens.append({ "id": item.json.id, "name": item.item.name, "token": item.json.token }) %} 8 | {% endif %} 9 | {% endfor %} 10 | {% endif %} 11 | {% if ansible_local|d() and ansible_local.gitlab_runner|d() and ansible_local.gitlab_runner.instance_tokens|d() %} 12 | {% for item in ansible_local.gitlab_runner.instance_tokens %} 13 | {% if item.name not in gitlab_runner__tpl_instances %} 14 | {% for element in (gitlab_runner__default_instances + gitlab_runner__instances + gitlab_runner__group_instances + gitlab_runner__host_instances) %} 15 | {% if (item.name == element.name and (element.state is undefined or element.state != 'absent')) %} 16 | {% set _ = gitlab_runner__tpl_instances.append(item.name) %} 17 | {% set _ = gitlab_runner__tpl_instance_tokens.append({ "id": item.id, "name": item.name, "token": item.token }) %} 18 | {% endif %} 19 | {% endfor %} 20 | {% endif %} 21 | {% endfor %} 22 | {% endif %} 23 | {% set output = { 24 | "instance_tokens": gitlab_runner__tpl_instance_tokens, 25 | "instances": gitlab_runner__tpl_instances 26 | } %} 27 | {{ output | to_nice_json }} 28 | -------------------------------------------------------------------------------- /templates/etc/gitlab-runner/config.toml.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | concurrent = {{ gitlab_runner__concurrent }} 4 | 5 | {% set gitlab_runner__tpl_instances = [] %} 6 | {% set gitlab_runner__tpl_instance_tokens = [] %} 7 | {% if gitlab_runner__register_new_instances|d() and gitlab_runner__register_new_instances.results %} 8 | {% for item in gitlab_runner__register_new_instances.results %} 9 | {% if item.item.name|d() and item.json|d() and item.json.token|d() %} 10 | {% set _ = gitlab_runner__tpl_instances.append(item.item.name) %} 11 | {% set _ = gitlab_runner__tpl_instance_tokens.append({ "name": item.item.name, "token": item.json.token }) %} 12 | {% endif %} 13 | {% endfor %} 14 | {% endif %} 15 | {% if ansible_local|d() and ansible_local.gitlab_runner|d() and ansible_local.gitlab_runner.instance_tokens|d() %} 16 | {% for item in ansible_local.gitlab_runner.instance_tokens %} 17 | {% if item.name not in gitlab_runner__tpl_instances %} 18 | {% for element in (gitlab_runner__default_instances + gitlab_runner__instances + gitlab_runner__group_instances + gitlab_runner__host_instances) %} 19 | {% if (item.name == element.name and (element.state is undefined or element.state != 'absent')) %} 20 | {% set _ = gitlab_runner__tpl_instances.append(item.name) %} 21 | {% set _ = gitlab_runner__tpl_instance_tokens.append({ "name": item.name, "token": item.token }) %} 22 | {% endif %} 23 | {% endfor %} 24 | {% endif %} 25 | {% endfor %} 26 | {% endif %} 27 | {% for runner in (gitlab_runner__default_instances + gitlab_runner__instances + gitlab_runner__group_instances + gitlab_runner__host_instances) %} 28 | {% set gitlab_runner__tpl_token = [] %} 29 | {% for item in gitlab_runner__tpl_instance_tokens %} 30 | {% if runner.name == item.name and item.token %} 31 | {% set _ = gitlab_runner__tpl_token.append(item.token) %} 32 | {% endif %} 33 | {% endfor %} 34 | {% if ((runner.state is undefined or runner.state != 'absent') and gitlab_runner__tpl_token) %} 35 | [[runners]] 36 | name = "{{ runner.name }}" 37 | url = "{{ runner.api_url | d(gitlab_runner__api_url) }}" 38 | token = "{{ gitlab_runner__tpl_token[0] }}" 39 | {% set gitlab_runner__tpl_environment = [] %} 40 | {% if gitlab_runner__environment is mapping %} 41 | {% for key, value in gitlab_runner__environment.iteritems() %} 42 | {% set _ = gitlab_runner__tpl_environment.append(key + "=" + value) %} 43 | {% endfor %} 44 | {% elif gitlab_runner__environment is string %} 45 | {% set _ = gitlab_runner__tpl_environment.append(gitlab_runner__environment) %} 46 | {% else %} 47 | {% for element in gitlab_runner__environment %} 48 | {% set _ = gitlab_runner__tpl_environment.append(element) %} 49 | {% endfor %} 50 | {% endif %} 51 | {% if runner.environment|d() %} 52 | {% if runner.environment is mapping %} 53 | {% for key, value in runner.environment.iteritems() %} 54 | {% set _ = gitlab_runner__tpl_environment.append(key + "=" + value) %} 55 | {% endfor %} 56 | {% elif runner.environment is string %} 57 | {% set _ = gitlab_runner__tpl_environment.append(runner.environment) %} 58 | {% else %} 59 | {% for element in runner.environment %} 60 | {% set _ = gitlab_runner__tpl_environment.append(element) %} 61 | {% endfor %} 62 | {% endif %} 63 | {% endif %} 64 | {% if gitlab_runner__tpl_environment %} 65 | environment = [ "{{ gitlab_runner__tpl_environment | join('", "') }}" ] 66 | {% endif %} 67 | {% if runner.tls_ca_file|d() %} 68 | tls-ca-file = "{{ runner.tls_ca_file }}" 69 | {% endif %} 70 | {% if runner.shell|d() %} 71 | shell = "{{ runner.shell }}" 72 | {% endif %} 73 | {% if runner.limit|d() %} 74 | limit = {{ runner.limit }} 75 | {% endif %} 76 | {% if runner.output_limit|d() %} 77 | output_limit = {{ runner.output_limit }} 78 | {% endif %} 79 | {% if runner.builds_dir|d() %} 80 | builds_dir = "{{ runner.builds_dir }}" 81 | {% endif %} 82 | {% if runner.cache_dir|d() %} 83 | cache_dir = "{{ runner.cache_dir }}" 84 | {% endif %} 85 | {% if runner.disable_verbose|d() %} 86 | disable_verbose = {{ runner.disable_verbose | bool | lower }} 87 | {% endif %} 88 | executor = "{{ runner.executor | d(gitlab_runner__executor) }}" 89 | {% if ((runner.executor|d() and runner.executor in [ 'docker', 'docker-ssh', 'docker+machine', 'docker-ssh+machine' ]) or 90 | (gitlab_runner__executor in [ 'docker', 'docker-ssh', 'docker+machine', 'docker-ssh+machine' ])) %} 91 | [runners.docker] 92 | image = "{{ runner.docker_image | d(gitlab_runner__docker_image) }}" 93 | privileged = {{ (runner.docker_privileged | d(gitlab_runner__docker_privileged)) | bool | lower }} 94 | disable_cache = {{ (runner.docker_disable_cache | d(gitlab_runner__docker_disable_cache)) | bool | lower }} 95 | {% if (runner.docker_cache_dir|d() or gitlab_runner__docker_cache_dir) %} 96 | cache_dir = "{{ runner.docker_cache_dir | d(gitlab_runner__docker_cache_dir) }}" 97 | {% endif %} 98 | {% if (runner.docker_host|d() or gitlab_runner__docker_host) %} 99 | host = "{{ runner.docker_host | d(gitlab_runner__docker_host) }}" 100 | {% endif %} 101 | {% if runner.docker_hostname|d() %} 102 | hostname = "{{ runner.docker_hostname }}" 103 | {% endif %} 104 | {% if (runner.docker_tls_cert_path|d() or gitlab_runner__docker_tls_cert_path) %} 105 | tls_cert_path = "{{ runner.docker_tls_cert_path | d(gitlab_runner__docker_tls_cert_path) }}" 106 | {% endif %} 107 | {% if runner.docker_wait_for_services_timeout|d() %} 108 | wait_for_services_timeout = {{ runner.docker_wait_for_services_timeout }} 109 | {% endif %} 110 | {% if runner.docker_image_ttl|d() %} 111 | image_ttl = {{ runner.docker_image_ttl }} 112 | {% endif %} 113 | {% set gitlab_runner__tpl_docker_cap_add = [] %} 114 | {% if gitlab_runner__docker_cap_add %} 115 | {% if gitlab_runner__docker_cap_add is string %} 116 | {% set _ = gitlab_runner__tpl_docker_cap_add.append(gitlab_runner__docker_cap_add) %} 117 | {% else %} 118 | {% for capability in gitlab_runner__docker_cap_add %} 119 | {% set _ = gitlab_runner__tpl_docker_cap_add.append(capability) %} 120 | {% endfor %} 121 | {% endif %} 122 | {% endif %} 123 | {% if runner.docker_cap_add|d() %} 124 | {% if runner.docker_cap_add is string %} 125 | {% set _ = gitlab_runner__tpl_docker_cap_add.append(runner.docker_cap_add) %} 126 | {% else %} 127 | {% for capability in runner.docker_cap_add %} 128 | {% set _ = gitlab_runner__tpl_docker_cap_add.append(capability) %} 129 | {% endfor %} 130 | {% endif %} 131 | {% endif %} 132 | {% if gitlab_runner__tpl_docker_cap_add %} 133 | cap_add = [ "{{ gitlab_runner__tpl_docker_cap_add | join('", "') }}" ] 134 | {% endif %} 135 | {% set gitlab_runner__tpl_docker_cap_drop = [] %} 136 | {% if gitlab_runner__docker_cap_drop %} 137 | {% if gitlab_runner__docker_cap_drop is string %} 138 | {% set _ = gitlab_runner__tpl_docker_cap_drop.append(gitlab_runner__docker_cap_drop) %} 139 | {% else %} 140 | {% for capability in gitlab_runner__docker_cap_drop %} 141 | {% set _ = gitlab_runner__tpl_docker_cap_drop.append(capability) %} 142 | {% endfor %} 143 | {% endif %} 144 | {% endif %} 145 | {% if runner.docker_cap_drop|d() %} 146 | {% if runner.docker_cap_drop is string %} 147 | {% set _ = gitlab_runner__tpl_docker_cap_drop.append(runner.docker_cap_drop) %} 148 | {% else %} 149 | {% for capability in runner.docker_cap_drop %} 150 | {% set _ = gitlab_runner__tpl_docker_cap_drop.append(capability) %} 151 | {% endfor %} 152 | {% endif %} 153 | {% endif %} 154 | {% if gitlab_runner__tpl_docker_cap_drop %} 155 | cap_drop = [ "{{ gitlab_runner__tpl_docker_cap_drop | join('", "') }}" ] 156 | {% endif %} 157 | {% set gitlab_runner__tpl_docker_devices = [] %} 158 | {% if gitlab_runner__docker_devices %} 159 | {% if gitlab_runner__docker_devices is string %} 160 | {% set _ = gitlab_runner__tpl_docker_devices.append(gitlab_runner__docker_devices) %} 161 | {% else %} 162 | {% for device in gitlab_runner__docker_devices %} 163 | {% set _ = gitlab_runner__tpl_docker_devices.append(device) %} 164 | {% endfor %} 165 | {% endif %} 166 | {% endif %} 167 | {% if runner.docker_devices|d() %} 168 | {% if runner.docker_devices is string %} 169 | {% set _ = gitlab_runner__tpl_docker_devices.append(runner.docker_devices) %} 170 | {% else %} 171 | {% for device in runner.docker_devices %} 172 | {% set _ = gitlab_runner__tpl_docker_devices.append(device) %} 173 | {% endfor %} 174 | {% endif %} 175 | {% endif %} 176 | {% if gitlab_runner__tpl_docker_devices %} 177 | devices = [ "{{ gitlab_runner__tpl_docker_devices | join('", "') }}" ] 178 | {% endif %} 179 | {% set gitlab_runner__tpl_docker_extra_hosts = [] %} 180 | {% if gitlab_runner__docker_extra_hosts %} 181 | {% if gitlab_runner__docker_extra_hosts is string %} 182 | {% set _ = gitlab_runner__tpl_docker_extra_hosts.append(gitlab_runner__docker_extra_hosts) %} 183 | {% else %} 184 | {% for host in gitlab_runner__docker_extra_hosts %} 185 | {% set _ = gitlab_runner__tpl_docker_extra_hosts.append(host) %} 186 | {% endfor %} 187 | {% endif %} 188 | {% endif %} 189 | {% if runner.docker_extra_hosts|d() %} 190 | {% if runner.docker_extra_hosts is string %} 191 | {% set _ = gitlab_runner__tpl_docker_extra_hosts.append(runner.docker_extra_hosts) %} 192 | {% else %} 193 | {% for host in runner.docker_extra_hosts %} 194 | {% set _ = gitlab_runner__tpl_docker_extra_hosts.append(host) %} 195 | {% endfor %} 196 | {% endif %} 197 | {% endif %} 198 | {% if gitlab_runner__tpl_docker_extra_hosts %} 199 | extra_hosts = [ "{{ gitlab_runner__tpl_docker_extra_hosts | join('", "') }}" ] 200 | {% endif %} 201 | {% set gitlab_runner__tpl_docker_links = [] %} 202 | {% if gitlab_runner__docker_links %} 203 | {% if gitlab_runner__docker_links is string %} 204 | {% set _ = gitlab_runner__tpl_docker_links.append(gitlab_runner__docker_links) %} 205 | {% else %} 206 | {% for link in gitlab_runner__docker_links %} 207 | {% set _ = gitlab_runner__tpl_docker_links.append(link) %} 208 | {% endfor %} 209 | {% endif %} 210 | {% endif %} 211 | {% if runner.docker_links|d() %} 212 | {% if runner.docker_links is string %} 213 | {% set _ = gitlab_runner__tpl_docker_links.append(runner.docker_links) %} 214 | {% else %} 215 | {% for link in runner.docker_links %} 216 | {% set _ = gitlab_runner__tpl_docker_links.append(link) %} 217 | {% endfor %} 218 | {% endif %} 219 | {% endif %} 220 | {% if gitlab_runner__tpl_docker_links %} 221 | links = [ "{{ gitlab_runner__tpl_docker_links | join('", "') }}" ] 222 | {% endif %} 223 | {% set gitlab_runner__tpl_docker_services = [] %} 224 | {% if gitlab_runner__docker_services %} 225 | {% if gitlab_runner__docker_services is string %} 226 | {% set _ = gitlab_runner__tpl_docker_services.append(gitlab_runner__docker_services) %} 227 | {% else %} 228 | {% for service in gitlab_runner__docker_services %} 229 | {% set _ = gitlab_runner__tpl_docker_services.append(service) %} 230 | {% endfor %} 231 | {% endif %} 232 | {% endif %} 233 | {% if runner.docker_services|d() %} 234 | {% if runner.docker_services is string %} 235 | {% set _ = gitlab_runner__tpl_docker_services.append(runner.docker_services) %} 236 | {% else %} 237 | {% for services in runner.docker_services %} 238 | {% set _ = gitlab_runner__tpl_docker_services.append(service) %} 239 | {% endfor %} 240 | {% endif %} 241 | {% endif %} 242 | {% if gitlab_runner__tpl_docker_services %} 243 | services = [ "{{ gitlab_runner__tpl_docker_services | join('", "') }}" ] 244 | {% endif %} 245 | {% set gitlab_runner__tpl_docker_volumes = [] %} 246 | {% if gitlab_runner__docker_volumes %} 247 | {% if gitlab_runner__docker_volumes is string %} 248 | {% set _ = gitlab_runner__tpl_docker_volumes.append(gitlab_runner__docker_volumes) %} 249 | {% else %} 250 | {% for volume in gitlab_runner__docker_volumes %} 251 | {% set _ = gitlab_runner__tpl_docker_volumes.append(volume) %} 252 | {% endfor %} 253 | {% endif %} 254 | {% endif %} 255 | {% if runner.docker_volumes|d() %} 256 | {% if runner.docker_volumes is string %} 257 | {% set _ = gitlab_runner__tpl_docker_volumes.append(runner.docker_volumes) %} 258 | {% else %} 259 | {% for volume in runner.docker_volumes %} 260 | {% set _ = gitlab_runner__tpl_docker_volumes.append(volume) %} 261 | {% endfor %} 262 | {% endif %} 263 | {% endif %} 264 | {% if gitlab_runner__tpl_docker_volumes %} 265 | volumes = [ "{{ gitlab_runner__tpl_docker_volumes | join('", "') }}" ] 266 | {% endif %} 267 | {% set gitlab_runner__tpl_docker_allowed_images = [] %} 268 | {% if gitlab_runner__docker_allowed_images %} 269 | {% if gitlab_runner__docker_allowed_images is string %} 270 | {% set _ = gitlab_runner__tpl_docker_allowed_images.append(gitlab_runner__docker_allowed_images) %} 271 | {% else %} 272 | {% for image in gitlab_runner__docker_allowed_images %} 273 | {% set _ = gitlab_runner__tpl_docker_allowed_images.append(image) %} 274 | {% endfor %} 275 | {% endif %} 276 | {% endif %} 277 | {% if runner.docker_allowed_images|d() %} 278 | {% if runner.docker_allowed_images is string %} 279 | {% set _ = gitlab_runner__tpl_docker_allowed_images.append(runner.docker_allowed_images) %} 280 | {% else %} 281 | {% for image in runner.docker_allowed_images %} 282 | {% set _ = gitlab_runner__tpl_docker_allowed_images.append(image) %} 283 | {% endfor %} 284 | {% endif %} 285 | {% endif %} 286 | {% if gitlab_runner__tpl_docker_allowed_images %} 287 | allowed_images = [ "{{ gitlab_runner__tpl_docker_allowed_images | join('", "') }}" ] 288 | {% endif %} 289 | {% set gitlab_runner__tpl_docker_allowed_services = [] %} 290 | {% if gitlab_runner__docker_allowed_services %} 291 | {% if gitlab_runner__docker_allowed_services is string %} 292 | {% set _ = gitlab_runner__tpl_docker_allowed_services.append(gitlab_runner__docker_allowed_services) %} 293 | {% else %} 294 | {% for service in gitlab_runner__docker_allowed_services %} 295 | {% set _ = gitlab_runner__tpl_docker_allowed_services.append(service) %} 296 | {% endfor %} 297 | {% endif %} 298 | {% endif %} 299 | {% if runner.docker_allowed_services|d() %} 300 | {% if runner.docker_allowed_services is string %} 301 | {% set _ = gitlab_runner__tpl_docker_allowed_services.append(runner.docker_allowed_services) %} 302 | {% else %} 303 | {% for service in runner.docker_allowed_services %} 304 | {% set _ = gitlab_runner__tpl_docker_allowed_services.append(service) %} 305 | {% endfor %} 306 | {% endif %} 307 | {% endif %} 308 | {% if gitlab_runner__tpl_docker_allowed_services %} 309 | allowed_services = [ "{{ gitlab_runner__tpl_docker_allowed_services | join('", "') }}" ] 310 | {% endif %} 311 | {% if runner.docker_pull_policy|d() %} 312 | pull_policy = "{{ runner.docker_pull_policy }}" 313 | {% endif %} 314 | {% endif %} 315 | {% if ((runner.executor|d() and runner.executor in [ 'parallels' ]) or 316 | (gitlab_runner__executor in [ 'parallels' ])) %} 317 | [runners.parallels] 318 | base_name = "{{ runner.parallels_base_name }}" 319 | {% if runner.parallels_template_name|d() %} 320 | template_name = "{{ runner.parallels_template_name }}" 321 | {% endif %} 322 | {% if runner.parallels_disable_snapshots|d() %} 323 | disable_snapshots = {{ runner.parallels_disable_snapshots | bool | lower }} 324 | {% endif %} 325 | {% endif %} 326 | {% if ((runner.executor|d() and runner.executor in [ 'virtualbox' ]) or 327 | (gitlab_runner__executor in [ 'virtualbox' ])) %} 328 | [runners.virtualbox] 329 | base_name = "{{ runner.virtualbox_base_name }}" 330 | {% if runner.virtualbox_disable_snapshots|d() %} 331 | disable_snapshots = {{ runner.virtualbox_disable_snapshots | bool | lower }} 332 | {% endif %} 333 | {% endif %} 334 | {% if ((runner.executor|d() and runner.executor in [ 'ssh', 'docker-ssh', 'docker-ssh+machine', 'parallels', 'virtualbox' ]) or 335 | (gitlab_runner__executor in [ 'ssh', 'docker-ssh', 'docker-ssh+machine', 'parallels', 'virtualbox' ])) %} 336 | [runners.ssh] 337 | host = "{{ runner.ssh_host | d(gitlab_runner__ssh_host) }}" 338 | port = "{{ runner.ssh_port | d(gitlab_runner__ssh_port) }}" 339 | user = "{{ runner.ssh_user | d(gitlab_runner__ssh_user) }}" 340 | {% if (runner.ssh_password|d() or gitlab_runner__ssh_password) %} 341 | password = "{{ runner.ssh_password | d(gitlab_runner__ssh_password) }}" 342 | {% endif %} 343 | {% if (runner.ssh_identity_file|d() or gitlab_runner__ssh_identity_file) %} 344 | identity_file = "{{ runner.ssh_identity_file | d(gitlab_runner__ssh_identity_file) }}" 345 | {% endif %} 346 | {% endif %} 347 | {% if ((runner.executor|d() and runner.executor in [ 'docker+machine', 'docker-ssh+machine' ]) or 348 | (gitlab_runner__executor in [ 'docker+machine', 'docker-ssh+machine' ])) %} 349 | [runners.machine] 350 | IdleCount = {{ runner.machine_idle_count | d(gitlab_runner__machine_idle_count) }} 351 | IdleTime = {{ runner.machine_idle_time | d(gitlab_runner__machine_idle_time) }} 352 | MaxBuilds = {{ runner.machine_max_builds | d(gitlab_runner__machine_max_builds) }} 353 | MachineName = "{{ runner.machine_name | d(gitlab_runner__machine_name) }}" 354 | MachineDriver = "{{ runner.machine_driver | d(gitlab_runner__machine_driver) }}" 355 | {% if runner.machine_offpeakperiods|d() or gitlab_runner__machine_offpeakperiods %} 356 | OffPeakPeriods = [ 357 | {% if runner.machine_offpeakperiods|d() %} 358 | {% for offpeakperiod in runner.machine_offpeakperiods %} 359 | "{{ offpeakperiod }}"{% if not loop.last %}, 360 | {% endif %} 361 | {% endfor %} 362 | {% else %} 363 | {% for offpeakperiod in gitlab_runner__machine_offpeakperiods %} 364 | "{{ offpeakperiod }}"{% if not loop.last %}, 365 | {% endif %} 366 | {% endfor %} 367 | {% endif %} 368 | ] 369 | {% endif %} 370 | {% if runner.machine_offpeakidlecount|d() or gitlab_runner__machine_offpeakidlecount %} 371 | OffPeakIdleCount = {{ runner.machine_offpeakidlecount | d(gitlab_runner__machine_offpeakidlecount) }} 372 | {% endif %} 373 | {% if runner.machine_offpeakidletime|d() or gitlab_runner__machine_offpeakidletime %} 374 | OffPeakIdleTime = {{ runner.machine_offpeakidletime | d(gitlab_runner__machine_offpeakidletime) }} 375 | {% endif %} 376 | {% if runner.machine_options|d() or gitlab_runner__machine_options %} 377 | MachineOptions = [ 378 | {% if runner.machine_options|d() %} 379 | {% for option in runner.machine_options %} 380 | "{{ option }}"{% if not loop.last %}, 381 | {% endif %} 382 | {% endfor %} 383 | {% else %} 384 | {% for option in gitlab_runner__machine_options %} 385 | "{{ option }}"{% if not loop.last %}, 386 | {% endif %} 387 | {% endfor %} 388 | {% endif %} 389 | 390 | ] 391 | {% endif %} 392 | {% endif %} 393 | {% if ((runner.cache|d() and runner.cache|bool) or gitlab_runner__cache|bool) %} 394 | [runners.cache] 395 | Type = "{{ runner.cache_type | d(gitlab_runner__cache_type) }}" 396 | ServerAddress = "{{ runner.cache_server_address | d(gitlab_runner__cache_server_address) }}" 397 | AccessKey = "{{ runner.cache_access_key | d(gitlab_runner__cache_access_key) }}" 398 | SecretKey = "{{ runner.cache_secret_key | d(gitlab_runner__cache_secret_key) }}" 399 | BucketName = "{{ runner.cache_bucket_name | d(gitlab_runner__cache_bucket_name) }}" 400 | BucketLocation = "{{ runner.cache_bucket_location | d(gitlab_runner__cache_bucket_location) }}" 401 | Insecure = {{ (runner.cache_insecure | d(gitlab_runner__cache_insecure)) | bool | lower }} 402 | {% endif %} 403 | 404 | {% endif %} 405 | {% endfor %} 406 | -------------------------------------------------------------------------------- /templates/etc/sudoers.d/gitlab-runner-vagrant-lxc.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | # lxc 4 | {{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-ls 5 | {{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-info * 6 | {{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-config * 7 | {{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-attach * 8 | {{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env which lxc-* 9 | 10 | # vagrant-lxc (startup) 11 | {{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env cat /var/lib/lxc/*/config 12 | {{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-start -d --name * 13 | 14 | # vagrant-lxc (create) 15 | {{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-create --version 16 | {{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-create -B * --template * --name * -- --tarball {{ gitlab_runner__home }}/.vagrant.d/boxes/* --config {{ gitlab_runner__home }}/.vagrant.d/boxes/* 17 | {{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env tar --numeric-owner -cvzf /tmp/*/rootfs.tar.gz -C /var/lib/lxc/* ./rootfs 18 | {{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env cp -f /tmp/lxc-config* /var/lib/lxc/*/config 19 | {{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env chown root\:root /var/lib/lxc/*/config 20 | {{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env chown *\:* /tmp/*/rootfs.tar.gz 21 | 22 | # vagrant-lxc (shutdown & destroy) 23 | {{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-shutdown --name * 24 | {{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-stop --name * 25 | {{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-destroy --name * 26 | -------------------------------------------------------------------------------- /templates/lookup/gitlab_runner__shell_tags.j2: -------------------------------------------------------------------------------- 1 | {% set output = [ 'shell' ] %} 2 | {% set _ = output.append(ansible_pkg_mgr) %} 3 | {% set _ = output.append(ansible_service_mgr) %} 4 | {% set _ = output.append(ansible_system | lower) %} 5 | {% if (ansible_local|d() and ansible_local.tags|d()) %} 6 | {% set _ = output.extend(ansible_local.tags) %} 7 | {% endif %} 8 | {% if (ansible_local|d() and ansible_local.docker|d() and 9 | (ansible_local.docker.installed|d()) | bool) %} 10 | {% set _ = output.append('docker-host') %} 11 | {% endif %} 12 | {% if (ansible_local|d() and ansible_local.lxc|d() and 13 | (ansible_local.lxc.installed|d()) | bool) %} 14 | {% set _ = output.append('lxc-host') %} 15 | {% endif %} 16 | {% if gitlab_runner__vagrant_lxc|bool %} 17 | {% set _ = output.append('vagrant-lxc') %} 18 | {% endif %} 19 | {% set _ = output.append((ansible_local.core.distribution 20 | if (ansible_local|d() and ansible_local.core|d() and 21 | ansible_local.core.distribution|d()) 22 | else ansible_distribution) | lower) %} 23 | {% set _ = output.append((ansible_local.core.distribution_release 24 | if (ansible_local|d() and ansible_local.core|d() and 25 | ansible_local.core.distribution_release|d()) 26 | else ansible_distribution_release) | lower) %} 27 | {% if ansible_virtualization_type not in [ 'NA' ] %} 28 | {% set _ = output.append(ansible_virtualization_type + '-' + ansible_virtualization_role) %} 29 | {% endif %} 30 | {% set _ = output.append('amd64' if (ansible_architecture == 'x86_64') else ansible_architecture) %} 31 | {{ output | unique }} 32 | --------------------------------------------------------------------------------