├── .gitignore ├── LICENSE ├── README.md ├── ansible.cfg ├── config ├── ansible.cfg ├── ssh_config ├── tmp │ ├── .gitkeep │ ├── retry │ │ └── requirements.retry │ └── ssh │ │ └── .gitkeep └── vault_password ├── docs ├── resources.md ├── skel-start.md └── skel-tips.md ├── group_vars ├── all.yml ├── dev.yml ├── preprod.yml └── prod.yml ├── host_vars └── .gitkeep ├── inventory ├── default.ini ├── dev.ini ├── preprod.ini └── prod.ini ├── playbooks ├── 0_local_requirements.yaml ├── 1_target_test.yml ├── 2_target_requirements.yml └── 3_target_sysadmin.yml ├── plugins ├── README.txt ├── action │ └── .gitkeep ├── callback │ ├── .gitkeep │ └── profile_tasks.py ├── connection │ └── .gitkeep ├── filter │ ├── .gitkeep │ ├── ipaddr.py │ ├── split.py │ └── string_utils.py ├── lookup │ └── .gitkeep ├── modules │ └── .gitkeep └── vars │ └── .gitkeep └── roles ├── local └── .gitkeep ├── profiles └── .gitkeep └── requirements.yml /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Ignore some config files/dir 3 | config/var/* 4 | config/ansible.log 5 | config/known_hosts 6 | 7 | # Ignore uptream code directory 8 | roles/vendors/* 9 | 10 | # Ignore generic files 11 | *.pyc 12 | 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 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 Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ansible-skel 2 | This is my Ansible skeleton. It provide a nice structure to work comfortably with Ansible. You don't need to follow all principes of this structure to use Ansible. 3 | 4 | 5 | ## Goal and features 6 | 7 | The goal of this template is to provide a quick way to start with Ansible. It is a mix of best practices gathered around the web and the result of my own experience. You will find here an extremely modular structure, which should not let the user doubt where to put the correct files. Some advanced topics are covered into [the docs folder](docs/) 8 | 9 | Basically, this structure provides: 10 | 11 | - A nice default ```ansible.cfg``` file 12 | - A way to organise hosts and groups 13 | - An efficient way to organise variables, depending hosts, groups or environments 14 | - It helps to avoid the recommended messy structure 15 | - Most of files are grouped under directories to avoid confusion 16 | - Provide a nice subset of plugins 17 | - Provide default playbooks to really start quickly your development 18 | - Most of file are shortly documented, with a description of most common patterns 19 | 20 | So, just clone this repo, and start to dev :-) 21 | 22 | 23 | ## Quick Start 24 | 25 | To help you to start quickly, there are few entrey point to have your first playbook working. First, you need to add the targets you want to manage: 26 | 27 | ``` 28 | vim inventory/default.ini 29 | ``` 30 | Then add your target hosts under the ```[targets]``` section. If you feel lost, checkout the examples inside the file. Once you have done that, you can run the first playbook, which will ensure you have all required roles. If you don't have them, it will download them from [Ansible Galaxy](https://galaxy.ansible.com/) or from a git repo depending the source. It will install them into ```roles/vendors```. 31 | 32 | ``` 33 | ansible-playbook playbooks/0_local_requirements.yaml 34 | ``` 35 | Once you get there, you are sure you have all requirements to play with Ansible. Then, we will ensure your inventory is correct by trying to connect on all hosts. Obviously, this playbook will not modify at this stage your targets, it's just to be sure your inventory is ok. 36 | ``` 37 | ansible-playbook playbooks/1_target_test.yml 38 | ``` 39 | If it run without errors, you can start to develop you own playbooks and roles. Enjoy! 40 | 41 | 42 | ## File structure 43 | The files structure is organised this way: 44 | ``` 45 | . 46 | ├── LICENSE 47 | ├── README.md # Documentation entry point 48 | ├── ansible.cfg -> config/ansible.cfg # Symlink to vagrant config 49 | ├── config # Configuration directory 50 | │ ├── ansible.cfg # Ansible configuration 51 | │ ├── ssh_config # SSH configuration 52 | │ ├── tmp # Temporary files 53 | │ └── vault_password # Default vault file 54 | ├── docs # Advanced documentation topics 55 | │ ├── skel-start.md 56 | │ └── skel-tips.md 57 | ├── group_vars # Group vars directory 58 | │ ├── all.yml # Common variables to all hosts 59 | │ ├── dev.yml # Dev env variables 60 | │ ├── preprod.yml # Preprod env variables 61 | │ └── prod.yml # Production env variables 62 | ├── host_vars # Host vars directory 63 | ├── inventory # Inventory directory 64 | │ ├── default.ini -> dev.ini # Default inventory to use 65 | │ ├── dev.ini # Dev inventory 66 | │ ├── preprod.ini # Preprod inventary 67 | │ └── prod.ini # Production inventory 68 | ├── playbooks # Playbook directory 69 | │ ├── 0_local_requirements.yaml # Configure local system 70 | │ ├── 1_target_test.yml # Test targets 71 | │ ├── 2_target_requirements.yml # Basic configuration of targets 72 | │ └── 3_target_sysadmin.yml # Advanced confivuration of targets 73 | ├── plugins # Plugin directory 74 | │ ├── action # Action plugins 75 | │ ├── callback # Callback plugins 76 | │ ├── connection # Connection plugins 77 | │ ├── filter # Filter plugins 78 | │ ├── lookup # Lookup plugins 79 | │ ├── modules # Modules plugins 80 | │ └── vars # Vars plugins 81 | └── roles # Roles directory 82 | ├── local # Locale roles 83 | ├── profiles # Profile roles 84 | ├── requirements.yml # Vendor roles list 85 | └── vendors # Vendor roles 86 | ``` 87 | 88 | ## Compatibility 89 | 90 | This skeleton will mainly work with Ansible 2.2. It could run on lower versions, but it has not been tested. Definitely not compatible with 1.x branch. Please checkout the correct branch of this repo to get the matching version. 91 | 92 | As this skeleton comes with some python plugins, you may need to install extra Python dependencies if you want to use them: 93 | 94 | * string_utils: slugify 95 | * ipaddr: netaddr 96 | 97 | Usually, a simple ```pip install slugify netaddr``` should let use those plugins. At this stage, documentation for the plugins is pretty poor, and you may need to read the source code if you want to understand how to use them. 98 | 99 | ## Releases 100 | 101 | * 0.5 - 26/01/2017 102 | * Compatibility for Ansible-2.2 103 | * Make some clean, stabilise the code 104 | * Update the documentation documentation 105 | 106 | ## License 107 | 108 | Please read [GNU AFFERO GENERAL PUBLIC LICENSE](LICENSE). 109 | 110 | ## Credits 111 | There are a lot of goood ideas taken from the [enginyoyen ansible best practice repository](https://github.com/enginyoyen/ansible-best-practises/). The rest comes from some colleagues (Hi [Simon](https://github.com/spiette) !) and my customer experience. 112 | 113 | 114 | -------------------------------------------------------------------------------- /ansible.cfg: -------------------------------------------------------------------------------- 1 | config/ansible.cfg -------------------------------------------------------------------------------- /config/ansible.cfg: -------------------------------------------------------------------------------- 1 | # Configuration file for Ansible 2.2 2 | # Documentation: http://docs.ansible.com/ansible/intro_configuration.html 3 | 4 | [defaults] 5 | 6 | 7 | ######################################## 8 | # Display settings 9 | ######################################## 10 | 11 | # Output display 12 | force_color = 1 13 | nocows = 0 14 | 15 | 16 | # Note: http://docs.ansible.com/ansible/intro_configuration.html#ansible-managed 17 | ansible_managed = Ansible managed - ansible-skel 18 | #ansible_managed = Ansible managed 19 | #ansible_managed = Ansible managed - {file} on {host} 20 | 21 | 22 | # Warn when ansible think it is better to use module. 23 | # Note: http://docs.ansible.com/ansible/intro_configuration.html#id88 24 | command_warnings = True 25 | 26 | # Enable this to debug tasks calls 27 | display_args_to_stdout = False 28 | display_skipped_hosts = false 29 | 30 | 31 | ######################################## 32 | # Playbook settings 33 | ######################################## 34 | 35 | 36 | # Default strategy 37 | strategy = free 38 | 39 | # Make some actions faster with loops 40 | #squash_actions = apk,apt,dnf,homebrew,package,pacman,pkgng,yum,zypper 41 | 42 | # Set it to replace or merge 43 | hash_behaviour = replace 44 | #hash_behaviour = merge, but prefer use combine filter 45 | 46 | # Polling 47 | poll_interval = 15 48 | internal_poll_interval=0.001 49 | 50 | # Number of hosts processed in parallel 51 | forks = 20 52 | 53 | # This shouldn't be touched, but could be useful 54 | error_on_undefined_vars = True 55 | force_handlers = False 56 | 57 | 58 | 59 | ######################################## 60 | # Behaviour settings 61 | ######################################## 62 | 63 | 64 | # Make role variables private 65 | retry_files_enabled = True 66 | 67 | # Fact options 68 | gathering = smart 69 | #gathering = !all 70 | #gathering = smart,network,hardware,virtual,ohai,facter 71 | #gathering = network,!hardware,virtual,!ohai,!facter 72 | 73 | # Locales 74 | module_set_locale = True 75 | module_lang = en_US.UTF-8 76 | 77 | # Enable or disable logs : 78 | # Note put to false in prod 79 | no_log = False 80 | 81 | # TODO Deprecated option ? 82 | no_target_syslog = True 83 | 84 | 85 | 86 | 87 | 88 | ######################################## 89 | # Common destinations 90 | ######################################## 91 | 92 | inventory = inventory/default.ini 93 | hostfile = inventory/default.ini 94 | roles_path = roles/local:roles/profiles:roles/vendors 95 | retry_files_save_path = config/tmp/retry/ 96 | log_path = config/tmp/ansible.log 97 | #vault_password_file = config/vault_password:~/.ansible/default.vault 98 | 99 | 100 | ######################################## 101 | # Plugins paths 102 | ######################################## 103 | 104 | action_plugins = plugins/action:~/.ansible/plugins/action_plugins/:/usr/share/ansible_plugins/action_plugins 105 | callback_plugins = plugins/callback:~/.ansible/plugins/callback_plugins/:/usr/share/ansible_plugins/callback_plugins 106 | connection_plugins = plugins/connection:~/.ansible/plugins/connection_plugins/:/usr/share/ansible_plugins/connection_plugins 107 | filter_plugins = plugins/filter:~/.ansible/plugins/filter_plugins/:/usr/share/ansible_plugins/filter_plugins 108 | lookup_plugins = plugins/lookup:~/.ansible/plugins/lookup_plugins/:/usr/share/ansible_plugins/lookup_plugins 109 | vars_plugins = plugins/vars:~/.ansible/plugins/vars_plugins/:/usr/share/ansible_plugins/vars_plugins 110 | strategy_plugins = plugins/strategy:~/.ansible/plugins/strategy_plugins/:/usr/share/ansible_plugins/strategy_plugins 111 | library = plugins/modules:/usr/share/ansible 112 | 113 | 114 | ######################################## 115 | # Escalation settings 116 | ######################################## 117 | 118 | # Escalation 119 | #become = False 120 | #become_method = su 121 | ## su, pbrun, pfexec, doas, ksu 122 | #become_user = root 123 | become_ask_pass = True 124 | #become_allow_same_user = False 125 | 126 | 127 | # Sudo settings 128 | #sudo_exe = sudo 129 | #sudo_flags=-H -S -n 130 | #sudo_user = root 131 | 132 | 133 | ######################################## 134 | # SSH settings 135 | ######################################## 136 | 137 | #private_key_file = ... 138 | host_key_checking = True 139 | remote_port = 22 140 | remote_user = root 141 | 142 | timeout = 5 143 | transport = smart 144 | #transport = jail,ssh,local,chroot,paramiko,... 145 | 146 | 147 | 148 | [ssh_connection] 149 | # Note: http://docs.ansible.com/ansible/intro_configuration.html#ssh-args 150 | ssh_args = -F config/ssh_config 151 | 152 | # Note: when using "sudo:" operations you must first disable ‘requiretty’ in /etc/sudoers on all managed hosts 153 | pipelining = True 154 | 155 | # Take the second one if errors if filename lenght 156 | control_path = config/tmp/ssh/%%h-%%p-%%r 157 | #control_path = config/tmp/ssh/%%h-%%r 158 | 159 | # Enable only on old systems 160 | # Note: http://docs.ansible.com/ansible/playbooks_acceleration.html 161 | scp_if_ssh = False 162 | 163 | [paramiko_connection] 164 | record_host_keys = True 165 | proxy_command = ssh -W "%h:%p" bastion 166 | 167 | 168 | 169 | ######################################## 170 | # Accelerate mode 171 | ######################################## 172 | #[accelerate] 173 | #accelerate_port = 5099 174 | #accelerate_timeout = 30 175 | #accelerate_connect_timeout = 1.0 176 | #accelerate_daemon_timeout = 30 177 | #accelerate_multi_key = yes 178 | 179 | 180 | ######################################## 181 | # Various 182 | ######################################## 183 | 184 | [selinux] 185 | show_custom_stats = True 186 | 187 | 188 | 189 | ######################################## 190 | # Color settings: TODO DEPRECATEDS ? 191 | ######################################## 192 | 193 | [colors] 194 | #verbose = blue 195 | #warn = bright purple 196 | #error = red 197 | #debug = dark gray 198 | #deprecate = purple 199 | #skip = cyan 200 | #unreachable = red 201 | #ok = green 202 | #changed = yellow 203 | -------------------------------------------------------------------------------- /config/ssh_config: -------------------------------------------------------------------------------- 1 | ControlMaster auto 2 | ControlPersist 30m 3 | UserKnownHostsFile config/known_hosts 4 | HashKnownHosts no 5 | -------------------------------------------------------------------------------- /config/tmp/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrjk/ansible-skel/5fe8f548dabebf4e0422de03b1ee93a5f3647d40/config/tmp/.gitkeep -------------------------------------------------------------------------------- /config/tmp/retry/requirements.retry: -------------------------------------------------------------------------------- 1 | localhost 2 | -------------------------------------------------------------------------------- /config/tmp/ssh/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrjk/ansible-skel/5fe8f548dabebf4e0422de03b1ee93a5f3647d40/config/tmp/ssh/.gitkeep -------------------------------------------------------------------------------- /config/vault_password: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrjk/ansible-skel/5fe8f548dabebf4e0422de03b1ee93a5f3647d40/config/vault_password -------------------------------------------------------------------------------- /docs/resources.md: -------------------------------------------------------------------------------- 1 | 2 | There are some interesting links: 3 | 4 | - https://github.com/bertvv/ansible-skeleton : 5 | - https://github.com/bertvv/ansible-role-skeleton : Very good ideas :D 6 | - https://github.com/bertvv/ansible-skeleton/blob/master/scripts/run-playbook-locally.sh : Windows support? 7 | - https://github.com/KSid/windows-vagrant-ansible/blob/master/provision.sh 8 | - https://github.com/geerlingguy/JJG-Ansible-Windows 9 | - https://github.com/bertvv/docker-images-ansible : Simple way to test playbooks, crazily swagg 10 | - Roles examplaires: 11 | - https://github.com/bertvv/ansible-role-collectd 12 | - https://github.com/bertvv/ansible-role-dhcp 13 | -------------------------------------------------------------------------------- /docs/skel-start.md: -------------------------------------------------------------------------------- 1 | # Quick start 2 | 3 | There is the way to install your dependencies: 4 | 5 | ansible-playbook playbooks/requirements.yaml 6 | 7 | Then you can test your remote host connections: 8 | 9 | ansible-playbook playbooks/test_connection.yml 10 | 11 | At this stage, if everything went well, you can run all other playbooks. 12 | 13 | 14 | # Debug and developping 15 | 16 | ## Dump all variables from an host 17 | 18 | TODO: dumpall 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/skel-tips.md: -------------------------------------------------------------------------------- 1 | 2 | # Quickies 3 | 4 | Where are all parameters specs: 5 | 6 | http://docs.ansible.com/ansible/intro_configuration.html 7 | 8 | How to override default ansible configuration: 9 | 10 | * ANSIBLE_CONFIG (an environment variable) 11 | * ansible.cfg (in the current directory) 12 | * .ansible.cfg (in the home directory) 13 | * /etc/ansible/ansible.cfg 14 | 15 | 16 | What are all constants of Ansible: 17 | 18 | https://github.com/ansible/ansible/blob/devel/lib/ansible/constants.py 19 | 20 | What is the best and pure yaml syntax for Ansible? 21 | 22 | https://support.ansible.com/hc/en-us/articles/201957837-How-do-I-split-an-action-into-a-multi-line-format- 23 | 24 | -------------------------------------------------------------------------------- /group_vars/all.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | # Documentation: 4 | # ###################################### 5 | # Put here all the variables associated to 6 | # your environments. Those variables should be 7 | # common to all of our environment (prod, preprod 8 | # dev, etc ...) 9 | 10 | -------------------------------------------------------------------------------- /group_vars/dev.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | # Documentation: 4 | # ###################################### 5 | # Put here all the variables associated to 6 | # the development environment. To make this work, 7 | # please be sure you have defined a group called [dev] 8 | # into your inventory. You can do this for all of your 9 | # environments. 10 | 11 | targets_debug: true 12 | 13 | -------------------------------------------------------------------------------- /group_vars/preprod.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | targets_debug: false 4 | 5 | -------------------------------------------------------------------------------- /group_vars/prod.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | targets_debug: false 4 | 5 | -------------------------------------------------------------------------------- /host_vars/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrjk/ansible-skel/5fe8f548dabebf4e0422de03b1ee93a5f3647d40/host_vars/.gitkeep -------------------------------------------------------------------------------- /inventory/default.ini: -------------------------------------------------------------------------------- 1 | dev.ini -------------------------------------------------------------------------------- /inventory/dev.ini: -------------------------------------------------------------------------------- 1 | 2 | # Localhost definitions 3 | [local] 4 | local_user ansible_connection=local ansible_become=false 5 | 6 | 7 | # Target host definitions 8 | [targets] 9 | host1 ansible_host=x.x.x.x 10 | 11 | 12 | # # Examples 13 | # ###################################### 14 | # [local] 15 | # local_sudo ansible_connection=local ansible_become=true become_method=sudo 16 | # local_user ansible_connection=local ansible_become=false 17 | # 18 | # [targets] 19 | # web1 ansible_host=x.x.x.x ansible_user=webapp1 20 | # web2 ansible_host=x.x.x.x ansible_user=webapp1 21 | # web3 ansible_host=x.x.x.x ansible_user=wabapp1 22 | # mysql1 ansible_host=x.x.x.x ansible_user=root 23 | # mysql2 ansible_host=x.x.x.x ansible_user=root 24 | # 25 | # [web] 26 | # web1 27 | # web2 28 | # web3 29 | # 30 | # [mysql] 31 | # mysql1 32 | # mysql2 33 | # 34 | # [masters:children] 35 | # web 36 | # mysql 37 | # 38 | # [vagrant:children] 39 | # targets 40 | # 41 | # [dev:children] 42 | # targets 43 | # 44 | # 45 | # # Other useful arguments 46 | # ###################################### 47 | # ansible_host=, 48 | # ansible_user= 49 | # ansible_connection=ssh,local,docker 50 | # ansible_ssh_private_key_file= 51 | # ansible_port= 52 | # ansible_ssh_extra_args= 53 | # 54 | # 55 | # # Local conenction example 56 | # ###################################### 57 | # local_root ansible_host=127.0.0.1 ansible_user=root 58 | # local_sudo ansible_connection=local ansible_become=true become_method=sudo 59 | # local_su ansible_connection=local ansible_become=true become_method=su 60 | # local_ksu ansible_connection=local ansible_become=true become_method=ksu 61 | # local_pfexec ansible_connection=local ansible_become=true become_method=pfexec 62 | # 63 | # 64 | -------------------------------------------------------------------------------- /inventory/preprod.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrjk/ansible-skel/5fe8f548dabebf4e0422de03b1ee93a5f3647d40/inventory/preprod.ini -------------------------------------------------------------------------------- /inventory/prod.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrjk/ansible-skel/5fe8f548dabebf4e0422de03b1ee93a5f3647d40/inventory/prod.ini -------------------------------------------------------------------------------- /playbooks/0_local_requirements.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | # Documentation: 4 | # This playbook will install all dependencies roles. The configuration 5 | # is sourced from roles/requirements.yml and all vendor modules are 6 | # installed by default into roles/vendors/. Each time this playbook is 7 | # call, all vendor roles will be purged. 8 | 9 | 10 | # TODO: Find a work around for task omnipotence 11 | 12 | - hosts: localhost 13 | connection: local 14 | 15 | vars: 16 | force_purge: false 17 | installation_dir: roles/vendors 18 | installation_prefix: ../ 19 | 20 | tasks: 21 | # - name: Get current working path 22 | # command: pwd 23 | 24 | - name: Remove existing vendor roles 25 | file: 26 | path: "{{ installation_prefix }}{{ installation_dir }}" 27 | state: absent 28 | when: force_purge | bool 29 | 30 | - name: Install all vendor roles 31 | command: > 32 | ansible-galaxy install 33 | {{ ( force_purge | bool ) | ternary('--force','') }} 34 | --role-file {{ installation_prefix }}roles/requirements.yml 35 | --roles-path {{ installation_prefix }}{{ installation_dir }} 36 | 37 | -------------------------------------------------------------------------------- /playbooks/1_target_test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Documentation: 3 | # This playbook helps to check if all hosts defined into the inventory 4 | # are joinable. This playbook can also retrieve a dump of all remote 5 | # hosts. This should support most UNIX operating systems (OSX included). 6 | 7 | 8 | - hosts: all 9 | 10 | vars: 11 | dump_vars: true 12 | 13 | pre_tasks: 14 | 15 | - name: Test Ansible ping 16 | ping: 17 | 18 | - name: Run a command to get target release 19 | shell: cat /etc/*ease || sw_vers 20 | changed_when: false 21 | 22 | roles: 23 | - role: dumpall 24 | # when: dump_vars | bool 25 | -------------------------------------------------------------------------------- /playbooks/2_target_requirements.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | # TODO: 4 | # - Install python 2.7 for example 5 | # - Push ssh keys 6 | # - Customize virtualbox config 7 | # Goal: Make the system working 8 | -------------------------------------------------------------------------------- /playbooks/3_target_sysadmin.yml: -------------------------------------------------------------------------------- 1 | 2 | # TODO: 3 | # - should install the default utils: screen, vim, htop, etc ... 4 | # - Should make the user happy to use the vm: bashrc, gitconfig, screenrc, etc ... 5 | 6 | - hosts: vagrant 7 | user: root 8 | roles: 9 | # - dumpall 10 | # - sysadmin 11 | - sysadmin-centos 12 | 13 | -------------------------------------------------------------------------------- /plugins/README.txt: -------------------------------------------------------------------------------- 1 | # TODO 2 | Interesting repos: 3 | https://github.com/ginsys/ansible-plugins 4 | https://gist.github.com/halberom/093d9958adf87a8df880 5 | https://github.com/spiette/ansible-net-filters/blob/master/net_filters.py 6 | 7 | 8 | -------------------------------------------------------------------------------- /plugins/action/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrjk/ansible-skel/5fe8f548dabebf4e0422de03b1ee93a5f3647d40/plugins/action/.gitkeep -------------------------------------------------------------------------------- /plugins/callback/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrjk/ansible-skel/5fe8f548dabebf4e0422de03b1ee93a5f3647d40/plugins/callback/.gitkeep -------------------------------------------------------------------------------- /plugins/callback/profile_tasks.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import os 3 | import time 4 | 5 | 6 | class CallbackModule(object): 7 | """ 8 | A plugin for timing tasks 9 | """ 10 | def __init__(self): 11 | self.stats = {} 12 | self.current = None 13 | 14 | def playbook_on_task_start(self, name, is_conditional): 15 | """ 16 | Logs the start of each task 17 | """ 18 | 19 | if os.getenv("ANSIBLE_PROFILE_DISABLE") is not None: 20 | return 21 | 22 | if self.current is not None: 23 | # Record the running time of the last executed task 24 | self.stats[self.current] = time.time() - self.stats[self.current] 25 | 26 | # Record the start time of the current task 27 | self.current = name 28 | self.stats[self.current] = time.time() 29 | 30 | def playbook_on_stats(self, stats): 31 | """ 32 | Prints the timings 33 | """ 34 | 35 | if os.getenv("ANSIBLE_PROFILE_DISABLE") is not None: 36 | return 37 | 38 | # Record the timing of the very last task 39 | if self.current is not None: 40 | self.stats[self.current] = time.time() - self.stats[self.current] 41 | 42 | # Sort the tasks by their running time 43 | results = sorted( 44 | self.stats.items(), 45 | key=lambda value: value[1], 46 | reverse=True, 47 | ) 48 | 49 | # Just keep the top 10 50 | results = results[:10] 51 | 52 | # Print the timings 53 | for name, elapsed in results: 54 | print( 55 | "{0:-<70}{1:->9}".format( 56 | '{0} '.format(name), 57 | ' {0:.02f}s'.format(elapsed), 58 | ) 59 | ) 60 | 61 | total_seconds = sum([x[1] for x in self.stats.items()]) 62 | print("\nPlaybook finished: {0}, {1} total tasks. {2} elapsed. \n".format( 63 | time.asctime(), 64 | len(self.stats.items()), 65 | datetime.timedelta(seconds=(int(total_seconds))) 66 | ) 67 | ) 68 | -------------------------------------------------------------------------------- /plugins/connection/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrjk/ansible-skel/5fe8f548dabebf4e0422de03b1ee93a5f3647d40/plugins/connection/.gitkeep -------------------------------------------------------------------------------- /plugins/filter/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrjk/ansible-skel/5fe8f548dabebf4e0422de03b1ee93a5f3647d40/plugins/filter/.gitkeep -------------------------------------------------------------------------------- /plugins/filter/ipaddr.py: -------------------------------------------------------------------------------- 1 | # (c) 2014, Maciej Delmanowski 2 | # 3 | # This file is part of Ansible 4 | # 5 | # Ansible is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # Ansible is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with Ansible. If not, see . 17 | 18 | from ansible import errors 19 | 20 | try: 21 | import netaddr 22 | except Exception, e: 23 | raise errors.AnsibleFilterError('python-netaddr package is not installed') 24 | 25 | 26 | # ---- IP address and network filters ---- 27 | 28 | def ipaddr(value, query = '', version = False, alias = 'ipaddr'): 29 | ''' Check if string is an IP address or network and filter it ''' 30 | 31 | query_types = [ 'type', 'bool', 'int', 'version', 'size', 'address', 'ip', 'host', \ 32 | 'network', 'subnet', 'prefix', 'broadcast', 'netmask', 'hostmask', \ 33 | 'unicast', 'multicast', 'private', 'public', 'loopback', 'lo', \ 34 | 'revdns', 'wrap', 'ipv6', 'v6', 'ipv4', 'v4', 'cidr', 'net', \ 35 | 'hostnet', 'router', 'gateway', 'gw', 'host/prefix', 'address/prefix' ] 36 | 37 | if not value: 38 | return False 39 | 40 | elif value == True: 41 | return False 42 | 43 | # Check if value is a list and parse each element 44 | elif isinstance(value, (list, tuple)): 45 | 46 | _ret = [] 47 | for element in value: 48 | if ipaddr(element, str(query), version): 49 | _ret.append(ipaddr(element, str(query), version)) 50 | 51 | if _ret: 52 | return _ret 53 | else: 54 | return list() 55 | 56 | # Check if value is a number and convert it to an IP address 57 | elif str(value).isdigit(): 58 | 59 | # We don't know what IP version to assume, so let's check IPv4 first, 60 | # then IPv6 61 | try: 62 | if ((not version) or (version and version == 4)): 63 | v = netaddr.IPNetwork('0.0.0.0/0') 64 | v.value = int(value) 65 | v.prefixlen = 32 66 | elif version and version == 6: 67 | v = netaddr.IPNetwork('::/0') 68 | v.value = int(value) 69 | v.prefixlen = 128 70 | 71 | # IPv4 didn't work the first time, so it definitely has to be IPv6 72 | except: 73 | try: 74 | v = netaddr.IPNetwork('::/0') 75 | v.value = int(value) 76 | v.prefixlen = 128 77 | 78 | # The value is too big for IPv6. Are you a nanobot? 79 | except: 80 | return False 81 | 82 | # We got an IP address, let's mark it as such 83 | value = str(v) 84 | vtype = 'address' 85 | 86 | # value has not been recognized, check if it's a valid IP string 87 | else: 88 | try: 89 | v = netaddr.IPNetwork(value) 90 | 91 | # value is a valid IP string, check if user specified 92 | # CIDR prefix or just an IP address, this will indicate default 93 | # output format 94 | try: 95 | address, prefix = value.split('/') 96 | vtype = 'network' 97 | except: 98 | vtype = 'address' 99 | 100 | # value hasn't been recognized, maybe it's a numerical CIDR? 101 | except: 102 | try: 103 | address, prefix = value.split('/') 104 | address.isdigit() 105 | address = int(address) 106 | prefix.isdigit() 107 | prefix = int(prefix) 108 | 109 | # It's not numerical CIDR, give up 110 | except: 111 | return False 112 | 113 | # It is something, so let's try and build a CIDR from the parts 114 | try: 115 | v = netaddr.IPNetwork('0.0.0.0/0') 116 | v.value = address 117 | v.prefixlen = prefix 118 | 119 | # It's not a valid IPv4 CIDR 120 | except: 121 | try: 122 | v = netaddr.IPNetwork('::/0') 123 | v.value = address 124 | v.prefixlen = prefix 125 | 126 | # It's not a valid IPv6 CIDR. Give up. 127 | except: 128 | return False 129 | 130 | # We have a valid CIDR, so let's write it in correct format 131 | value = str(v) 132 | vtype = 'network' 133 | 134 | v_ip = netaddr.IPAddress(str(v.ip)) 135 | 136 | # We have a query string but it's not in the known query types. Check if 137 | # that string is a valid subnet, if so, we can check later if given IP 138 | # address/network is inside that specific subnet 139 | try: 140 | if query and query not in query_types and ipaddr(query, 'network'): 141 | iplist = netaddr.IPSet([netaddr.IPNetwork(query)]) 142 | query = 'cidr_lookup' 143 | except: 144 | None 145 | 146 | # This code checks if value maches the IP version the user wants, ie. if 147 | # it's any version ("ipaddr()"), IPv4 ("ipv4()") or IPv6 ("ipv6()") 148 | # If version does not match, return False 149 | if version and v.version != version: 150 | return False 151 | 152 | # We don't have any query to process, so just check what type the user 153 | # expects, and return the IP address in a correct format 154 | if not query: 155 | if v: 156 | if vtype == 'address': 157 | return str(v.ip) 158 | elif vtype == 'network': 159 | return str(v) 160 | 161 | elif query == 'type': 162 | if v.size == 1: 163 | return 'address' 164 | if v.size > 1: 165 | if v.ip != v.network: 166 | return 'address' 167 | else: 168 | return 'network' 169 | 170 | elif query == 'bool': 171 | if v: 172 | return True 173 | 174 | elif query == 'int': 175 | if vtype == 'address': 176 | return int(v.ip) 177 | elif vtype == 'network': 178 | return str(int(v.ip)) + '/' + str(int(v.prefixlen)) 179 | 180 | elif query == 'version': 181 | return v.version 182 | 183 | elif query == 'size': 184 | return v.size 185 | 186 | elif query in [ 'address', 'ip' ]: 187 | if v.size == 1: 188 | return str(v.ip) 189 | if v.size > 1: 190 | if v.ip != v.network: 191 | return str(v.ip) 192 | 193 | elif query == 'host': 194 | if v.size == 1: 195 | return str(v) 196 | elif v.size > 1: 197 | if v.ip != v.network: 198 | return str(v.ip) + '/' + str(v.prefixlen) 199 | 200 | elif query == 'net': 201 | if v.size > 1: 202 | if v.ip == v.network: 203 | return str(v.network) + '/' + str(v.prefixlen) 204 | 205 | elif query in [ 'hostnet', 'router', 'gateway', 'gw', 'host/prefix', 'address/prefix' ]: 206 | if v.size > 1: 207 | if v.ip != v.network: 208 | return str(v.ip) + '/' + str(v.prefixlen) 209 | 210 | elif query == 'network': 211 | if v.size > 1: 212 | return str(v.network) 213 | 214 | elif query == 'subnet': 215 | return str(v.cidr) 216 | 217 | elif query == 'cidr': 218 | return str(v) 219 | 220 | elif query == 'prefix': 221 | return int(v.prefixlen) 222 | 223 | elif query == 'broadcast': 224 | if v.size > 1: 225 | return str(v.broadcast) 226 | 227 | elif query == 'netmask': 228 | if v.size > 1: 229 | return str(v.netmask) 230 | 231 | elif query == 'hostmask': 232 | return str(v.hostmask) 233 | 234 | elif query == 'unicast': 235 | if v.is_unicast(): 236 | return value 237 | 238 | elif query == 'multicast': 239 | if v.is_multicast(): 240 | return value 241 | 242 | elif query == 'link-local': 243 | if v.version == 4: 244 | if ipaddr(str(v_ip), '169.254.0.0/24'): 245 | return value 246 | 247 | elif v.version == 6: 248 | if ipaddr(str(v_ip), 'fe80::/10'): 249 | return value 250 | 251 | elif query == 'private': 252 | if v.is_private(): 253 | return value 254 | 255 | elif query == 'public': 256 | if v_ip.is_unicast() and not v_ip.is_private() and \ 257 | not v_ip.is_loopback() and not v_ip.is_netmask() and \ 258 | not v_ip.is_hostmask(): 259 | return value 260 | 261 | elif query in [ 'loopback', 'lo' ]: 262 | if v_ip.is_loopback(): 263 | return value 264 | 265 | elif query == 'revdns': 266 | return v_ip.reverse_dns 267 | 268 | elif query == 'wrap': 269 | if v.version == 6: 270 | if vtype == 'address': 271 | return '[' + str(v.ip) + ']' 272 | elif vtype == 'network': 273 | return '[' + str(v.ip) + ']/' + str(v.prefixlen) 274 | else: 275 | return value 276 | 277 | elif query in [ 'ipv6', 'v6' ]: 278 | if v.version == 4: 279 | return str(v.ipv6()) 280 | else: 281 | return value 282 | 283 | elif query in [ 'ipv4', 'v4' ]: 284 | if v.version == 6: 285 | try: 286 | return str(v.ipv4()) 287 | except: 288 | return False 289 | else: 290 | return value 291 | 292 | elif query == '6to4': 293 | 294 | if v.version == 4: 295 | 296 | if v.size == 1: 297 | ipconv = str(v.ip) 298 | elif v.size > 1: 299 | if v.ip != v.network: 300 | ipconv = str(v.ip) 301 | else: 302 | ipconv = False 303 | 304 | if ipaddr(ipconv, 'public'): 305 | numbers = list(map(int, ipconv.split('.'))) 306 | 307 | try: 308 | return '2002:{:02x}{:02x}:{:02x}{:02x}::1/48'.format(*numbers) 309 | except: 310 | return False 311 | 312 | elif v.version == 6: 313 | if vtype == 'address': 314 | if ipaddr(str(v), '2002::/16'): 315 | return value 316 | elif vtype == 'network': 317 | if v.ip != v.network: 318 | if ipaddr(str(v.ip), '2002::/16'): 319 | return value 320 | else: 321 | return False 322 | 323 | elif query == 'cidr_lookup': 324 | try: 325 | if v in iplist: 326 | return value 327 | except: 328 | return False 329 | 330 | else: 331 | try: 332 | float(query) 333 | if v.size == 1: 334 | if vtype == 'address': 335 | return str(v.ip) 336 | elif vtype == 'network': 337 | return str(v) 338 | 339 | elif v.size > 1: 340 | try: 341 | return str(v[query]) + '/' + str(v.prefixlen) 342 | except: 343 | return False 344 | 345 | else: 346 | return value 347 | 348 | except: 349 | raise errors.AnsibleFilterError(alias + ': unknown filter type: %s' % query) 350 | 351 | return False 352 | 353 | 354 | def ipwrap(value, query = ''): 355 | try: 356 | if isinstance(value, (list, tuple)): 357 | _ret = [] 358 | for element in value: 359 | if ipaddr(element, query, version = False, alias = 'ipwrap'): 360 | _ret.append(ipaddr(element, 'wrap')) 361 | else: 362 | _ret.append(element) 363 | 364 | return _ret 365 | else: 366 | _ret = ipaddr(value, query, version = False, alias = 'ipwrap') 367 | if _ret: 368 | return ipaddr(_ret, 'wrap') 369 | else: 370 | return value 371 | 372 | except: 373 | return value 374 | 375 | 376 | def ipv4(value, query = ''): 377 | return ipaddr(value, query, version = 4, alias = 'ipv4') 378 | 379 | 380 | def ipv6(value, query = ''): 381 | return ipaddr(value, query, version = 6, alias = 'ipv6') 382 | 383 | 384 | # Split given subnet into smaller subnets or find out the biggest subnet of 385 | # a given IP address with given CIDR prefix 386 | # Usage: 387 | # 388 | # - address or address/prefix | ipsubnet 389 | # returns CIDR subnet of a given input 390 | # 391 | # - address/prefix | ipsubnet(cidr) 392 | # returns number of possible subnets for given CIDR prefix 393 | # 394 | # - address/prefix | ipsubnet(cidr, index) 395 | # returns new subnet with given CIDR prefix 396 | # 397 | # - address | ipsubnet(cidr) 398 | # returns biggest subnet with given CIDR prefix that address belongs to 399 | # 400 | # - address | ipsubnet(cidr, index) 401 | # returns next indexed subnet which contains given address 402 | def ipsubnet(value, query = '', index = 'x'): 403 | ''' Manipulate IPv4/IPv6 subnets ''' 404 | 405 | try: 406 | vtype = ipaddr(value, 'type') 407 | if vtype == 'address': 408 | v = ipaddr(value, 'cidr') 409 | elif vtype == 'network': 410 | v = ipaddr(value, 'subnet') 411 | 412 | value = netaddr.IPNetwork(v) 413 | except: 414 | return False 415 | 416 | if not query: 417 | return str(value) 418 | 419 | elif str(query).isdigit(): 420 | vsize = ipaddr(v, 'size') 421 | query = int(query) 422 | 423 | try: 424 | float(index) 425 | index = int(index) 426 | 427 | if vsize > 1: 428 | try: 429 | return str(list(value.subnet(query))[index]) 430 | except: 431 | return False 432 | 433 | elif vsize == 1: 434 | try: 435 | return str(value.supernet(query)[index]) 436 | except: 437 | return False 438 | 439 | except: 440 | if vsize > 1: 441 | try: 442 | return str(len(list(value.subnet(query)))) 443 | except: 444 | return False 445 | 446 | elif vsize == 1: 447 | try: 448 | return str(value.supernet(query)[0]) 449 | except: 450 | return False 451 | 452 | return False 453 | 454 | 455 | # ---- HWaddr / MAC address filters ---- 456 | 457 | def hwaddr(value, query = '', alias = 'hwaddr'): 458 | ''' Check if string is a HW/MAC address and filter it ''' 459 | 460 | try: 461 | v = netaddr.EUI(value) 462 | except: 463 | if query and query not in [ 'bool' ]: 464 | raise errors.AnsibleFilterError(alias + ': not a hardware address: %s' % value) 465 | 466 | if not query: 467 | if v: 468 | return value 469 | 470 | elif query == 'bool': 471 | if v: 472 | return True 473 | 474 | elif query in [ 'win', 'eui48' ]: 475 | v.dialect = netaddr.mac_eui48 476 | return str(v) 477 | 478 | elif query == 'unix': 479 | v.dialect = netaddr.mac_unix 480 | return str(v) 481 | 482 | elif query in [ 'pgsql', 'postgresql', 'psql' ]: 483 | v.dialect = netaddr.mac_pgsql 484 | return str(v) 485 | 486 | elif query == 'cisco': 487 | v.dialect = netaddr.mac_cisco 488 | return str(v) 489 | 490 | elif query == 'bare': 491 | v.dialect = netaddr.mac_bare 492 | return str(v) 493 | 494 | elif query == 'linux': 495 | v.dialect = mac_linux 496 | return str(v) 497 | 498 | else: 499 | raise errors.AnsibleFilterError(alias + ': unknown filter type: %s' % query) 500 | 501 | return False 502 | 503 | class mac_linux(netaddr.mac_unix): pass 504 | mac_linux.word_fmt = '%.2x' 505 | 506 | 507 | def macaddr(value, query = ''): 508 | return hwaddr(value, query, alias = 'macaddr') 509 | 510 | 511 | # ---- Ansible filters ---- 512 | 513 | class FilterModule(object): 514 | ''' IP address and network manipulation filters ''' 515 | 516 | def filters(self): 517 | return { 518 | 519 | # IP addresses and networks 520 | 'ipaddr': ipaddr, 521 | 'ipwrap': ipwrap, 522 | 'ipv4': ipv4, 523 | 'ipv6': ipv6, 524 | 'ipsubnet': ipsubnet, 525 | 526 | # MAC / HW addresses 527 | 'hwaddr': hwaddr, 528 | 'macaddr': macaddr 529 | 530 | } 531 | 532 | -------------------------------------------------------------------------------- /plugins/filter/split.py: -------------------------------------------------------------------------------- 1 | # From: https://github.com/timraasveld/ansible-string-split-filter 2 | 3 | from ansible import errors 4 | import re 5 | 6 | 7 | def split_string(string, seperator=' '): 8 | try: 9 | return string.split(seperator) 10 | except Exception, e: 11 | raise errors.AnsibleFilterError('split plugin error: %s, string=%s' % str(e),str(string) ) 12 | 13 | def split_regex(string, seperator_pattern): 14 | try: 15 | return re.split(seperator_pattern, string) 16 | except Exception, e: 17 | raise errors.AnsibleFilterError('split plugin error: %s' % str(e)) 18 | 19 | class FilterModule(object): 20 | ''' A filter to split a string into a list. ''' 21 | def filters(self): 22 | return { 23 | 'split' : split_string, 24 | 'split_regex' : split_regex, 25 | } 26 | -------------------------------------------------------------------------------- /plugins/filter/string_utils.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # From: https://github.com/lxhunter/ansible-filter-plugins/blob/master/collection_utils.py 4 | 5 | # Import modules 6 | import unittest 7 | import re 8 | import unicodedata 9 | import textwrap 10 | 11 | # Try to find external modules 12 | try: 13 | from slugify import slugify 14 | HAS_SLUGIFY = True 15 | except ImportError: 16 | HAS_SLUGIFY = False 17 | 18 | 19 | def _string_sanity_check(string): 20 | if string is None: 21 | return '' 22 | if not isinstance(string, basestring): 23 | return str(string) 24 | return string 25 | 26 | 27 | ''' Converts underscored or dasherized string to a camelized one. Begins with a lower case letter unless it starts with an underscore, dash or an upper case letter. ''' 28 | 29 | 30 | def camelize(string, uppercase_first_letter=True): 31 | sanitzed_string = _string_sanity_check(string) 32 | replaced = re.sub(r"^[-_\s]+", "", sanitzed_string) 33 | if uppercase_first_letter: 34 | return re.sub(r"(?:^|[-_\s]+)(.)", lambda m: m.group(1).upper(), replaced) 35 | else: 36 | return replaced[0].lower() + camelize(replaced)[1:] 37 | 38 | ''' Converts string to camelized class name. First letter is always upper case. ''' 39 | 40 | 41 | def classify(string): 42 | sanitzed_string = _string_sanity_check(string) 43 | replaced = re.sub( 44 | r"(?:^|[\.]+)(.)", lambda m: m.group(1).upper(), sanitzed_string) 45 | return camelize(replaced) 46 | 47 | ''' Trim and replace multiple spaces with a single space. ''' 48 | 49 | 50 | def clean(string): 51 | sanitzed_string = _string_sanity_check(string) 52 | return " ".join(sanitzed_string.split()) 53 | 54 | ''' Counts the number of times needle is in haystack ''' 55 | 56 | 57 | def count(haystack, needle): 58 | haystack = _string_sanity_check(haystack) 59 | needle = _string_sanity_check(needle) 60 | if needle is '' or needle is None: 61 | return 0 62 | return haystack.count(needle) 63 | 64 | ''' Converts a underscored or camelized string into an dasherized one ''' 65 | 66 | 67 | def dasherize(string): 68 | sanitzed_string = _string_sanity_check(string) 69 | striped = sanitzed_string.strip() 70 | replaced = re.sub(r'([A-Z])', r'-\1', striped) 71 | replaced = re.sub(r'[-_\s]+', r'-', replaced) 72 | replaced = re.sub(r'^-', r'', replaced) 73 | return replaced.lower() 74 | 75 | ''' Converts first letter of the string to lowercase. ''' 76 | 77 | 78 | def decapitalize(string): 79 | sanitzed_string = _string_sanity_check(string) 80 | if sanitzed_string is '' or sanitzed_string is None: 81 | return '' 82 | return sanitzed_string[0].lower() + sanitzed_string[1:] 83 | 84 | 85 | ''' Dedent unnecessary indentation. ''' 86 | 87 | 88 | def dedent(string): 89 | sanitzed_string = _string_sanity_check(string) 90 | if sanitzed_string is '' or sanitzed_string is None: 91 | return '' 92 | return textwrap.dedent(sanitzed_string) 93 | 94 | ''' Checks whether the string ends with needle at position (default: haystack.length). ''' 95 | 96 | 97 | def ends_with(haystack, needle, beg=0, end=None): 98 | haystack = _string_sanity_check(haystack) 99 | needle = _string_sanity_check(needle) 100 | if end is None: 101 | end = len(haystack) 102 | return haystack.endswith(needle, beg, end) 103 | 104 | ''' Converts HTML special characters to their entity equivalents. This function supports cent, yen, euro, pound, lt, gt, copy, reg, quote, amp, apos. ''' 105 | 106 | 107 | def escape_html(haystack): 108 | haystack = _string_sanity_check(haystack) 109 | return haystack.replace('&' , '&') \ 110 | .replace('¢' , '¢') \ 111 | .replace('£' , '£') \ 112 | .replace('¥' , '¥') \ 113 | .replace('€' , '€') \ 114 | .replace('©' , '©') \ 115 | .replace('®' , '®') \ 116 | .replace('<' , '<') \ 117 | .replace('>' , '>') \ 118 | .replace('"' , '"') \ 119 | .replace("'", ''') 120 | 121 | ''' Converts an underscored, camelized, or dasherized string into a humanized one. Also removes beginning and ending whitespace, and removes the postfix '_id'. ''' 122 | 123 | 124 | def humanize(string): 125 | if string is '' or string is None: 126 | return '' 127 | sanitzed_string = _string_sanity_check(string) 128 | underscored = underscore(sanitzed_string) 129 | replaced = re.sub('_id$', '', underscored) 130 | replaced = replaced.replace("_", ' ') 131 | replaced = replaced.replace("-", ' ') 132 | striped = replaced.strip() 133 | firstUp = striped[0].upper() + striped[1:] 134 | return re.sub(' +', ' ', firstUp) 135 | 136 | ''' Tests if string contains a substring. ''' 137 | 138 | 139 | def includes(haystack, needle): 140 | haystack = _string_sanity_check(haystack) 141 | needle = _string_sanity_check(needle) 142 | if needle in haystack: 143 | return True 144 | else: 145 | return False 146 | 147 | ''' Insert word in string at the defined position ''' 148 | 149 | 150 | def insert(string, index, substring): 151 | sanitzed_string = _string_sanity_check(string) 152 | sanitzed_substring = _string_sanity_check(substring) 153 | return sanitzed_string[:index] + sanitzed_substring + sanitzed_string[index:] 154 | 155 | ''' Returns split lines as an array ''' 156 | 157 | 158 | def lines(string): 159 | sanitzed_string = _string_sanity_check(string) 160 | return re.split('\r\n?|\n', sanitzed_string) 161 | 162 | ''' Return the string left justified in a string of length width. ''' 163 | 164 | 165 | def lpad(string, width, fillchar=' '): 166 | sanitzed_string = _string_sanity_check(string) 167 | return sanitzed_string.rjust(width, fillchar) 168 | 169 | ''' Return a copy of the string with leading characters removed. ''' 170 | 171 | 172 | def ltrim(string, chars=None): 173 | sanitzed_string = _string_sanity_check(string) 174 | if isinstance(chars, int): 175 | chars = str(chars) 176 | return sanitzed_string.lstrip(chars) 177 | 178 | ''' Repeats a string count times. ''' 179 | 180 | 181 | def repeat(string, count, separator=None): 182 | sanitzed_string = _string_sanity_check(string) 183 | sanitzed_count = int(count) 184 | if separator is None: 185 | return sanitzed_count * sanitzed_string 186 | sanitzed_separator = str(separator) 187 | return (sanitzed_count * (sanitzed_string + str(sanitzed_separator)))[:-len(sanitzed_separator)] 188 | 189 | ''' Return the string right justified in a string of length width. ''' 190 | 191 | 192 | def rpad(string, width, fillchar=' '): 193 | sanitzed_string = _string_sanity_check(string) 194 | return sanitzed_string.ljust(width, fillchar) 195 | 196 | ''' Return a copy of the string with trailing characters removed. ''' 197 | 198 | 199 | def rtrim(string, chars=None): 200 | sanitzed_string = _string_sanity_check(string) 201 | if isinstance(chars, int): 202 | chars = str(chars) 203 | return sanitzed_string.rstrip(chars) 204 | 205 | 206 | def _slugify(string, entities=True, decimal=True, hexadecimal=True, max_length=0, word_boundary=False, 207 | separator='-', save_order=False, stopwords=()): 208 | if not HAS_SLUGIFY: 209 | module.fail_json(msg='slugify required for this module') 210 | if string is None: 211 | return '' 212 | sanitzed_string = _string_sanity_check(string) 213 | return slugify(sanitzed_string, entities, decimal, hexadecimal, max_length, word_boundary, 214 | separator, save_order, stopwords) 215 | 216 | ''' Replace string in string ''' 217 | 218 | 219 | def splice(string, index, how_many, substring): 220 | sanitzed_string = _string_sanity_check(string) 221 | sanitzed_substring = _string_sanity_check(substring) 222 | return sanitzed_string[:index] + sanitzed_substring + sanitzed_string[index + how_many:] 223 | 224 | ''' Checks whether the string begins with the needle at position (default: 0). ''' 225 | 226 | 227 | def starts_with(haystack, needle, beg=0, end=None): 228 | sanitzed_haystack = _string_sanity_check(haystack) 229 | sanitzed_needle = _string_sanity_check(needle) 230 | if end is None: 231 | end = len(sanitzed_haystack) 232 | return sanitzed_haystack.startswith(sanitzed_needle, beg, end) 233 | 234 | ''' Returns the successor to string ''' 235 | 236 | 237 | def successor(string): 238 | sanitzed_string = _string_sanity_check(string) 239 | strip_zs = sanitzed_string.rstrip('z') 240 | if strip_zs: 241 | return strip_zs[:-1] + chr(ord(strip_zs[-1]) + 1) + 'a' * (len(sanitzed_string) - len(strip_zs)) 242 | else: 243 | return 'a' * (len(sanitzed_string) + 1) 244 | 245 | ''' Returns a copy of the string in which all the case-based characters have had their case swapped.''' 246 | 247 | 248 | def swap_case(string): 249 | sanitzed_string = _string_sanity_check(string) 250 | return string.swapcase() 251 | 252 | 253 | def transliterate(string): 254 | sanitzed_string = _string_sanity_check(string) 255 | normalized = unicodedata.normalize('NFKD', sanitzed_string) 256 | return normalized.encode('ascii', 'ignore').decode('ascii') 257 | 258 | ''' Converts a underscored or camelized string into an dasherized one ''' 259 | 260 | 261 | def underscore(string): 262 | sanitzed_string = _string_sanity_check(string) 263 | replaced = re.sub(r"([A-Z]+)([A-Z][a-z])", r'\1_\2', sanitzed_string) 264 | replaced = re.sub(r"([a-z\d])([A-Z])", r'\1_\2', replaced) 265 | return replaced.replace("-", "_").lower() 266 | 267 | ''' Converts entity characters to HTML equivalents. This function supports cent, yen, euro, pound, lt, gt, copy, reg, quote, amp, apos, nbsp. ''' 268 | 269 | 270 | def unescape_html(haystack): 271 | haystack = _string_sanity_check(haystack) 272 | return haystack.replace(''', "'") \ 273 | .replace('¢', '¢') \ 274 | .replace('£', '£') \ 275 | .replace('¥', '¥') \ 276 | .replace('€', '€') \ 277 | .replace('©', '©') \ 278 | .replace('®', '®') \ 279 | .replace('<', '<') \ 280 | .replace('>', '>') \ 281 | .replace('"', '"') \ 282 | .replace(''', "'") \ 283 | .replace(''', "'") \ 284 | .replace(' ', ' ') \ 285 | .replace('&', '&') 286 | 287 | # --- 288 | 289 | 290 | class FilterModule(object): 291 | 292 | def filters(self): 293 | return { 294 | 'camelize': camelize, 295 | 'clean': clean, 296 | 'classify': classify, 297 | 'count': count, 298 | 'dasherize': dasherize, 299 | 'decapitalize': decapitalize, 300 | 'dedent': dedent, 301 | 'ends_with': ends_with, 302 | 'escape_html': escape_html, 303 | 'humanize': humanize, 304 | 'includes': includes, 305 | 'insert': insert, 306 | 'lines': lines, 307 | 'lpad': lpad, 308 | 'ltrim': ltrim, 309 | 'rpad': rpad, 310 | 'rtrim': rtrim, 311 | 'repeat': repeat, 312 | 'slugify': _slugify, 313 | 'splice': splice, 314 | 'starts_with': starts_with, 315 | 'successor': successor, 316 | 'swap_case': swap_case, 317 | 'transliterate': transliterate, 318 | 'underscore': underscore, 319 | 'unescape_html': unescape_html 320 | } 321 | 322 | # --- 323 | 324 | 325 | class TestStringUtlisFunctions(unittest.TestCase): 326 | 327 | def test_camelize(self): 328 | self.assertEqual( 329 | camelize('the_camelize_string_method', False), 'theCamelizeStringMethod') 330 | self.assertEqual( 331 | camelize('webkit-transform', False), 'webkitTransform') 332 | self.assertEqual(camelize('webkit-transform', True), 'WebkitTransform') 333 | self.assertEqual( 334 | camelize('-the-camelize-string-method', True), 'TheCamelizeStringMethod') 335 | self.assertEqual( 336 | camelize('_the_camelize_string_method'), 'TheCamelizeStringMethod') 337 | self.assertEqual( 338 | camelize('The-camelize-string-method'), 'TheCamelizeStringMethod') 339 | self.assertEqual( 340 | camelize('the camelize string method', False), 'theCamelizeStringMethod') 341 | self.assertEqual( 342 | camelize(' the camelize string method', False), 'theCamelizeStringMethod') 343 | self.assertEqual( 344 | camelize('the camelize string method', False), 'theCamelizeStringMethod') 345 | self.assertEqual(camelize(' with spaces', False), 'withSpaces') 346 | self.assertEqual(camelize("_som eWeird---name"), 'SomEWeirdName') 347 | self.assertEqual( 348 | camelize(''), '', 'Camelize empty string returns empty string') 349 | self.assertEqual( 350 | camelize(None), '', 'Camelize null returns empty string') 351 | self.assertEqual(camelize(123), '123') 352 | 353 | def test_classify(self): 354 | self.assertEqual(classify(1), '1') 355 | self.assertEqual(classify('some_class_name'), 'SomeClassName') 356 | self.assertEqual( 357 | classify('my wonderfull class_name'), 'MyWonderfullClassName') 358 | self.assertEqual( 359 | classify('my wonderfull.class.name'), 'MyWonderfullClassName') 360 | self.assertEqual(classify('myLittleCamel'), 'MyLittleCamel') 361 | self.assertEqual( 362 | classify('myLittleCamel.class.name'), 'MyLittleCamelClassName') 363 | self.assertEqual(classify(123), '123') 364 | self.assertEqual(classify(''), '') 365 | self.assertEqual(classify(None), '') 366 | 367 | def test_clean(self): 368 | self.assertEqual(clean(' foo bar '), 'foo bar') 369 | self.assertEqual(clean(123), '123') 370 | self.assertEqual( 371 | clean(''), '', 'cleaning empty string returns empty string') 372 | self.assertEqual(clean(None), '', 'cleaning null returns empty string') 373 | self.assertEqual(clean(' foo bar '), 'foo bar') 374 | self.assertEqual(clean('foo bar '), 'foo bar') 375 | self.assertEqual(clean(' foo\t bar '), 'foo bar') 376 | 377 | def test_count(self): 378 | self.assertEqual(count('Hello world', 'l'), 3) 379 | self.assertEqual(count('Hello world', 'Hello'), 1) 380 | self.assertEqual(count('Hello world', 'foo'), 0) 381 | self.assertEqual(count('x.xx....x.x', 'x'), 5) 382 | self.assertEqual(count('', 'x'), 0) 383 | self.assertEqual(count(None, 'x'), 0) 384 | self.assertEqual(count(12345, 1), 1) 385 | self.assertEqual(count(11345, 1), 2) 386 | self.assertEqual(count('Hello World', ''), 0) 387 | self.assertEqual(count('Hello World', None), 0) 388 | self.assertEqual(count('', ''), 0) 389 | 390 | def test_dasherize(self): 391 | self.assertEqual(dasherize('foo_bar'), 'foo-bar') 392 | self.assertEqual( 393 | dasherize('the_dasherize_string_method'), 'the-dasherize-string-method') 394 | self.assertEqual(dasherize('thisIsATest'), 'this-is-a-test') 395 | self.assertEqual(dasherize('this Is A Test'), 'this-is-a-test') 396 | self.assertEqual(dasherize('thisIsATest123'), 'this-is-a-test123') 397 | self.assertEqual(dasherize('123thisIsATest'), '123this-is-a-test') 398 | self.assertEqual( 399 | dasherize('the dasherize string method'), 'the-dasherize-string-method') 400 | self.assertEqual( 401 | dasherize('the dasherize string method '), 'the-dasherize-string-method') 402 | self.assertEqual(dasherize('téléphone'), 'téléphone') 403 | self.assertEqual(dasherize('foo$bar'), 'foo$bar') 404 | self.assertEqual(dasherize(''), '') 405 | self.assertEqual(dasherize(None), '') 406 | self.assertEqual(dasherize(123), '123') 407 | 408 | def test_decapitalize(self): 409 | self.assertEqual( 410 | decapitalize('Fabio'), 'fabio', 'First letter is lower case') 411 | self.assertEqual( 412 | decapitalize('Fabio'), 'fabio', 'First letter is lower case') 413 | self.assertEqual(decapitalize('FOO'), 'fOO', 'Other letters unchanged') 414 | self.assertEqual(decapitalize(123), '123', 'Non string') 415 | self.assertEqual( 416 | decapitalize(''), '', 'Decapitalizing empty string returns empty string') 417 | self.assertEqual( 418 | decapitalize(None), '', 'Decapitalizing null returns empty string') 419 | 420 | def test_dedent(self): 421 | self.assertEqual(dedent('Hello\nWorld'), 'Hello\nWorld') 422 | self.assertEqual(dedent('Hello\t\nWorld'), 'Hello\t\nWorld') 423 | self.assertEqual(dedent('Hello \nWorld'), 'Hello \nWorld') 424 | self.assertEqual(dedent('Hello\n World'), 'Hello\n World') 425 | self.assertEqual(dedent(' Hello\n World'), ' Hello\nWorld') 426 | self.assertEqual(dedent(' Hello\nWorld'), ' Hello\nWorld') 427 | self.assertEqual(dedent(' Hello World'), 'Hello World') 428 | self.assertEqual(dedent(' Hello\n World'), 'Hello\nWorld') 429 | self.assertEqual(dedent(' Hello\n World'), 'Hello\n World') 430 | self.assertEqual(dedent('\t\tHello\tWorld'), 'Hello\tWorld') 431 | self.assertEqual(dedent('\t\tHello\n\t\tWorld'), 'Hello\nWorld') 432 | self.assertEqual(dedent('Hello\n\t\tWorld'), 'Hello\n\t\tWorld') 433 | self.assertEqual( 434 | dedent('\t\tHello\n\t\t\t\tWorld'), 'Hello\n\t\tWorld') 435 | self.assertEqual( 436 | dedent('\t\tHello\r\n\t\t\t\tWorld'), 'Hello\r\n\t\tWorld') 437 | self.assertEqual( 438 | dedent('\t\tHello\n\n\n\n\t\t\t\tWorld'), 'Hello\n\n\n\n\t\tWorld') 439 | 440 | def test_escape_html(self): 441 | self.assertEqual(escape_html('
Blah & "blah" & \'blah\'
'), 442 | '<div>Blah & "blah" & 'blah'</div>') 443 | self.assertEqual(escape_html('<'), '&lt;') 444 | self.assertEqual(escape_html(' '), ' ') 445 | self.assertEqual(escape_html('¢'), '¢') 446 | self.assertEqual( 447 | escape_html('¢ £ ¥ € © ®'), '¢ £ ¥ € © ®') 448 | self.assertEqual(escape_html(5), '5') 449 | self.assertEqual(escape_html(''), '') 450 | self.assertEqual(escape_html(None), '') 451 | 452 | def test_ends_with(self): 453 | self.assertEqual(ends_with('image.gif', 'gif'), True) 454 | self.assertEqual(ends_with('foobar', 'bar'), True) 455 | self.assertEqual(ends_with('foobarfoobar', 'bar'), True) 456 | self.assertEqual(ends_with('foo', 'o'), True) 457 | self.assertEqual(ends_with('foobar', 'bar'), True) 458 | self.assertEqual(ends_with( 459 | '00018-0000062.Plone.sdh264.1a7264e6912a91aa4a81b64dc5517df7b8875994.mp4', 'mp4'), True) 460 | self.assertEqual(ends_with('fooba', 'bar'), False) 461 | self.assertEqual(ends_with(12345, 45), True) 462 | self.assertEqual(ends_with(12345, 6), False) 463 | self.assertEqual(ends_with('', ''), True) 464 | self.assertEqual(ends_with(None, ''), True) 465 | self.assertEqual(ends_with(None, 'foo'), False) 466 | self.assertEqual(ends_with('foobä', 'ä'), True) 467 | 468 | def test_humanize(self): 469 | self.assertEqual( 470 | humanize('the_humanize_string_method'), 'The humanize string method') 471 | self.assertEqual( 472 | humanize('ThehumanizeStringMethod'), 'Thehumanize string method') 473 | self.assertEqual( 474 | humanize('-ThehumanizeStringMethod'), 'Thehumanize string method') 475 | self.assertEqual( 476 | humanize('the humanize string method'), 'The humanize string method') 477 | self.assertEqual( 478 | humanize('the humanize_id string method_id'), 'The humanize id string method') 479 | self.assertEqual( 480 | humanize('the humanize string method '), 'The humanize string method') 481 | self.assertEqual(humanize( 482 | ' capitalize dash-CamelCase_underscore trim '), 'Capitalize dash camel case underscore trim') 483 | self.assertEqual(humanize(123), '123') 484 | self.assertEqual(humanize(''), '') 485 | self.assertEqual(humanize(None), '') 486 | 487 | def test_includes(self): 488 | self.assertEqual(includes('foobar', 'ob'), True) 489 | self.assertEqual(includes('foobar', 'qux'), False) 490 | self.assertEqual(includes('foobar', 'bar'), True) 491 | self.assertEqual(includes('foobar', 'buzz'), False) 492 | self.assertEqual(includes(12345, 34), True) 493 | self.assertEqual(includes(12345, 6), False) 494 | self.assertEqual(includes('', 34), False) 495 | self.assertEqual(includes(None, 34), False) 496 | self.assertEqual(includes(None, ''), True) 497 | 498 | def test_insert(self): 499 | self.assertEqual(insert('foo ', 4, 'bar'), 'foo bar') 500 | self.assertEqual(insert('Hello ', 6, 'Jessy'), 'Hello Jessy') 501 | self.assertEqual(insert('Hello ', 100, 'Jessy'), 'Hello Jessy') 502 | self.assertEqual(insert('', 100, 'Jessy'), 'Jessy') 503 | self.assertEqual(insert(None, 100, 'Jessy'), 'Jessy') 504 | self.assertEqual(insert(12345, 6, 'Jessy'), '12345Jessy') 505 | 506 | def test_lines(self): 507 | self.assertEqual(lines('foo\nbar'), ['foo', 'bar']) 508 | self.assertEqual(len(lines('Hello\nWorld')), 2) 509 | self.assertEqual(len(lines('Hello\rWorld')), 2) 510 | self.assertEqual(len(lines('Hello World')), 1) 511 | self.assertEqual(len(lines('\r\n\n\r')), 4) 512 | self.assertEqual(len(lines('Hello\r\r\nWorld')), 3) 513 | self.assertEqual(len(lines('Hello\r\rWorld')), 3) 514 | self.assertEqual(len(lines(123)), 1) 515 | 516 | def test_lpad(self): 517 | self.assertEqual(lpad('1', 8), ' 1') 518 | self.assertEqual(lpad(1, 8), ' 1') 519 | self.assertEqual(lpad('1', 8, '0'), '00000001') 520 | self.assertEqual(lpad('', 2), ' ') 521 | self.assertEqual(lpad(None, 2), ' ') 522 | 523 | def test_ltrim(self): 524 | self.assertEqual(ltrim(' foo'), 'foo') 525 | self.assertEqual(ltrim(' foo'), 'foo') 526 | self.assertEqual(ltrim('foo '), 'foo ') 527 | self.assertEqual(ltrim(' foo '), 'foo ') 528 | self.assertEqual( 529 | ltrim(''), '', 'ltrim empty string should return empty string') 530 | self.assertEqual( 531 | ltrim(None), '', 'ltrim null should return empty string') 532 | self.assertEqual(ltrim('ffoo', 'f'), 'oo') 533 | self.assertEqual(ltrim('ooff', 'f'), 'ooff') 534 | self.assertEqual(ltrim('ffooff', 'f'), 'ooff') 535 | self.assertEqual(ltrim('_-foobar-_', '_-'), 'foobar-_') 536 | self.assertEqual(ltrim(123, 1), '23') 537 | 538 | def test_repeat(self): 539 | self.assertEqual(repeat('foo', 3), 'foofoofoo') 540 | self.assertEqual(repeat('foo', '3'), 'foofoofoo') 541 | self.assertEqual(repeat(123, 2), '123123') 542 | self.assertEqual(repeat(1234, 2, '*'), '1234*1234') 543 | self.assertEqual(repeat(1234, 2, '**'), '1234**1234') 544 | self.assertEqual(repeat(1234, 2, 5), '123451234') 545 | 546 | def test_rpad(self): 547 | self.assertEqual(rpad('1', 8), '1 ') 548 | self.assertEqual(rpad(1, 8), '1 ') 549 | self.assertEqual(rpad('1', 8, '0'), '10000000') 550 | self.assertEqual(rpad('foo', 8, '0'), 'foo00000') 551 | self.assertEqual(rpad('foo', 7, '0'), 'foo0000') 552 | self.assertEqual(rpad('', 2), ' ') 553 | self.assertEqual(rpad(None, 2), ' ') 554 | 555 | def test_rtrim(self): 556 | self.assertEqual(rtrim('http://foo/', '/'), 'http://foo') 557 | self.assertEqual(rtrim(' foo'), ' foo') 558 | self.assertEqual(rtrim('foo '), 'foo') 559 | self.assertEqual(rtrim('foo '), 'foo') 560 | self.assertEqual(rtrim('foo bar '), 'foo bar') 561 | self.assertEqual(rtrim(' foo '), ' foo') 562 | self.assertEqual(rtrim('ffoo', 'f'), 'ffoo') 563 | self.assertEqual(rtrim('ooff', 'f'), 'oo') 564 | self.assertEqual(rtrim('ffooff', 'f'), 'ffoo') 565 | self.assertEqual(rtrim('_-foobar-_', '_-'), '_-foobar') 566 | self.assertEqual(rtrim(123, 3), '12') 567 | self.assertEqual(rtrim(''), '') 568 | self.assertEqual(rtrim(None), '') 569 | 570 | def test_slugify(self): 571 | if not HAS_SLUGIFY: 572 | module.fail_json(msg='slugify required for this module') 573 | self.assertEqual(_slugify('Jack & Jill like numbers 1,2,3 and 4 and silly characters ?%.$!/'), 574 | 'jack-jill-like-numbers-1-2-3-and-4-and-silly-characters') 575 | self.assertEqual(_slugify('I know latin characters: á í ó ú ç ã õ ñ ü ă ș ț'), 576 | 'i-know-latin-characters-a-i-o-u-c-a-o-n-u-a-s-t') 577 | self.assertEqual(_slugify('I am a word too, even though I am but a single letter: i!'), 578 | 'i-am-a-word-too-even-though-i-am-but-a-single-letter-i') 579 | self.assertEqual(_slugify(''), '') 580 | self.assertEqual(_slugify(None), '') 581 | self.assertEqual(_slugify("This is a test ---"), "this-is-a-test") 582 | self.assertEqual(_slugify("___This is a test ---"), "this-is-a-test") 583 | self.assertEqual(_slugify("___This is a test___"), "this-is-a-test") 584 | self.assertEqual( 585 | _slugify("This -- is a ## test ---"), "this-is-a-test") 586 | self.assertEqual(_slugify('影師嗎'), "ying-shi-ma") 587 | self.assertEqual(_slugify('C\'est déjà l\'été.'), "cest-deja-lete") 588 | self.assertEqual( 589 | _slugify('Nín hǎo. Wǒ shì zhōng guó rén'), "nin-hao-wo-shi-zhong-guo-ren") 590 | self.assertEqual( 591 | _slugify('jaja---lol-méméméoo--a'), "jaja-lol-mememeoo-a") 592 | self.assertEqual(_slugify('Компьютер'), "kompiuter") 593 | self.assertEqual( 594 | _slugify('jaja---lol-méméméoo--a', max_length=9), "jaja-lol") 595 | self.assertEqual( 596 | _slugify('jaja---lol-méméméoo--a', max_length=15), "jaja-lol-mememe") 597 | self.assertEqual( 598 | _slugify('jaja---lol-méméméoo--a', max_length=50), "jaja-lol-mememeoo-a") 599 | self.assertEqual(_slugify( 600 | 'jaja---lol-méméméoo--a', max_length=15, word_boundary=True), "jaja-lol-a") 601 | self.assertEqual(_slugify( 602 | 'jaja---lol-méméméoo--a', max_length=17, word_boundary=True), "jaja-lol-mememeoo") 603 | self.assertEqual(_slugify( 604 | 'jaja---lol-méméméoo--a', max_length=18, word_boundary=True), "jaja-lol-mememeoo") 605 | self.assertEqual(_slugify( 606 | 'jaja---lol-méméméoo--a', max_length=19, word_boundary=True), "jaja-lol-mememeoo-a") 607 | self.assertEqual(_slugify('jaja---lol-méméméoo--a', max_length=20, 608 | word_boundary=True, separator="."), "jaja.lol.mememeoo.a") 609 | self.assertEqual(_slugify('jaja---lol-méméméoo--a', max_length=20, 610 | word_boundary=True, separator="ZZZZZZ"), "jajaZZZZZZlolZZZZZZmememeooZZZZZZa") 611 | self.assertEqual(_slugify('one two three four five', max_length=13, 612 | word_boundary=True, save_order=True), "one-two-three") 613 | self.assertEqual(_slugify('one two three four five', max_length=13, 614 | word_boundary=True, save_order=False), "one-two-three") 615 | self.assertEqual(_slugify('one two three four five', max_length=12, 616 | word_boundary=True, save_order=False), "one-two-four") 617 | self.assertEqual(_slugify( 618 | 'one two three four five', max_length=12, word_boundary=True, save_order=True), "one-two") 619 | self.assertEqual( 620 | _slugify('this has a stopword', stopwords=['stopword']), 'this-has-a') 621 | self.assertEqual(_slugify('the quick brown fox jumps over the lazy dog', stopwords=[ 622 | 'the']), 'quick-brown-fox-jumps-over-lazy-dog') 623 | self.assertEqual( 624 | _slugify('Foo A FOO B foo C', stopwords=['foo']), 'a-b-c') 625 | self.assertEqual( 626 | _slugify('Foo A FOO B foo C', stopwords=['FOO']), 'a-b-c') 627 | self.assertEqual(_slugify('the quick brown fox jumps over the lazy dog in a hurry', stopwords=[ 628 | 'the', 'in', 'a', 'hurry']), 'quick-brown-fox-jumps-over-lazy-dog') 629 | self.assertEqual(_slugify('foo & bar'), 'foo-bar') 630 | 631 | def test_splice(self): 632 | self.assertEqual(splice('http://github.com/lxhunter/string', 18, 8, 'awesome'), 633 | 'http://github.com/awesome/string') 634 | self.assertEqual(splice(12345, 1, 2, 321), '132145') 635 | 636 | def test_starts_with(self): 637 | self.assertEqual(starts_with('image.gif', 'image'), True) 638 | self.assertEqual(starts_with('foobar', 'foo'), True) 639 | self.assertEqual(starts_with('oobar', 'foo'), False) 640 | self.assertEqual(starts_with('oobar', 'o'), True) 641 | self.assertEqual(starts_with(12345, 123), True) 642 | self.assertEqual(starts_with(2345, 123), False) 643 | self.assertEqual(starts_with('', ''), True) 644 | self.assertEqual(starts_with(None, ''), True) 645 | self.assertEqual(starts_with(None, 'foo'), False) 646 | self.assertEqual(starts_with('-foobar', 'foo', 1), True) 647 | self.assertEqual(starts_with('foobar', 'foo', 0), True) 648 | self.assertEqual(starts_with('foobar', 'foo', 1), False) 649 | self.assertEqual(starts_with('Äpfel', 'Ä'), True) 650 | 651 | def test_successor(self): 652 | self.assertEqual(successor('a'), 'b') 653 | self.assertEqual(successor('b'), 'c') 654 | self.assertEqual(successor('z'), 'aa') 655 | 656 | def test_swap_case(self): 657 | self.assertEqual(swap_case('fOO'), 'Foo') 658 | 659 | def test_transliterate(self): 660 | self.assertEqual(transliterate(u'älämölö'), u'alamolo') 661 | self.assertEqual(transliterate(u'Ærøskøbing'), u'rskbing') 662 | 663 | def test_underscore(self): 664 | self.assertEqual(underscore('FooBar'), 'foo_bar') 665 | 666 | def test_unescape_html(self): 667 | self.assertEqual(unescape_html( 668 | '<div>Blah & "blah" & 'blah'</div>'), '
Blah & "blah" & \'blah\'
') 669 | self.assertEqual(unescape_html('&lt;'), '<') 670 | self.assertEqual(unescape_html('''), '\'') 671 | self.assertEqual(unescape_html('''), '\'') 672 | self.assertEqual(unescape_html('''), '\'') 673 | self.assertEqual(unescape_html('J'), 'J') 674 | self.assertEqual(unescape_html('&_#39;'), '&_#39;') 675 | self.assertEqual(unescape_html(''_;'), ''_;') 676 | self.assertEqual(unescape_html('&#38;'), '&') 677 | self.assertEqual(unescape_html('''), "'") 678 | self.assertEqual(unescape_html(''), '') 679 | self.assertEqual(unescape_html(' '), ' ') 680 | self.assertEqual(unescape_html( 681 | 'what is the ¥ to £ to € conversion process?'), 'what is the ¥ to £ to € conversion process?') 682 | self.assertEqual(unescape_html('® trademark'), '® trademark') 683 | self.assertEqual(unescape_html( 684 | '© 1992. License available for 50 ¢'), '© 1992. License available for 50 ¢') 685 | self.assertEqual(unescape_html(' '), ' ') 686 | self.assertEqual(unescape_html(' '), ' ') 687 | self.assertEqual(unescape_html(None), '') 688 | 689 | if __name__ == '__main__': 690 | unittest.main() 691 | -------------------------------------------------------------------------------- /plugins/lookup/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrjk/ansible-skel/5fe8f548dabebf4e0422de03b1ee93a5f3647d40/plugins/lookup/.gitkeep -------------------------------------------------------------------------------- /plugins/modules/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrjk/ansible-skel/5fe8f548dabebf4e0422de03b1ee93a5f3647d40/plugins/modules/.gitkeep -------------------------------------------------------------------------------- /plugins/vars/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrjk/ansible-skel/5fe8f548dabebf4e0422de03b1ee93a5f3647d40/plugins/vars/.gitkeep -------------------------------------------------------------------------------- /roles/local/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrjk/ansible-skel/5fe8f548dabebf4e0422de03b1ee93a5f3647d40/roles/local/.gitkeep -------------------------------------------------------------------------------- /roles/profiles/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrjk/ansible-skel/5fe8f548dabebf4e0422de03b1ee93a5f3647d40/roles/profiles/.gitkeep -------------------------------------------------------------------------------- /roles/requirements.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | # TODO: Do a better documentation 4 | # Doc: http://docs.ansible.com/ansible/galaxy.html#id8 5 | 6 | - src: mrjk.dumpall 7 | version: dev 8 | name: dumpall 9 | 10 | --------------------------------------------------------------------------------