├── LICENSE ├── README.md ├── docker ├── Dockerfile └── README.md ├── examples ├── full_config_example.json ├── fw_example.json ├── fw_inventory_example.json ├── group_vars │ └── test.json ├── host_vars │ └── test_fw1.json └── test_inventory ├── fortios ├── fortios_api.py ├── fortios_api_firewall_address.py ├── fortios_api_firewall_addrgrp.py ├── fortios_api_firewall_dos_policy.py ├── fortios_api_firewall_ippool.py ├── fortios_api_firewall_policy.py ├── fortios_api_firewall_service.py ├── fortios_api_firewall_service_group.py ├── fortios_api_firewall_vip.py ├── fortios_api_interface.py ├── fortios_api_link_monitor.py ├── fortios_api_ntp_server.py ├── fortios_api_prefix_list.py ├── fortios_api_route_map.py ├── fortios_api_router_bgp.py ├── fortios_api_router_ospf.py ├── fortios_api_router_ospf_interface.py ├── fortios_api_snmp_community.py ├── fortios_api_snmp_sysinfo.py ├── fortios_api_syslogd_setting.py ├── fortios_api_system_admin.py ├── fortios_api_system_dns.py ├── fortios_api_system_global.py ├── fortios_api_system_ha.py ├── fortios_api_system_ntp.py └── fortios_api_system_vdom.py └── module_utils └── fortios_api.py /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ansible_fortios_api 2 | Fortios API module for Ansible 3 | 4 | ## Version history 5 | 6 | - 1.0 - initial release 7 | - 1.1 - addition of full_config feature 8 | 9 | ## Installation 10 | Copy content of fortios folder to ansible/lib/ansible/modules/network/fortios 11 | 12 | Copy content of module_utils folder to ansible/lib/ansibe/module_utils 13 | 14 | Run Ansible playbook as you would normally do. 15 | 16 | 17 | ## Usage 18 | It's no different than any other Ansible module. If you have a Fortigate VM with code 5.4 at 192.0.2.5 accepting HTTP connections 19 | with username admin and password test, then you can simply run example playbooks like this: 20 | 21 | ansible-playbook fw_inventory_example.json -i test_inventory --extra-vars "pw=test" 22 | 23 | ansible-playbook fw_example.json -i test_inventory 24 | 25 | fw_example playbook goes through all of the modules and demonstrates how they can be used 26 | 27 | fw_inventory_example playbook goes through some configuration and shows one of the ways this module can be used with inventory files 28 | 29 | 30 | ## How this module works 31 | This module serves as the interface between Ansible and Fortios API. It can take any parameter that API accepts and send it over. 32 | 33 | It's very important to note that this module by default takes the end-state config on the object level. I.e. if you have policies 1, 34 | 2 and 3 configured on the Firewall and you run a playbook that has policies 4 and 5, the end configuration on the firewall will have 35 | policies 4 and 5 configured, while policied 1-3 will be deleted. 36 | 37 | If such behavior is not desired, make sure that full_config parameter is set to false. In this mode, you can delete specific objects 38 | by supplying their ID (usually ID or Name) in a delete_objects list. Please note that in this mode firewall_policy module will not 39 | attempt to change order of policies, as it is not possible to restructure them without having a full list of policies provided. 40 | 41 | Within the object, only the values that are specified will be changed. I.e. if you have configured policy 1 and run a playbook 42 | that has policy 1 with only a value of "comment=test comment", then only the comment field of the policy will be changed. 43 | 44 | To simplify onboarding of existing devices, you can run playbook with print_current_config:true option (see fw_example.json), 45 | which will run module in check mode and write a local file with current config of the specified firewall API endpoint. 46 | 47 | 48 | ## fortios_api arbitrary module 49 | While the rest of the modules have hard-coded API path, this module is written to accept any arbitrary API endpoint and any arbitrary 50 | set of variables. It will query the API to build an argument spec (which values can be assigned and what is the format for them) for 51 | the given API endpoint. In some cases it fails, so you may need to edit "convert_type_str" function in module_utils/fortios_api.py 52 | to solve the issue. 53 | 54 | You can see examples of how this module can be used in the module itself (for setting static routes) or in the fw_example.json 55 | (for managing VRRP interfaces) 56 | 57 | 58 | ## Parameters 59 | Hopefully most of the parameters are self-explanatory and don't need any additional clarifcation, but there are some I want to clarify. 60 | ``` 61 | endpoint_information - dictionary with information about API endpoint. You will see it only with fortios_api module 62 | endpoint - the API endpoint path 63 | list_identifier - the name of the list from which module will take objects 64 | object_identifier - if the list has multiple objects, module needs to know how this objects are identified in API (usually by name or id) 65 | print_current_config - false by default, if set to true will run module in check mode (no changes) and write a file with currect config 66 | conn_params - connection parameters, how to reach firewall and how to communicate with it 67 | fortigate_username - username 68 | fortigate_password - password 69 | fortigate_ip - ip or FQDN of the firewall 70 | secure - use HTTPS if true, use HTTP if false 71 | port - which port to use (default to 80 or 443 depending on secure) 72 | verify - verify validity of the cert if true 73 | proxies - if proxy is needed, specify it in the requests format (i.e. http: socks5://127.0.0.1:9000), see module code for example 74 | list_of_objects - this is the list referenced in list_identifier. Its name and content changes based on the module. Note that this value 75 | must be list all of the times, even if it is a list of 1 element. 76 | permanent_objects - list of objects by ID that can not be deleted. Instead, when they are not present in the end state config, module will try to 77 | reset them to defaults. Currently used only in the interface module. 78 | ignore_objects - list of objects by ID that will be ignored by the module. Useful if you don't want your module to mess with management interface, 79 | also can be used to not mess with built-in firewall addresses or services (see example playbooks). 80 | full_config - boolean, added in 1.1. If true (defaul value), module assumes that provided objects in the config are the only objects that 81 | should be present on the device and deletes the rest of them. If false, module only creates new objects, modifies existing 82 | ones and deletes only the objects in the delete_objects list provided by user. False value brings behavior of this module 83 | closer in line with most of the other networking modules. 84 | delete_objects - list of objects by ID that will be deleted, only used if full_confg is false. 85 | ``` 86 | 87 | ## Known gotchas 88 | This module will write some files in the folder you are running it from (specifically it will write argument spec and current config if 89 | you request it). I have not tested how it will work if it is run on a remote host. If the API changes at some point, you may need to 90 | delete the local files so that argument spec is renegarated and can accept new values. 91 | 92 | The module tries to make sure that config changes made it through to the firewall, but is not smart enough to understand that some 93 | values are identical. I.e. if you send firewall 10.0.0.0/8, it will save it as 10.0.0.0 255.0.0.0.0 and will return that value back. 94 | Module would think that there's an issue and revert config back. To work around the issue, provide values in the same format as they 95 | are stored in the firewall. 96 | 97 | Module requires requests library to function. If you want to use socks proxy, make sure you install socks support for requests as well. 98 | 99 | ## Why is it in private repo and not submitted to Ansible? 100 | I tried, they didn't take it. Ansible wants all of the modules to have defined argument spec, while this module builds it dynamically 101 | based on the API endpoint. I personally believe that the ability to use effectively the same code to communicate with different API endpoints 102 | is the point of using APIs, but I can see why Ansible wants modules to be better defined as well. 103 | Regardless, I currently don't have much desire or time to effectively reduce the module functionality in order for Ansible to accept it. -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.7 2 | 3 | ENV ANSIBLE_VERSION 2.5.5 4 | 5 | ENV BUILD_PACKAGES \ 6 | bash \ 7 | curl \ 8 | tar \ 9 | openssh-client \ 10 | sshpass \ 11 | git \ 12 | python \ 13 | py-boto \ 14 | py-dateutil \ 15 | py-httplib2 \ 16 | py-jinja2 \ 17 | py-paramiko \ 18 | py-pip \ 19 | py-yaml \ 20 | ca-certificates \ 21 | rsync 22 | 23 | RUN set -x && \ 24 | \ 25 | echo "==> Adding build-dependencies..." && \ 26 | apk --update add --virtual build-dependencies \ 27 | gcc \ 28 | musl-dev \ 29 | libffi-dev \ 30 | openssl-dev \ 31 | python-dev && \ 32 | \ 33 | echo "==> Upgrading apk and system..." && \ 34 | apk update && apk upgrade && \ 35 | \ 36 | echo "==> Adding Python runtime..." && \ 37 | apk add --no-cache ${BUILD_PACKAGES} && \ 38 | pip install --upgrade pip && \ 39 | pip install python-keyczar docker-py && \ 40 | pip install f5-sdk && \ 41 | pip install netaddr && \ 42 | \ 43 | echo "==> Installing Ansible..." && \ 44 | pip install ansible==${ANSIBLE_VERSION} && \ 45 | \ 46 | echo "==> Cleaning up..." && \ 47 | apk del build-dependencies && \ 48 | rm -rf /var/cache/apk/* && \ 49 | \ 50 | echo "==> Adding hosts for convenience..." && \ 51 | mkdir -p /etc/ansible /ansible && \ 52 | echo "[local]" >> /etc/ansible/hosts && \ 53 | echo "localhost" >> /etc/ansible/hosts 54 | 55 | RUN mkdir /source 56 | RUN cd /source && git clone https://github.com/eoprede/ansible_fortios_api.git 57 | RUN rsync -a /source/ansible_fortios_api/module_utils/ /usr/lib/python2.7/site-packages/ansible/module_utils/ && \ 58 | rsync -a /source/ansible_fortios_api/fortios/ /usr/lib/python2.7/site-packages/ansible/modules/network/fortios/ 59 | 60 | ENV ANSIBLE_GATHERING smart 61 | ENV ANSIBLE_HOST_KEY_CHECKING false 62 | ENV ANSIBLE_RETRY_FILES_ENABLED false 63 | ENV ANSIBLE_ROLES_PATH /ansible/playbooks/roles 64 | ENV ANSIBLE_SSH_PIPELINING True 65 | ENV PYTHONPATH /ansible/lib 66 | ENV PATH /ansible/bin:$PATH 67 | ENV ANSIBLE_LIBRARY /ansible/library 68 | 69 | WORKDIR /ansible/playbooks 70 | 71 | ENTRYPOINT ["ansible-playbook"] 72 | -------------------------------------------------------------------------------- /docker/README.md: -------------------------------------------------------------------------------- 1 | # Running Ansible in Docker 2 | 3 | Documentation on how to run Ansible in Docker. 4 | 5 | ## Why? 6 | 7 | It's mainly a convenience thing - instead of installing Ansible and then doing additional manipulations to install fortios_api module, I can simply run a container. 8 | 9 | Another use case - running multiple different Ansible versions on the same host - I need to do it now, where systems guys are running 2.4 and I need additional F5 modules that are available in 2.6 10 | 11 | Not to mention that there are still people who use Windows machines and containers provide nice and easy way to run Ansible from it (you just need to use absolute paths to forward the directory). 12 | 13 | ## How? 14 | 15 | Easiest option - just pull image from docker hub and run it. 16 | 17 | docker pull eoprede/ansible_fortios_api 18 | docker run --rm -it -v $(pwd):/ansible/playbooks eoprede/ansible_fortios_api test.yaml 19 | 20 | First command downloads the image. Second command shares your current directory with the container and runs an ansible-playbook test.yaml command. Then the container is cleaned up after it finishes the execution. So basically you can think of it as just an ansible executable, except instead of `ansible-playbook` command you will have to type `docker run --rm -it -v $(pwd):/ansible/playbooks eoprede/ansible_fortios_api` 21 | 22 | If you want to customize the image (i.e. you want some additional modules, or you want to run 2.6.0rc) you can just edit the Dockerfile and build image yourself. To build the image, enter the directory with Dockerfile and run 23 | 24 | docker build -t ansible_fortios_api . 25 | 26 | After that you can run your local container with 27 | 28 | docker run --rm -it -v $(pwd):/ansible/playbooks ansible_fortios_api 29 | 30 | ## Credits and additional documentation 31 | 32 | I used the following work for this container: https://github.com/walokra/docker-ansible-playbook 33 | You can find additional documentation, including how to run it with vault, at the link above. -------------------------------------------------------------------------------- /examples/full_config_example.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "Create rule with id 200 and remove rule with id 100", 4 | "fortios_api_firewall_policy": { 5 | "conn_params": "{{ test_fw }}", 6 | "vdom": "test_vdom", 7 | "full_config": false, 8 | "delete_objects": [ 9 | 100 10 | ], 11 | "policies": [ 12 | { 13 | "policyid": 200, 14 | "service": [ 15 | { 16 | "name": "HTTP" 17 | } 18 | ], 19 | "srcintf": [ 20 | { 21 | "name": "SUPPORT" 22 | } 23 | ], 24 | "srcaddr": [ 25 | { 26 | "name": "AD" 27 | } 28 | ], 29 | "dstintf": [ 30 | { 31 | "name": "APP" 32 | } 33 | ], 34 | "dstaddr": [ 35 | { 36 | "name": "all" 37 | } 38 | ], 39 | "action": "accept", 40 | "schedule": "always" 41 | } 42 | ] 43 | } 44 | }, 45 | { 46 | "name": "Resetting permanent object to default", 47 | "fortios_api_interface": { 48 | "conn_params": "{{ test_fw }}", 49 | "full_config": false, 50 | "delete_objects": [ 51 | "wan2" 52 | ], 53 | "permanent_objects": [ 54 | "wan2" 55 | ], 56 | "interfaces": null 57 | } 58 | } 59 | ] -------------------------------------------------------------------------------- /examples/fw_example.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "hosts": "test", 4 | "connection": "local", 5 | "gather_facts": false, 6 | "vars": { 7 | "test_fw": { 8 | "fortigate_username": "admin", 9 | "fortigate_password": "test", 10 | "fortigate_ip": "{{ ip }}", 11 | "secure": "{{ secure }}", 12 | "port": "{{ port }}", 13 | "verify": false 14 | } 15 | }, 16 | "tasks": [ 17 | { 18 | "name": "set system global setup", 19 | "tags": [ 20 | "hostname" 21 | ], 22 | "fortios_api_system_global": { 23 | "print_current_config": false, 24 | "conn_params": "{{ test_fw }}", 25 | "global": [ 26 | { 27 | "admintimeout": 99, 28 | "hostname": "FW-test", 29 | "timezone": "80", 30 | "vdom-admin": "disable" 31 | } 32 | ] 33 | } 34 | }, 35 | { 36 | "name": "Update All Interfaces", 37 | "tags": [ 38 | "interfaces" 39 | ], 40 | "fortios_api_interface": { 41 | "conn_params": "{{ test_fw }}", 42 | "permanent_objects": [ 43 | "ssl.root", 44 | "port1", 45 | "port2", 46 | "port3", 47 | "port4", 48 | "port5", 49 | "port6", 50 | "port7", 51 | "port8", 52 | "port9", 53 | "port10" 54 | ], 55 | "interfaces": [ 56 | { 57 | "name": "port1", 58 | "allowaccess": "ping ssh http", 59 | "ip": "192.0.2.5 255.255.255.0", 60 | "type": "physical", 61 | "description": "Management" 62 | }, 63 | { 64 | "name": "port2", 65 | "vdom": "root", 66 | "ipv6": { 67 | "autoconf": "disable", 68 | "dhcp6-client-options": "iapd iana dns", 69 | "dhcp6-prefix-delegation": "enable", 70 | "dhcp6-prefix-hint": "::/61", 71 | "ip6-allowaccess": "ping", 72 | "ip6-mode": "dhcp" 73 | } 74 | }, 75 | { 76 | "name": "port3", 77 | "vdom": "root", 78 | "allowaccess": "ping https http", 79 | "type": "physical", 80 | "ip": "192.0.5.4 255.255.255.0" 81 | }, 82 | { 83 | "name": "port5", 84 | "vdom": "root", 85 | "vlanforward": "enable", 86 | "type": "physical" 87 | }, 88 | { 89 | "name": "testint", 90 | "vdom": "root", 91 | "allowaccess": "ping", 92 | "ip": "192.0.3.56 255.255.255.0", 93 | "role": "lan", 94 | "interface": "port5", 95 | "vlanid": 5, 96 | "vrrp-virtual-mac": "enable" 97 | } 98 | ] 99 | } 100 | }, 101 | { 102 | "name": "Update vrrp for testint", 103 | "tags": [ 104 | "interfaces" 105 | ], 106 | "fortios_api": { 107 | "endpoint_information": { 108 | "endpoint": "cmdb/system/interface/testint/vrrp", 109 | "list_identifier": "vrrp", 110 | "object_identifier": "vrid" 111 | }, 112 | "conn_params": "{{ test_fw }}", 113 | "vrrp": [ 114 | { 115 | "vrid": 1, 116 | "vrip": "192.0.3.1", 117 | "priority": 200 118 | } 119 | ] 120 | } 121 | }, 122 | { 123 | "name": "Update system admin", 124 | "tags": [ 125 | "system_admin" 126 | ], 127 | "fortios_api_system_admin": { 128 | "conn_params": "{{ test_fw }}", 129 | "admins": [ 130 | { 131 | "name": "test_admin", 132 | "comments": "test_update", 133 | "password": "test1", 134 | "accprofile": "prof_admin", 135 | "trusthost1": "192.168.0.0 255.254.0.0" 136 | }, 137 | { 138 | "name": "admin", 139 | "comments": "manually configured admin" 140 | } 141 | ] 142 | } 143 | }, 144 | { 145 | "name": "set system ha setup", 146 | "tags": [ 147 | "ha" 148 | ], 149 | "fortios_api_system_ha": { 150 | "conn_params": "{{ test_fw }}", 151 | "ha": [ 152 | { 153 | "group-name": "testha", 154 | "hbdev": "\"port10\" 2 ", 155 | "mode": "standalone", 156 | "priority": 200 157 | } 158 | ] 159 | } 160 | }, 161 | { 162 | "name": "set system dns setup", 163 | "tags": [ 164 | "dns" 165 | ], 166 | "fortios_api_system_dns": { 167 | "conn_params": "{{ test_fw }}", 168 | "dns": [ 169 | { 170 | "primary": "8.8.8.8", 171 | "secondary": "8.8.4.4", 172 | "source-ip": "192.0.2.5" 173 | } 174 | ] 175 | } 176 | }, 177 | { 178 | "name": "set system snmp sysinfo", 179 | "tags": [ 180 | "snmp" 181 | ], 182 | "fortios_api_snmp_sysinfo": { 183 | "conn_params": "{{ test_fw }}", 184 | "sysinfo": [ 185 | { 186 | "status": "enable" 187 | } 188 | ] 189 | } 190 | }, 191 | { 192 | "name": "set system snmp sysinfo", 193 | "tags": [ 194 | "snmp" 195 | ], 196 | "fortios_api_snmp_community": { 197 | "conn_params": "{{ test_fw }}", 198 | "community": [ 199 | { 200 | "id": 1, 201 | "events": "cpu-high mem-low log-full intf-ip vpn-tun-up vpn-tun-down ha-switch ha-hb-failure ips-signature ips-anomaly av-virus av-oversize av-pattern av-fragmented fm-if-change bgp-established bgp-backward-transition ha-member-up ha-member-down ent-conf-change av-conserve av-bypass av-oversize-passed av-oversize-blocked ips-pkg-update ips-fail-open faz-disconnect fswctl-session-up fswctl-session-down load-balance-real-server-down", 202 | "hosts": [ 203 | { 204 | "id": 1, 205 | "ip": "10.0.0.2 255.255.255.255" 206 | } 207 | ], 208 | "name": "public", 209 | "status": "enable", 210 | "trap-v1-status": "enable", 211 | "trap-v2c-status": "enable" 212 | } 213 | ] 214 | } 215 | }, 216 | { 217 | "name": "set system syslog setting", 218 | "tags": [ 219 | "syslog" 220 | ], 221 | "fortios_api_syslogd_setting": { 222 | "conn_params": "{{ test_fw }}", 223 | "setting": [ 224 | { 225 | "server": "10.0.0.3", 226 | "status": "enable" 227 | } 228 | ] 229 | } 230 | }, 231 | { 232 | "name": "set system ntp settings", 233 | "tags": [ 234 | "ntp" 235 | ], 236 | "fortios_api_ntp_server": { 237 | "conn_params": "{{ test_fw }}", 238 | "ntpserver": [ 239 | { 240 | "authentication": "disable", 241 | "id": 1, 242 | "server": "time.nist.gov" 243 | } 244 | ] 245 | } 246 | }, 247 | { 248 | "name": "set system ntp settings", 249 | "tags": [ 250 | "ntp" 251 | ], 252 | "fortios_api_system_ntp": { 253 | "conn_params": "{{ test_fw }}", 254 | "ntp": [ 255 | { 256 | "type": "custom" 257 | } 258 | ] 259 | } 260 | }, 261 | { 262 | "name": "set firewall addresses", 263 | "tags": [ 264 | "fw_address", 265 | "fw" 266 | ], 267 | "fortios_api_firewall_address": { 268 | "conn_params": "{{ test_fw }}", 269 | "address": [ 270 | { 271 | "name": "test", 272 | "type": "fqdn", 273 | "fqdn": "test.com" 274 | }, 275 | { 276 | "name": "test2", 277 | "type": "ipmask", 278 | "subnet": "1.1.1.1 255.255.255.255" 279 | } 280 | ] 281 | } 282 | }, 283 | { 284 | "name": "set firewall address group", 285 | "tags": [ 286 | "fw_address", 287 | "fw" 288 | ], 289 | "fortios_api_firewall_addrgrp": { 290 | "conn_params": "{{ test_fw }}", 291 | "addrgrp": [ 292 | { 293 | "name": "test_grp", 294 | "member": [ 295 | { 296 | "name": "test" 297 | }, 298 | { 299 | "name": "test2" 300 | } 301 | ] 302 | } 303 | ] 304 | } 305 | }, 306 | { 307 | "name": "update firewall services", 308 | "tags": [ 309 | "firewall_services", 310 | "fw" 311 | ], 312 | "fortios_api_firewall_service": { 313 | "conn_params": "{{ test_fw }}", 314 | "services": [ 315 | { 316 | "name": "test_rule", 317 | "comment": "single_tcp_2004", 318 | "tcp-portrange": "2004" 319 | }, 320 | { 321 | "name": "test_svc_with_range_and_tcpudp", 322 | "tcp-portrange": "80 443 200-201", 323 | "udp-portrange": "53", 324 | "comment": "This is a comment" 325 | } 326 | ] 327 | } 328 | }, 329 | { 330 | "name": "set firewall IP pool", 331 | "tags": [ 332 | "fw_ippool", 333 | "fw" 334 | ], 335 | "fortios_api_firewall_ippool": { 336 | "conn_params": "{{ test_fw }}", 337 | "ippool": [ 338 | { 339 | "name": "test_pool", 340 | "type": "one-to-one", 341 | "startip": "1.2.3.4", 342 | "endip": "1.2.3.4" 343 | }, 344 | { 345 | "name": "test_pool_overload", 346 | "type": "overload", 347 | "startip": "2.2.3.4", 348 | "endip": "2.2.3.5" 349 | } 350 | ] 351 | } 352 | }, 353 | { 354 | "name": "set firewall IP pool", 355 | "tags": [ 356 | "fw_vip", 357 | "fw" 358 | ], 359 | "fortios_api_firewall_vip": { 360 | "conn_params": "{{ test_fw }}", 361 | "print_current_config": false, 362 | "vip": [ 363 | { 364 | "name": "test_vip", 365 | "extintf": "port3", 366 | "extip": "192.0.5.10", 367 | "mappedip": [ 368 | { 369 | "range": "1.2.3.4" 370 | } 371 | ] 372 | }, 373 | { 374 | "name": "test_vip_range", 375 | "extintf": "port3", 376 | "extip": "192.0.5.11-192.0.5.12", 377 | "mappedip": [ 378 | { 379 | "range": "1.2.3.5-1.2.3.6" 380 | } 381 | ] 382 | } 383 | ] 384 | } 385 | }, 386 | { 387 | "name": "update firewall policies", 388 | "tags": [ 389 | "fw", 390 | "fw_policy" 391 | ], 392 | "fortios_api_firewall_policy": { 393 | "conn_params": "{{ test_fw }}", 394 | "policies": [ 395 | { 396 | "policyid": 2, 397 | "srcintf": [ 398 | { 399 | "name": "port3" 400 | } 401 | ], 402 | "dstintf": [ 403 | { 404 | "name": "port5" 405 | } 406 | ], 407 | "srcaddr": [ 408 | { 409 | "name": "all" 410 | } 411 | ], 412 | "dstaddr": [ 413 | { 414 | "name": "all" 415 | } 416 | ], 417 | "schedule": "always", 418 | "service": [ 419 | { 420 | "name": "HTTPS" 421 | } 422 | ], 423 | "comments": "test2", 424 | "name": "test_rule2", 425 | "action": "deny" 426 | }, 427 | { 428 | "policyid": 7, 429 | "srcintf": [ 430 | { 431 | "name": "port3" 432 | } 433 | ], 434 | "dstintf": [ 435 | { 436 | "name": "port5" 437 | } 438 | ], 439 | "srcaddr": [ 440 | { 441 | "name": "all" 442 | } 443 | ], 444 | "dstaddr": [ 445 | { 446 | "name": "all" 447 | } 448 | ], 449 | "action": "accept", 450 | "schedule": "always", 451 | "service": [ 452 | { 453 | "name": "test_rule" 454 | } 455 | ], 456 | "comments": "allow_test_rule", 457 | "name": "test_rule3" 458 | }, 459 | { 460 | "policyid": 4, 461 | "srcintf": [ 462 | { 463 | "name": "port5" 464 | } 465 | ], 466 | "dstintf": [ 467 | { 468 | "name": "port3" 469 | } 470 | ], 471 | "srcaddr": [ 472 | { 473 | "name": "all" 474 | } 475 | ], 476 | "dstaddr": [ 477 | { 478 | "name": "all" 479 | } 480 | ], 481 | "action": "accept", 482 | "schedule": "always", 483 | "service": [ 484 | { 485 | "name": "test_svc_with_range_and_tcpudp" 486 | } 487 | ], 488 | "name": "Test outbound with NAT", 489 | "nat": "enable" 490 | } 491 | ] 492 | } 493 | }, 494 | { 495 | "name": "update router prefix-list", 496 | "tags": [ 497 | "prefix_list" 498 | ], 499 | "fortios_api_prefix_list": { 500 | "conn_params": "{{ test_fw }}", 501 | "prefixes": [ 502 | { 503 | "name": "default_only", 504 | "rule": [ 505 | { 506 | "prefix": "0.0.0.0 0.0.0.0" 507 | } 508 | ] 509 | }, 510 | { 511 | "name": "test_block", 512 | "rule": [ 513 | { 514 | "prefix": "10.254.160.0 255.255.240.0" 515 | }, 516 | { 517 | "prefix": "2.0.0.0 255.0.0.0" 518 | } 519 | ] 520 | } 521 | ] 522 | } 523 | }, 524 | { 525 | "name": "update router route-map", 526 | "tags": [ 527 | "route_map" 528 | ], 529 | "fortios_api_route_map": { 530 | "print_current_config": false, 531 | "conn_params": "{{ test_fw }}", 532 | "route-map": [ 533 | { 534 | "comments": "comment", 535 | "name": "test_default", 536 | "rule": [ 537 | { 538 | "match-flags": 2, 539 | "match-ip-address": "default_only", 540 | "set-flags": 0 541 | }, 542 | { 543 | "match-flags": 2, 544 | "match-ip-address": "test_block", 545 | "set-flags": 2, 546 | "set-metric": 200 547 | } 548 | ] 549 | } 550 | ] 551 | } 552 | }, 553 | { 554 | "name": "Test OSPF", 555 | "tags": [ 556 | "ospf" 557 | ], 558 | "fortios_api_router_ospf": { 559 | "print_current_config": false, 560 | "conn_params": "{{ test_fw }}", 561 | "ospf": [ 562 | { 563 | "auto-cost-ref-bandwidth": 100000, 564 | "default-information-originate": "enable", 565 | "default-information-metric": 150, 566 | "router-id": "1.2.3.4", 567 | "area": [ 568 | { 569 | "id": "0.0.0.0" 570 | } 571 | ], 572 | "network": [ 573 | { 574 | "prefix": "192.0.5.0 255.255.255.0", 575 | "area": "0.0.0.0" 576 | } 577 | ] 578 | } 579 | ] 580 | } 581 | }, 582 | { 583 | "name": "Test OSPF Interface", 584 | "tags": [ 585 | "ospf" 586 | ], 587 | "fortios_api_router_ospf_interface": { 588 | "print_current_config": false, 589 | "conn_params": "{{ test_fw }}", 590 | "interface": [ 591 | { 592 | "name": "test", 593 | "interface": "port3", 594 | "authentication": "md5", 595 | "md5-key": "1 asd" 596 | } 597 | ] 598 | } 599 | }, 600 | { 601 | "name": "Update link-monitor", 602 | "tags": "link-monitor", 603 | "fortios_api_link_monitor": { 604 | "conn_params": "{{ test_fw }}", 605 | "monitor": [ 606 | { 607 | "name": "google_dns", 608 | "protocol": "ping", 609 | "server": [ 610 | { 611 | "address": "8.8.4.4" 612 | } 613 | ], 614 | "srcintf": "port5" 615 | } 616 | ] 617 | } 618 | }, 619 | { 620 | "name": "Check vdom", 621 | "tags": "vdom", 622 | "fortios_api_system_vdom": { 623 | "conn_params": "{{ test_fw }}", 624 | "vdoms": [ 625 | { 626 | "name": "root" 627 | } 628 | ] 629 | } 630 | }, 631 | { 632 | "name": "Test BGP", 633 | "tags": [ 634 | "bgp" 635 | ], 636 | "fortios_api_router_bgp": { 637 | "print_current_config": false, 638 | "conn_params": "{{ test_fw }}", 639 | "bgp": [ 640 | { 641 | "as": 65001, 642 | "router-id": "192.0.5.1", 643 | "log-neighbour-changes": "enable", 644 | "graceful-restart": "enable", 645 | "neighbor": [ 646 | { 647 | "ip": "192.0.5.2", 648 | "soft-reconfiguration": "enable", 649 | "remote-as": 65002, 650 | "prefix-list-in": "default_only" 651 | } 652 | ], 653 | "aggregate-address": [ 654 | { 655 | "prefix": "10.254.166.0 255.255.254.0" 656 | }, 657 | { 658 | "prefix": "10.254.164.0 255.255.252.0" 659 | } 660 | ], 661 | "network": [ 662 | { 663 | "prefix": "10.254.166.0 255.255.255.0" 664 | } 665 | ], 666 | "redistribute": [ 667 | { 668 | "name": "connected", 669 | "status": "enable", 670 | "route-map": "test_default" 671 | }, 672 | { 673 | "name": "rip", 674 | "status": "disable" 675 | }, 676 | { 677 | "name": "ospf", 678 | "status": "disable" 679 | }, 680 | { 681 | "name": "static", 682 | "status": "disable" 683 | }, 684 | { 685 | "name": "isis", 686 | "status": "disable" 687 | } 688 | ] 689 | } 690 | ] 691 | } 692 | }, 693 | { 694 | "name": "Test DHCP server", 695 | "tags": [ 696 | "dhcp" 697 | ], 698 | "fortios_api": { 699 | "endpoint_information": { 700 | "endpoint": "cmdb/system.dhcp/server", 701 | "list_identifier": "servers", 702 | "object_identifier": "id" 703 | }, 704 | "conn_params": "{{ test_fw }}", 705 | "servers": [] 706 | } 707 | } 708 | ] 709 | } 710 | ] -------------------------------------------------------------------------------- /examples/fw_inventory_example.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "hosts": "test_fw1", 4 | "connection": "local", 5 | "gather_facts": false, 6 | "vars": { 7 | "test_fw": { 8 | "fortigate_username": "admin", 9 | "fortigate_password": "{{ pw }}", 10 | "fortigate_ip": "{{ ip }}", 11 | "secure": "{{ secure }}", 12 | "port": "{{ port }}", 13 | "verify": false 14 | } 15 | }, 16 | "tasks": [ 17 | { 18 | "name": "set system global setup", 19 | "tags": [ 20 | "system_global", 21 | "system" 22 | ], 23 | "fortios_api_system_global": { 24 | "print_current_config": false, 25 | "conn_params": "{{ test_fw }}", 26 | "global": "{{ system_global }}" 27 | } 28 | }, 29 | { 30 | "name": "Update All Interfaces", 31 | "tags": [ 32 | "interfaces" 33 | ], 34 | "fortios_api_interface": { 35 | "conn_params": "{{ test_fw }}", 36 | "print_current_config": false, 37 | "permanent_objects": [ 38 | "ssl.root", 39 | "port2", 40 | "port3", 41 | "port4", 42 | "port5", 43 | "port6", 44 | "port7", 45 | "port8", 46 | "port9", 47 | "port10" 48 | ], 49 | "ignore_objects": [ 50 | "port1", 51 | "mgmt1" 52 | ], 53 | "interfaces": "{{ interfaces }}" 54 | } 55 | }, 56 | { 57 | "name": "Configure VRRP", 58 | "tags": [ 59 | "interfaces" 60 | ], 61 | "fortios_api": { 62 | "endpoint_information": { 63 | "endpoint": "cmdb/system/interface/{{ item.name }}/vrrp", 64 | "list_identifier": "vrrp", 65 | "object_identifier": "vrid" 66 | }, 67 | "conn_params": "{{ test_fw }}", 68 | "vrrp": "{{ item.params }}" 69 | }, 70 | "with_items": [ 71 | "{{ vrrp }}" 72 | ] 73 | }, 74 | { 75 | "name": "Update system admin", 76 | "tags": [ 77 | "system_admin", 78 | "system" 79 | ], 80 | "fortios_api_system_admin": { 81 | "conn_params": "{{ test_fw }}", 82 | "admins": "{{ system_admins }}" 83 | } 84 | }, 85 | { 86 | "name": "set system dns setup", 87 | "tags": [ 88 | "dns", 89 | "system" 90 | ], 91 | "fortios_api_system_dns": { 92 | "conn_params": "{{ test_fw }}", 93 | "dns": "{{ system_dns }}" 94 | } 95 | } 96 | ] 97 | } 98 | ] -------------------------------------------------------------------------------- /examples/group_vars/test.json: -------------------------------------------------------------------------------- 1 | { 2 | "log_settings": [ 3 | { 4 | "name": "syslogd", 5 | "server": "10.0.5.98", 6 | "status": "enable" 7 | }, 8 | { 9 | "name": "syslogd2", 10 | "server": "10.0.5.99", 11 | "status": "enable" 12 | }, 13 | { 14 | "name": "syslogd3", 15 | "server": "10.0.5.88", 16 | "status": "enable" 17 | } 18 | ], 19 | "snmp_community": [ 20 | { 21 | "events": [ 22 | "cpu-high", 23 | "mem-low", 24 | "log-full", 25 | "intf-ip", 26 | "vpn-tun-up", 27 | "vpn-tun-down", 28 | "ha-switch", 29 | "ha-hb-failure", 30 | "ips-signature", 31 | "ips-anomaly", 32 | "av-virus", 33 | "av-oversize", 34 | "av-pattern", 35 | "av-fragmented", 36 | "fm-if-change", 37 | "bgp-established", 38 | "bgp-backward-transition", 39 | "ha-member-up", 40 | "ha-member-down", 41 | "ent-conf-change", 42 | "av-conserve", 43 | "av-bypass", 44 | "av-oversize-passed", 45 | "av-oversize-blocked", 46 | "ips-pkg-update", 47 | "ips-fail-open", 48 | "power-supply-failure", 49 | "faz-disconnect", 50 | "wc-ap-up", 51 | "wc-ap-down" 52 | ], 53 | "hosts": [ 54 | "10.0.5.98 255.255.255.255", 55 | "10.0.5.99 255.255.255.255" 56 | ], 57 | "name": "public" 58 | } 59 | ], 60 | "system_admins": [ 61 | { 62 | "name": "test_admin", 63 | "comments": "test_update", 64 | "password": "test1", 65 | "accprofile": "prof_admin", 66 | "trusthost1": "192.168.0.0 255.254.0.0" 67 | }, 68 | { 69 | "name": "admin", 70 | "trusthost1": "10.0.0.0 255.0.0.0", 71 | "trusthost2": "192.0.0.0 255.0.0.0" 72 | } 73 | ], 74 | "system_dns": [ 75 | { 76 | "primary": "4.2.2.2", 77 | "secondary": "8.8.8.8" 78 | } 79 | ] 80 | } -------------------------------------------------------------------------------- /examples/host_vars/test_fw1.json: -------------------------------------------------------------------------------- 1 | { 2 | "interfaces": [ 3 | { 4 | "interface": "", 5 | "ip": "1.1.3.207 255.255.255.254", 6 | "name": "port3", 7 | "status": "up", 8 | "vdom": "root", 9 | "vlanforward": "disable", 10 | "vlanid": 0, 11 | "vrrp-virtual-mac": "disable" 12 | }, 13 | { 14 | "interface": "", 15 | "ip": "10.66.255.1 255.255.255.248", 16 | "name": "port4", 17 | "status": "up", 18 | "vdom": "root", 19 | "vlanforward": "enable", 20 | "vlanid": 0, 21 | "vrrp-virtual-mac": "disable" 22 | }, 23 | { 24 | "interface": "", 25 | "ip": "10.66.255.9 255.255.255.252", 26 | "name": "port5", 27 | "status": "down", 28 | "vdom": "root", 29 | "vlanforward": "enable", 30 | "vlanid": 0, 31 | "vrrp-virtual-mac": "disable" 32 | }, 33 | { 34 | "interface": "", 35 | "ip": "10.66.255.13 255.255.255.252", 36 | "name": "port6", 37 | "status": "down", 38 | "vdom": "root", 39 | "vlanforward": "enable", 40 | "vlanid": 0, 41 | "vrrp-virtual-mac": "disable" 42 | }, 43 | { 44 | "interface": "port4", 45 | "ip": "1.1.16.26 255.255.255.248", 46 | "name": "net_pub", 47 | "status": "up", 48 | "vdom": "root", 49 | "vlanforward": "disable", 50 | "vlanid": 4, 51 | "vrrp-virtual-mac": "enable" 52 | }, 53 | { 54 | "interface": "port4", 55 | "ip": "10.254.166.2 255.255.255.192", 56 | "name": "replication_net", 57 | "status": "up", 58 | "vdom": "root", 59 | "vlanforward": "disable", 60 | "vlanid": 3333, 61 | "vrrp-virtual-mac": "enable" 62 | } 63 | ], 64 | "ntp": { 65 | "interface": "port1", 66 | "ntpserver": [ 67 | { 68 | "server": "ntp-a.boulder.nist.gov" 69 | }, 70 | { 71 | "server": "time.nist.gov" 72 | }, 73 | { 74 | "server": "clock.nyc.he.net" 75 | } 76 | ], 77 | "server-mode": "enable", 78 | "type": "custom" 79 | }, 80 | "system_global": [ 81 | { 82 | "admintimeout": 30, 83 | "hostname": "Test-FW", 84 | "timezone": "80" 85 | } 86 | ], 87 | "vrrp": [ 88 | { 89 | "name": "net_pub", 90 | "params": [ 91 | { 92 | "priority": 255, 93 | "vrid": 1, 94 | "vrip": "1.1.16.25" 95 | } 96 | ] 97 | }, 98 | { 99 | "name": "replication_net", 100 | "params": [ 101 | { 102 | "priority": 200, 103 | "vrid": 1, 104 | "vrip": "10.254.166.1" 105 | } 106 | ] 107 | } 108 | ] 109 | } -------------------------------------------------------------------------------- /examples/test_inventory: -------------------------------------------------------------------------------- 1 | [test] 2 | test_fw1 ip=192.0.2.5 secure=False port=80 -------------------------------------------------------------------------------- /fortios/fortios_api.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module to manage arbitrary objects via API in fortigate devices 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or 6 | # https://www.gnu.org/licenses/gpl-3.0.txt) 7 | 8 | from __future__ import (absolute_import, division, print_function) 9 | __metaclass__ = type 10 | 11 | ANSIBLE_METADATA = {'metadata_version': '1.1', 12 | 'status': ['preview'], 13 | 'supported_by': 'community'} 14 | 15 | DOCUMENTATION = ''' 16 | --- 17 | module: fortios_api 18 | extends_documentation_fragment: fortios_api_doc 19 | version_added: "2.5" 20 | short_description: Manages arbitrarily designated fortios configurations. 21 | description: 22 | - Manages arbitrarily designated fortios configurations. Can be used to edit any endpoint, as long as proper API path is provided. 23 | author: 24 | - Will Wagner (@willwagner602) 25 | Eugene Opredelennov (@eoprede) 26 | notes: 27 | - Tested against Fortigate v5.4.5 VM 28 | 29 | options: 30 | endpoint_information: 31 | description: Information about the endpoint. 32 | required: true 33 | suboptions: 34 | endpoint: 35 | required: true 36 | description: identifies the string to be added to the api 37 | URL to access the appropriate endpoint. 38 | list_identifier: 39 | required: true 40 | description: The identifier used by this configuration to identify the list of 41 | objects that should be used to update the endpoint's configuration. 42 | object_identifier: 43 | required: false 44 | description: The unique identifier used by this endpoint to differentiate objects. 45 | Typically 'name', 'id', or some variation. Not required for endpoints which 46 | contain only a single object. 47 | permanent_objects: 48 | required: false 49 | description: A list of identifiers for objects at the endpoint that cannot be deleted. 50 | 51 | ''' 52 | EXAMPLES = ''' 53 | - name: Update router static 54 | fortios_api: 55 | endpoint_information: 56 | endpoint: cmdb/router/static 57 | list_identifier: routers 58 | object_identifier: seq-num 59 | permanent_objects: 60 | conn_params: 61 | fortigate_username: admin 62 | fortigate_password: test 63 | fortigate_ip: 1.2.3.4 64 | port: 10080 65 | verify: false 66 | secure: false 67 | proxies: 68 | http: socks5://127.0.0.1:9000 69 | routers: 70 | - seq-num: 1 71 | status: enable 72 | dst: 0.0.0.0 0.0.0.0 73 | gateway: 192.0.2.1 74 | distance: 10 75 | weight: 0 76 | priority: 0 77 | device: port1 78 | comment: '' 79 | blackhole: disable 80 | dynamic-gateway: disable 81 | virtual-wan-link: disable 82 | dstaddr: '' 83 | internet-service: 0 84 | internet-service-custom: '' 85 | 86 | - seq-num: 2 87 | status: enable 88 | dst: 0.0.0.0 0.0.0.0 89 | gateway: 192.0.3.1 90 | distance: 10 91 | weight: 0 92 | priority: 0 93 | device: port2 94 | comment: '' 95 | blackhole: disable 96 | dynamic-gateway: disable 97 | virtual-wan-link: disable 98 | dstaddr: '' 99 | internet-service: 0 100 | internet-service-custom: '' 101 | ''' 102 | 103 | RETURN = ''' 104 | proposed: 105 | description: k/v pairs of parameters passed into module and sent to the device for changes 106 | returned: always 107 | type: list 108 | sample: '[{"blackhole": "disable", "comment": "", "device": "port1", "distance": 10, 109 | "dst": "0.0.0.0 0.0.0.0", "dstaddr": "", "dynamic-gateway": "disable", 110 | "gateway": "192.0.2.1", "internet-service": 0, "internet-service-custom": "", 111 | "priority": 0, "seq-num": 1, "status": "enable", "virtual-wan-link": "disable", "weight": 0}, 112 | {"blackhole": "disable", "comment": "", "device": "port2", "distance": 10, 113 | "dst": "0.0.0.0 0.0.0.0", "dstaddr": "", "dynamic-gateway": "disable", 114 | "gateway": "192.0.3.1", "internet-service": 0, "internet-service-custom": "", 115 | "priority": 0, "seq-num": 2, "status": "enable", "virtual-wan-link": "disable", "weight": 0}]' 116 | existing: 117 | description: k/v pairs of existing configuration 118 | returned: always 119 | type: list 120 | sample: '[{"blackhole": "disable", "comment": "", "device": "port1", "distance": 10, 121 | "dst": "0.0.0.0 0.0.0.0", "dstaddr": "", "dynamic-gateway": "disable", 122 | "gateway": "192.0.2.1", "internet-service": 0, "internet-service-custom": "", 123 | "priority": 0, "q_origin_key": "1", "seq-num": 1, "status": "enable", 124 | "virtual-wan-link": "disable", "weight": 0}]' 125 | end_state: 126 | description: k/v pairs of configuration after module execution 127 | returned: always 128 | type: list 129 | sample: '[{"blackhole": "disable", "comment": "", "device": "port1", "distance": 10, 130 | "dst": "0.0.0.0 0.0.0.0", "dstaddr": "", "dynamic-gateway": "disable", 131 | "gateway": "192.0.2.1", "internet-service": 0, "internet-service-custom": "", 132 | "priority": 0, "q_origin_key": "1", "seq-num": 1, "status": "enable", 133 | "virtual-wan-link": "disable", "weight": 0}, 134 | {"blackhole": "disable", "comment": "", "device": "port2", "distance": 10, 135 | "dst": "0.0.0.0 0.0.0.0", "dstaddr": "", "dynamic-gateway": "disable", 136 | "gateway": "192.0.3.1", "internet-service": 0, "internet-service-custom": "", 137 | "priority": 0, "q_origin_key": "2", "seq-num": 2, "status": "enable", 138 | "virtual-wan-link": "disable", "weight": 0}]' 139 | changed: 140 | description: Whether a change was required for the device configuration. 141 | returned: always 142 | type: boolean 143 | sample: true 144 | msg: 145 | description: A short description of the success of the change and status of the device. 146 | returned: always 147 | type: str 148 | sample: "Configuration updated." 149 | ''' 150 | 151 | from ansible.module_utils.fortios_api import API 152 | 153 | interface_api_args = { 154 | "from_configs": True 155 | } 156 | 157 | 158 | def main(): 159 | forti_api = API(interface_api_args) 160 | forti_api.apply_configuration_to_endpoint() 161 | 162 | 163 | if __name__ == "__main__": 164 | main() 165 | -------------------------------------------------------------------------------- /fortios/fortios_api_firewall_address.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module for managing Fortigate devices via API 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or 6 | # https://www.gnu.org/licenses/gpl-3.0.txt) 7 | 8 | from __future__ import (absolute_import, division, print_function) 9 | __metaclass__ = type 10 | 11 | ANSIBLE_METADATA = {'metadata_version': '1.0', 12 | 'status': ['preview'], 13 | 'supported_by': 'community'} 14 | 15 | DOCUMENTATION = ''' 16 | --- 17 | module: fortios_api_firewall_address 18 | extends_documentation_fragment: fortios_api_doc 19 | version_added: "2.4" 20 | short_description: Manages Firewall address configuration. 21 | description: 22 | - Manages Firewall address configuration. 23 | author: 24 | - Will Wagner (@willwagner602) 25 | Eugene Opredelennov (@eoprede) 26 | notes: 27 | - Tested against Fortigate v5.4.5 VM 28 | - Assumes the list of default objects of firewall rules. This list may have to be edited in the library if it changes over time. 29 | 30 | options: 31 | address: 32 | description: 33 | - Full list of addresses to be applied to the Firewall. Note that any address not present in the list will be DELETED. 34 | required: true 35 | suboptions: 36 | name: 37 | description: 38 | - Name of the address (must be unique) 39 | required: true 40 | type: 41 | description: 42 | - type of the firewall rule 43 | required: false 44 | options: ['fqdn','ipmask','iprange'] 45 | ''' 46 | EXAMPLES = ''' 47 | --- 48 | - name: set firewall addresses 49 | fortios_api_firewall_address: 50 | conn_params: 51 | fortigate_username: admin 52 | fortigate_password: test 53 | fortigate_ip: 1.2.3.4 54 | port: 10080 55 | verify: false 56 | secure: false 57 | proxies: 58 | http: socks5://127.0.0.1:9000 59 | address: 60 | - name: test 61 | type: fqdn 62 | fqdn: test.com 63 | - name: test2 64 | type: ipmask 65 | subnet: 1.1.1.1 255.255.255.255 66 | ''' 67 | 68 | RETURN = ''' 69 | proposed: 70 | description: k/v pairs of parameters passed into module and sent to the device for changes 71 | returned: always 72 | type: list 73 | 74 | existing: 75 | description: k/v pairs of existing configuration 76 | returned: always 77 | type: list 78 | 79 | end_state: 80 | description: k/v pairs of configuration after module execution 81 | returned: always 82 | type: list 83 | 84 | changed: 85 | description: check to see if a change was made on the device 86 | returned: always 87 | type: boolean 88 | ''' 89 | 90 | from ansible.module_utils.fortios_api import API 91 | 92 | system_global_api_args = { 93 | 'endpoint': 'cmdb/firewall/address', 94 | 'list_identifier': 'address', 95 | 'object_identifier': 'name', 96 | 'default_ignore_params': [], 97 | "ignore_objects": [ 98 | "Adobe Login", 99 | "FIREWALL_AUTH_PORTAL_ADDRESS", 100 | "Gotomeeting", 101 | "SSLVPN_TUNNEL_ADDR1", 102 | "Windows update 2", 103 | "adobe", 104 | "all", 105 | "android", 106 | "apple", 107 | "appstore", 108 | "auth.gfx.ms", 109 | "autoupdate.opera.com", 110 | "citrix", 111 | "dropbox.com", 112 | "eease", 113 | "firefox update server", 114 | "fortinet", 115 | "google-drive", 116 | "google-play", 117 | "google-play2", 118 | "google-play3", 119 | "googleapis.com", 120 | "icloud", 121 | "itunes", 122 | "microsoft", 123 | "skype", 124 | "softwareupdate.vmware.com", 125 | "swscan.apple.com", 126 | "update.microsoft.com", 127 | "verisign" 128 | ] 129 | } 130 | 131 | 132 | def main(): 133 | forti_api = API(system_global_api_args) 134 | forti_api.apply_configuration_to_endpoint() 135 | 136 | 137 | if __name__ == "__main__": 138 | main() 139 | -------------------------------------------------------------------------------- /fortios/fortios_api_firewall_addrgrp.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module for managing Fortigate devices via API 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | ANSIBLE_METADATA = {'metadata_version': '1.0', 11 | 'status': ['preview'], 12 | 'supported_by': 'community'} 13 | 14 | DOCUMENTATION = ''' 15 | --- 16 | module: fortios_api_firewall_addrgrp 17 | extends_documentation_fragment: fortios_api_doc 18 | version_added: "2.4" 19 | short_description: Manages Firewall address group configuration. 20 | description: 21 | - Manages Firewall address group configuration. 22 | author: 23 | - Will Wagner (@willwagner602) 24 | Eugene Opredelennov (@eoprede) 25 | notes: 26 | - Tested against Fortigate v5.4.5 VM 27 | 28 | options: 29 | addrgrp: 30 | description: 31 | - Full list of address groups to be applied to the Firewall. Note that any address group not present in the list will be DELETED. 32 | required: true 33 | suboptions: 34 | name: 35 | description: 36 | - Name of the address group (must be unique) 37 | required: true 38 | member: 39 | description: 40 | - List of the addresses (by name) to add to the address group 41 | required: false 42 | ''' 43 | EXAMPLES = ''' 44 | --- 45 | name: set firewall address group 46 | fortios_api_firewall_addrgrp: 47 | conn_params: 48 | fortigate_username: admin 49 | fortigate_password: test 50 | fortigate_ip: 1.2.3.4 51 | port: 10080 52 | verify: false 53 | secure: false 54 | proxies: 55 | http: socks5://127.0.0.1:9000 56 | addrgrp: 57 | - name: test_grp 58 | member: 59 | - name: test 60 | - name: test2 61 | ''' 62 | 63 | RETURN = ''' 64 | proposed: 65 | description: k/v pairs of parameters passed into module and sent to the device for changes 66 | returned: always 67 | type: list 68 | 69 | existing: 70 | description: k/v pairs of existing configuration 71 | returned: always 72 | type: list 73 | 74 | end_state: 75 | description: k/v pairs of configuration after module execution 76 | returned: always 77 | type: list 78 | 79 | changed: 80 | description: check to see if a change was made on the device 81 | returned: always 82 | type: boolean 83 | ''' 84 | 85 | from ansible.module_utils.fortios_api import API 86 | 87 | system_global_api_args = { 88 | 'endpoint': 'cmdb/firewall/addrgrp', 89 | 'list_identifier': 'addrgrp', 90 | 'object_identifier': 'name', 91 | 'default_ignore_params': [] 92 | } 93 | 94 | 95 | def main(): 96 | forti_api = API(system_global_api_args) 97 | forti_api.apply_configuration_to_endpoint() 98 | 99 | 100 | if __name__ == "__main__": 101 | main() 102 | -------------------------------------------------------------------------------- /fortios/fortios_api_firewall_dos_policy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module to manage arbitrary objects via API in fortigate devices 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | ANSIBLE_METADATA = {'metadata_version': '1.0', 11 | 'status': ['preview'], 12 | 'supported_by': 'community'} 13 | 14 | DOCUMENTATION = ''' 15 | --- 16 | module: fortios_api_firewall_dos_policy 17 | extends_documentation_fragment: fortios_api_doc 18 | version_added: "2.4" 19 | short_description: Manages firewall DoS policy configuration. 20 | description: 21 | - Manages firewall DoS policy configuration. 22 | author: 23 | - Will Wagner (@willwagner602) 24 | - Eugene Opredelennov (@eoprede) 25 | notes: 26 | - Tested against Fortigate v5.4.5 VM 27 | - Can use all of the parameters supported by Fortigate API 28 | - The FortiOS API has a bug that rejects creating objects at this endpoint on an initial request. 29 | As a temporary workaround, simply setup your playbook to immediately re-attempt the configuration. 30 | A permanent workaround will require a fix to the API by the vendor. 31 | 32 | options: 33 | dos_policies: 34 | description: 35 | - DoS policy parameters, must be a list of firewall DoS policy objects. 36 | ''' 37 | EXAMPLES = ''' 38 | # It appears that you MUST submit full anomaly list with all the configuration parameters, 39 | # API will not assume any default values for anomaly list 40 | fortios_api_firewall_dos_policy: 41 | endpoint_information: 42 | conn_params: '{{ test_fw }}' 43 | dos_policies: 44 | - interface: "port3" 45 | srcaddr: 46 | - name: "all" 47 | dstaddr: 48 | - name: "all" 49 | service: 50 | - name: "ALL" 51 | policyid: 1 52 | anomaly: 53 | 54 | - name: "tcp_syn_flood" 55 | status: enable 56 | log: enable 57 | threshold: 2000 58 | 59 | - name: "tcp_port_scan" 60 | status: disable 61 | 62 | - name: "tcp_src_session" 63 | status: enable 64 | log: enable 65 | threshold: 5000 66 | 67 | - name: "tcp_dst_session" 68 | status: enable 69 | log: enable 70 | threshold: 5000 71 | 72 | - name: "udp_flood" 73 | status: enable 74 | log: enable 75 | action: block 76 | threshold: 20000 77 | 78 | - name: "udp_scan" 79 | status: enable 80 | log: enable 81 | threshold: 2000 82 | 83 | - name: "udp_src_session" 84 | status: enable 85 | log: enable 86 | threshold: 5000 87 | 88 | - name: "udp_dst_session" 89 | status: enable 90 | log: enable 91 | threshold: 5000 92 | 93 | - name: "icmp_flood" 94 | status: enable 95 | log: enable 96 | threshold: 250 97 | 98 | - name: "icmp_sweep" 99 | status: enable 100 | log: enable 101 | threshold: 100 102 | 103 | - name: "icmp_src_session" 104 | status: enable 105 | log: enable 106 | threshold: 300 107 | 108 | - name: "icmp_dst_session" 109 | status: enable 110 | log: enable 111 | threshold: 1000 112 | 113 | - name: "ip_src_session" 114 | status: enable 115 | log: enable 116 | threshold: 5000 117 | 118 | - name: "ip_dst_session" 119 | status: enable 120 | log: enable 121 | threshold: 5000 122 | 123 | - name: "sctp_flood" 124 | status: enable 125 | log: enable 126 | threshold: 2000 127 | 128 | - name: "sctp_scan" 129 | status: enable 130 | log: enable 131 | threshold: 1000 132 | 133 | - name: "sctp_src_session" 134 | status: enable 135 | log: enable 136 | threshold: 5000 137 | 138 | - name: "sctp_dst_session" 139 | status: enable 140 | log: enable 141 | threshold: 5000 142 | ''' 143 | 144 | RETURN = ''' 145 | proposed: 146 | description: k/v pairs of parameters passed into module and sent to the device for changes 147 | returned: always 148 | type: list 149 | sample: '[{"anomaly": [ 150 | {"log": "enable", "name": "tcp_syn_flood", "status": "enable", "threshold": 2000}, 151 | {"name": "tcp_port_scan", "status": "disable"}, 152 | {"log": "enable", "name": "tcp_src_session", "status": "enable", "threshold": 5000}, 153 | {"log": "enable", "name": "tcp_dst_session", "status": "enable", "threshold": 5000}, 154 | {"action": "block", "log": "enable", "name": "udp_flood", "status": "enable", "threshold": 20000}, 155 | {"log": "enable", "name": "udp_scan", "status": "enable", "threshold": 2000}, 156 | {"log": "enable", "name": "udp_src_session", "status": "enable", "threshold": 5000}, 157 | {"log": "enable", "name": "udp_dst_session", "status": "enable", "threshold": 5000}, 158 | {"log": "enable", "name": "icmp_flood", "status": "enable", "threshold": 250}, 159 | {"log": "enable", "name": "icmp_sweep", "status": "enable", "threshold": 100}, 160 | {"log": "enable", "name": "icmp_src_session", "status": "enable", "threshold": 300}, 161 | {"log": "enable", "name": "icmp_dst_session", "status": "enable", "threshold": 1000}, 162 | {"log": "enable", "name": "ip_src_session", "status": "enable", "threshold": 5000}, 163 | {"log": "enable", "name": "ip_dst_session", "status": "enable", "threshold": 5000}, 164 | {"log": "enable", "name": "sctp_flood", "status": "enable", "threshold": 2000}, 165 | {"log": "enable", "name": "sctp_scan", "status": "enable", "threshold": 1000}, 166 | {"log": "enable", "name": "sctp_src_session", "status": "enable", "threshold": 5000}, 167 | {"log": "enable", "name": "sctp_dst_session", "status": "enable", "threshold": 5000}], 168 | "dstaddr": [{"name": "all"}], 169 | "interface": "port3", 170 | "policyid": 1, 171 | "service": [{"name": "ALL"}], 172 | "srcaddr": [{"name": "all"}]}]' 173 | existing: 174 | description: k/v pairs of existing configuration 175 | returned: always 176 | type: list 177 | sample: '[]' 178 | end_state: 179 | description: k/v pairs of configuration after module execution 180 | returned: always 181 | type: list 182 | changed: 183 | description: Whether a change was required for the device configuration. 184 | returned: always 185 | type: boolean 186 | sample: true 187 | msg: 188 | description: A short description of the success of the change and status of the device. 189 | returned: always 190 | type: str 191 | sample: "Configuration updated." 192 | ''' 193 | 194 | from ansible.module_utils.fortios_api import API 195 | 196 | router_ospf_ospf_interface_args = { 197 | "endpoint": ['cmdb', 'firewall', 'DoS-policy'], 198 | "list_identifier": 'dos_policies', 199 | "object_identifier": "policyid", 200 | "permanent_objects": [], 201 | "default_ignore_params": [], 202 | "match_ignore_params": [] 203 | } 204 | 205 | 206 | def main(): 207 | forti_api = API(router_ospf_ospf_interface_args) 208 | forti_api.apply_configuration_to_endpoint() 209 | 210 | 211 | if __name__ == "__main__": 212 | main() 213 | -------------------------------------------------------------------------------- /fortios/fortios_api_firewall_ippool.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module for managing Fortigate devices via API 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | ANSIBLE_METADATA = {'metadata_version': '1.0', 11 | 'status': ['preview'], 12 | 'supported_by': 'community'} 13 | 14 | DOCUMENTATION = ''' 15 | --- 16 | module: fortios_api_firewall_ippool 17 | extends_documentation_fragment: fortios_api_doc 18 | version_added: "2.4" 19 | short_description: Manages Firewall IP pool configuration. 20 | description: 21 | - Manages Firewall IP pool configuration. 22 | author: 23 | - Will Wagner (@willwagner602) 24 | Eugene Opredelennov (@eoprede) 25 | notes: 26 | - Tested against Fortigate v5.4.5 VM 27 | 28 | options: 29 | ippool: 30 | description: 31 | - Full list of IP pools to be applied to the Firewall. Note that any ip pool not present in the list will be DELETED. 32 | required: true 33 | suboptions: 34 | name: 35 | description: 36 | - Name of the IP pool (must be unique) 37 | required: true 38 | type: 39 | description: 40 | - Type of the IP pool 41 | required: true 42 | startip: 43 | description: 44 | - Start IP of the pool 45 | required: true 46 | endip: 47 | description: 48 | - End IP of the pool 49 | required: true 50 | 51 | ''' 52 | EXAMPLES = ''' 53 | --- 54 | name: set firewall IP pool 55 | fortios_api_firewall_ippool: 56 | conn_params: 57 | fortigate_username: admin 58 | fortigate_password: test 59 | fortigate_ip: 1.2.3.4 60 | port: 10080 61 | verify: false 62 | secure: false 63 | proxies: 64 | http: socks5://127.0.0.1:9000 65 | ippool: 66 | - name: test_pool 67 | type: one-to-one 68 | startip: 1.2.3.4 69 | endip: 1.2.3.4 70 | - name: test_pool_overload 71 | type: overload 72 | startip: 2.2.3.4 73 | endip: 2.2.3.5 74 | 75 | ''' 76 | 77 | RETURN = ''' 78 | proposed: 79 | description: k/v pairs of parameters passed into module and sent to the device for changes 80 | returned: always 81 | type: list 82 | 83 | existing: 84 | description: k/v pairs of existing configuration 85 | returned: always 86 | type: list 87 | 88 | end_state: 89 | description: k/v pairs of configuration after module execution 90 | returned: always 91 | type: list 92 | 93 | changed: 94 | description: check to see if a change was made on the device 95 | returned: always 96 | type: boolean 97 | ''' 98 | 99 | from ansible.module_utils.fortios_api import API 100 | 101 | system_global_api_args = { 102 | 'endpoint': 'cmdb/firewall/ippool', 103 | 'list_identifier': 'ippool', 104 | 'object_identifier': 'name', 105 | 'default_ignore_params': [] 106 | } 107 | 108 | 109 | def main(): 110 | forti_api = API(system_global_api_args) 111 | forti_api.apply_configuration_to_endpoint() 112 | 113 | 114 | if __name__ == "__main__": 115 | main() 116 | -------------------------------------------------------------------------------- /fortios/fortios_api_firewall_policy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module to manage arbitrary objects via API in fortigate devices 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or 6 | # https://www.gnu.org/licenses/gpl-3.0.txt) 7 | 8 | from __future__ import (absolute_import, division, print_function) 9 | __metaclass__ = type 10 | 11 | ANSIBLE_METADATA = {'metadata_version': '1.0', 12 | 'status': ['preview'], 13 | 'supported_by': 'community'} 14 | 15 | DOCUMENTATION = ''' 16 | --- 17 | module: fortios_api_firewall_policy 18 | extends_documentation_fragment: fortios_api_doc 19 | version_added: "2.4" 20 | short_description: Manages Firewall policy configuration. 21 | description: 22 | - Manages Firewall policy configuration. 23 | author: 24 | - Will Wagner (@willwagner602) 25 | Eugene Opredelennov (@eoprede) 26 | notes: 27 | - Tested against Fortigate v5.4.5 VM 28 | - Assumes the list of default (permanent) objects. 29 | 30 | options: 31 | policies: 32 | description: 33 | - Full list of policies to be applied to the Firewall. Note that any policy not present in the list will be DELETED. 34 | The order in which objects appear in the list is the order in which Firewall will process the rules. 35 | required: true 36 | suboptions: 37 | policyid: 38 | description: 39 | - ID of the policy, must be unique 40 | required: true 41 | name: 42 | description: 43 | - Name of the policy. Doesn't exist in 5.2 and isn't required for 5.4 CLI, but required for 5.4 GUI 44 | required: false 45 | default: null 46 | srcintf: 47 | description: 48 | - Source interface. 49 | required: true 50 | type: list 51 | dstintf: 52 | description: 53 | - Destination interface 54 | required: true 55 | type: list 56 | srcaddr: 57 | description: 58 | - Source address. 59 | required: true 60 | type: list 61 | dstaddr: 62 | description: 63 | - Destination address. 64 | required: true 65 | type: list 66 | schedule: 67 | description: 68 | - Schedule. 69 | required: true 70 | service: 71 | description: 72 | - Service(s) list. 73 | required: true 74 | type: list 75 | action: 76 | description: 77 | - What to do with the traffic matched by the policy 78 | required: true 79 | type: str 80 | choices: ['accept', 'deny', 'learn'] 81 | ''' 82 | EXAMPLES = ''' 83 | --- 84 | name: update firewall policies 85 | fortios_api_firewall_policy: 86 | conn_params: 87 | fortigate_username: admin 88 | fortigate_password: test 89 | fortigate_ip: 1.2.3.4 90 | port: 10080 91 | verify: false 92 | secure: false 93 | proxies: 94 | http: socks5://127.0.0.1:9000 95 | policies: 96 | - policyid: 14 97 | srcintf: 98 | - name: port4 99 | dstintf: 100 | - name: port3 101 | srcaddr: 102 | - name: auth.gfx.ms 103 | dstaddr: 104 | - name: all 105 | action: accept 106 | schedule: always 107 | service: 108 | - name: IMAPS 109 | comments: test_policy 110 | name: Test policy 111 | nat: enable 112 | - policyid: 5 113 | srcintf: 114 | - name: port3 115 | dstintf: 116 | - name: port5 117 | srcaddr: 118 | - name: all 119 | dstaddr: 120 | - name: all 121 | action: accept 122 | schedule: always 123 | service: 124 | - name: IMAPS 125 | comments: allow_imaps_in 126 | name: imaps_in 127 | ''' 128 | 129 | RETURN = ''' 130 | proposed: 131 | description: k/v pairs of parameters passed into module and sent to the device for changes 132 | returned: always 133 | type: list 134 | 135 | existing: 136 | description: k/v pairs of existing configuration 137 | returned: always 138 | type: list 139 | 140 | end_state: 141 | description: k/v pairs of configuration after module execution 142 | returned: always 143 | type: list 144 | 145 | changed: 146 | description: check to see if a change was made on the device 147 | returned: always 148 | type: boolean 149 | ''' 150 | 151 | from ansible.module_utils.fortios_api import API 152 | 153 | 154 | fw_api_args = { 155 | "endpoint": ["cmdb", "firewall", "policy"], 156 | "list_identifier": 'policies', 157 | "object_identifier": 'policyid', 158 | "permanent_objects": [], 159 | "default_ignore_params": [], 160 | } 161 | 162 | 163 | class FirewallAPI(API): 164 | 165 | def __init__(self, module): 166 | super(FirewallAPI, self).__init__(module) 167 | self._validate_policies() 168 | self._object_map = [] 169 | 170 | def _validate_policies(self): 171 | policy_specification = self._get_argument_spec() 172 | if not self._update_config: 173 | return 174 | 175 | types = { 176 | 'str': str, 177 | 'list': list, 178 | 'dict': dict, 179 | 'int': int, 180 | } 181 | 182 | required = [k for k in policy_specification if policy_specification[ 183 | k].get('necessary')] 184 | for i, policy in enumerate(self._update_config): 185 | missing = [] 186 | unrecognized = [] 187 | wrong_type = "" 188 | 189 | for k in required: 190 | if k not in policy: 191 | missing.append(k) 192 | 193 | if missing: 194 | self.fail(msg="Missing required arguments '%s' in policy #%s" % ( 195 | ", ".join(missing), str(i))) 196 | 197 | try: 198 | for k, v in policy.items(): 199 | if k not in policy_specification: 200 | unrecognized.append(k) 201 | else: 202 | value_type = type(v) 203 | required_type = policy_specification[k].get('type') 204 | if v is not None and value_type != types[required_type]: 205 | wrong_type += ("Wrong type %s for argument '%s' in policy #%s. Requires %s.\n" % ( 206 | value_type, k, str(i), required_type)) 207 | except AttributeError: 208 | for k, v in policy.items(): 209 | if k not in policy_specification: 210 | unrecognized.append(k) 211 | else: 212 | value_type = type(v) 213 | required_type = policy_specification[k].get('type') 214 | if v is not None and value_type != types[required_type]: 215 | wrong_type += ("Wrong type %s for argument '%s' in policy #%s. Requires %s.\n" % ( 216 | value_type, k, str(i), required_type)) 217 | 218 | if wrong_type: 219 | self.fail(wrong_type) 220 | 221 | if unrecognized: 222 | self.fail(msg="Unrecognized arguments '%s' in policy #%s" % 223 | (", ".join(unrecognized), str(i))) 224 | 225 | def apply_configuration_to_endpoint(self): 226 | self._execute_config_changes() 227 | if self._full_config: 228 | self._build_object_map() 229 | self._move_existing_policies() 230 | if not self._check_mode: 231 | message, changed, failed = self._process_response() 232 | changed = changed or self._order_changed() 233 | else: 234 | message = "Check Mode" 235 | original_match, update_match = self._original_or_update_match_current_configuration() 236 | changed = not update_match or self._order_changed() 237 | failed = False 238 | 239 | self._module.exit_json(msg=message, changed=changed, failed=failed, 240 | existing=self._fortigate_current_config, proposed=self._update_config, new=self._diff_configs()) 241 | 242 | def _order_changed(self): 243 | try: 244 | return any([True for i, o in enumerate(self._fortigate_original_config) 245 | if o[self._object_identifier] != self._fortigate_current_config[i][self._object_identifier]]) 246 | except IndexError: 247 | return True 248 | 249 | def _identify_highest_distance_move(self): 250 | index = None 251 | highest = 0 252 | for i, policy_info in enumerate(self._object_map): 253 | if policy_info: 254 | move_distance = policy_info[2] 255 | if move_distance > highest: 256 | index = i 257 | highest = move_distance 258 | return index 259 | 260 | def _get_policy_index_from_object_map(self, target_policy_id): 261 | index = None 262 | for i, policy_info in enumerate(self._object_map): 263 | policy_id = policy_info[1] 264 | if policy_id == target_policy_id: 265 | index = i 266 | break 267 | return index 268 | 269 | def _move_existing_policies(self): 270 | mpol_target_index = self._identify_highest_distance_move() 271 | while mpol_target_index is not None: 272 | self._move_policy(mpol_target_index) 273 | mpol_target_index = self._identify_highest_distance_move() 274 | 275 | def _move_policy(self, mpol_target_index): 276 | # move policy is the one going to its final position 277 | mpol_info = self._object_map[mpol_target_index] 278 | mpol_cur_index = mpol_info[0] 279 | mpol_id = mpol_info[1] 280 | 281 | target_index_id = self._fortigate_current_config[ 282 | mpol_target_index]['policyid'] 283 | 284 | if mpol_target_index > mpol_cur_index: 285 | self._fortigate_current_config.insert( 286 | mpol_target_index + 1, self._fortigate_current_config[mpol_cur_index]) 287 | del self._fortigate_current_config[mpol_cur_index] 288 | if not self._check_mode: 289 | self._edit('/'.join([self._endpoint, str(mpol_id)]), 290 | params={"action": "move", "after": str(target_index_id), "vdom": self._vdom}) 291 | else: 292 | self._fortigate_current_config.insert( 293 | mpol_target_index, self._fortigate_current_config[mpol_cur_index]) 294 | del self._fortigate_current_config[mpol_cur_index + 1] 295 | if not self._check_mode: 296 | self._edit('/'.join([self._endpoint, str(mpol_id)]), 297 | params={"action": "move", "before": str(target_index_id), "vdom": self._vdom}) 298 | 299 | self._build_object_map() 300 | 301 | def _find_policy_index_in_current_config_by_id(self, policy_id): 302 | for i, p in enumerate(self._fortigate_current_config): 303 | if p['policyid'] == policy_id: 304 | return i 305 | return False 306 | 307 | def _get_index_of_matching_object(self, forti_object): 308 | found = False 309 | existing_index = 0 310 | existing_object_count = len(self._fortigate_current_config) 311 | 312 | while not found and existing_index < existing_object_count: 313 | if not self._diff_unknown(self._fortigate_current_config[existing_index], forti_object): 314 | return existing_index 315 | existing_index = existing_index + 1 316 | return None 317 | 318 | def _build_object_map(self): 319 | self._get_current_configuration() 320 | if not self._update_config: 321 | self._object_map = [None] * len(self._fortigate_current_config) 322 | else: 323 | self._object_map = [] 324 | for desired_index, forti_object in enumerate(self._update_config): 325 | existing_index = self._get_index_of_matching_object( 326 | forti_object) 327 | if existing_index is not None: 328 | self._object_map.append((existing_index, 329 | self._fortigate_current_config[ 330 | existing_index][self._object_identifier], 331 | abs(existing_index - desired_index))) 332 | else: 333 | self._object_map.append(None) 334 | 335 | 336 | def main(): 337 | forti_api = FirewallAPI(fw_api_args) 338 | forti_api.apply_configuration_to_endpoint() 339 | 340 | 341 | if __name__ == "__main__": 342 | main() 343 | -------------------------------------------------------------------------------- /fortios/fortios_api_firewall_service.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module to manage arbitrary objects via API in fortigate devices 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or 6 | # https://www.gnu.org/licenses/gpl-3.0.txt) 7 | 8 | from __future__ import (absolute_import, division, print_function) 9 | __metaclass__ = type 10 | 11 | ANSIBLE_METADATA = {'metadata_version': '1.0', 12 | 'status': ['preview'], 13 | 'supported_by': 'community'} 14 | 15 | DOCUMENTATION = ''' 16 | --- 17 | module: fortios_api_firewall_service 18 | extends_documentation_fragment: fortios_api_doc 19 | version_added: "2.4" 20 | short_description: Manages Firewall custom service configuration. 21 | description: 22 | - Manages Firewall custom service configuration. 23 | author: 24 | - Will Wagner (@willwagner602) 25 | Eugene Opredelennov (@eoprede) 26 | notes: 27 | - Tested against Fortigate v5.4.5 VM 28 | - Assumes the list of default (permanent) objects. This list may have to be edited in the library (or moved to device config) if it changes over time. 29 | 30 | options: 31 | services: 32 | description: 33 | - Full list of services to be applied to the Firewall. Note that any service not present in the list will be DELETED. 34 | required: true 35 | suboptions: 36 | name: 37 | description: 38 | - Name of the firewall service 39 | required: true 40 | comment: 41 | description: 42 | - Comment for the firewall service 43 | required: false 44 | default: null 45 | tcp-portrange: 46 | description: 47 | - TCP ports used by the service separated by space, use '-' for multiple ports 48 | required: false 49 | default: null 50 | udp-portrange: 51 | description: 52 | - UDP ports used by the service separated by space, use '-' for multiple ports 53 | required: false 54 | default: null 55 | ''' 56 | EXAMPLES = ''' 57 | # Sample FW service 58 | - name: update firewall services 59 | fortios_api_firewall_service: 60 | print_current_config: false 61 | conn_params: 62 | fortigate_username: admin 63 | fortigate_password: test 64 | fortigate_ip: 1.2.3.4 65 | port: 10080 66 | verify: false 67 | secure: false 68 | proxies: 69 | http: socks5://127.0.0.1:9000 70 | services: 71 | - name: allow_outbound_test 72 | comment: allow_outbound_test 73 | tcp-portrange: 25 53 80 443 200-201 74 | udp-portrange: '69' 75 | - name: test_tcp_9993 76 | comment: test_tcp_9993 77 | tcp-portrange: '9993' 78 | ''' 79 | 80 | RETURN = ''' 81 | proposed: 82 | description: k/v pairs of parameters passed into module and sent to the device for changes 83 | returned: always 84 | type: list 85 | 86 | existing: 87 | description: k/v pairs of existing configuration 88 | returned: always 89 | type: list 90 | 91 | end_state: 92 | description: k/v pairs of configuration after module execution 93 | returned: always 94 | type: list 95 | 96 | changed: 97 | description: check to see if a change was made on the device 98 | returned: always 99 | type: boolean 100 | ''' 101 | 102 | from ansible.module_utils.fortios_api import API 103 | 104 | system_global_api_args = { 105 | 'endpoint': 'cmdb/firewall.service/custom', 106 | 'list_identifier': 'services', 107 | 'object_identifier': 'name', 108 | 'default_ignore_params': [], 109 | 'ignore_objects': ['ALL', 'DNS', 'HTTP', 'HTTPS', 'IMAP', 'IMAPS', 'LDAP', 'DCE-RPC', 'POP3', 110 | 'POP3S', 'SAMBA', 'SMTP', 'SMTPS', 'KERBEROS', 'LDAP_UDP', 'SMB', 'webproxy', 111 | 'ALL_TCP', 'ALL_UDP', 'ALL_ICMP', 'ALL_ICMP6', 'GRE', 'AH', 'ESP', 'AOL', 'BGP', 'DHCP', 'FINGER', 'FTP', 112 | 'FTP_GET', 'FTP_PUT', 'GOPHER', 'H323', 'IKE', 'Internet-Locator-Service', 'IRC', 'L2TP', 'NetMeeting', 113 | 'NFS', 'NNTP', 'NTP', 'OSPF', 'PC-Anywhere', 'PING', 'TIMESTAMP', 'INFO_REQUEST', 'INFO_ADDRESS', 114 | 'ONC-RPC', 'PPTP', 'QUAKE', 'RAUDIO', 'REXEC', 'RIP', 'RLOGIN', 'RSH', 'SCCP', 'SIP', 'SIP-MSNmessenger', 115 | 'SNMP', 'SSH', 'SYSLOG', 'TALK', 'TELNET', 'TFTP', 'MGCP', 'UUCP', 'VDOLIVE', 'WAIS', 'WINFRAME', 116 | 'X-WINDOWS', 'PING6', 'MS-SQL', 'MYSQL', 'RDP', 'VNC', 'DHCP6', 'SQUID', 'SOCKS', 'WINS', 'RADIUS', 117 | 'RADIUS-OLD', 'CVSPSERVER', 'AFS3', 'TRACEROUTE', 'RTSP', 'MMS', 'NONE'] 118 | } 119 | 120 | 121 | def main(): 122 | forti_api = API(system_global_api_args) 123 | forti_api.apply_configuration_to_endpoint() 124 | 125 | 126 | if __name__ == "__main__": 127 | main() 128 | -------------------------------------------------------------------------------- /fortios/fortios_api_firewall_service_group.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module to manage arbitrary objects via API in fortigate devices 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or 6 | # https://www.gnu.org/licenses/gpl-3.0.txt) 7 | 8 | from __future__ import (absolute_import, division, print_function) 9 | __metaclass__ = type 10 | 11 | ANSIBLE_METADATA = {'metadata_version': '1.0', 12 | 'status': ['preview'], 13 | 'supported_by': 'community'} 14 | 15 | DOCUMENTATION = ''' 16 | --- 17 | module: fortios_api_firewall_service_group 18 | extends_documentation_fragment: fortios_api_doc 19 | version_added: "2.4" 20 | short_description: Manages Firewall custom service group configuration. 21 | description: 22 | - Manages Firewall custom service group configuration. 23 | author: 24 | - Will Wagner (@willwagner602) 25 | Eugene Opredelennov (@eoprede) 26 | Daryl Banttari (@dbanttari) 27 | notes: 28 | - Tested against Fortigate v5.4.5 VM 29 | - Assumes the list of default (permanent) objects. This list may have to be edited in the library (or moved to device config) if it changes over time. 30 | 31 | options: 32 | services: 33 | description: 34 | - Full list of service groups to be applied to the Firewall. Note that any service group not present in the list will be DELETED. 35 | required: true 36 | suboptions: 37 | name: 38 | description: 39 | - Name of the firewall service 40 | required: true 41 | groups: 42 | description: 43 | - List of named services 44 | required: true 45 | ''' 46 | EXAMPLES = ''' 47 | # Sample FW service 48 | - name: update firewall services 49 | fortios_api_firewall_service_group: 50 | print_current_config: false 51 | conn_params: 52 | fortigate_username: admin 53 | fortigate_password: test 54 | fortigate_ip: 1.2.3.4 55 | port: 10080 56 | verify: false 57 | secure: false 58 | proxies: 59 | http: socks5://127.0.0.1:9000 60 | groups: 61 | - name: dns_ldap 62 | services: DNS LDAP LDAPS 63 | ''' 64 | 65 | RETURN = ''' 66 | proposed: 67 | description: k/v pairs of parameters passed into module and sent to the device for changes 68 | returned: always 69 | type: list 70 | 71 | existing: 72 | description: k/v pairs of existing configuration 73 | returned: always 74 | type: list 75 | 76 | end_state: 77 | description: k/v pairs of configuration after module execution 78 | returned: always 79 | type: list 80 | 81 | changed: 82 | description: check to see if a change was made on the device 83 | returned: always 84 | type: boolean 85 | ''' 86 | 87 | from ansible.module_utils.fortios_api import API 88 | 89 | system_global_api_args = { 90 | 'endpoint': 'cmdb/firewall.service/group', 91 | 'list_identifier': 'groups', 92 | 'object_identifier': 'name', 93 | 'default_ignore_params': [], 94 | 'ignore_objects': [] 95 | } 96 | 97 | 98 | def main(): 99 | forti_api = API(system_global_api_args) 100 | forti_api.apply_configuration_to_endpoint() 101 | 102 | 103 | if __name__ == "__main__": 104 | main() 105 | -------------------------------------------------------------------------------- /fortios/fortios_api_firewall_vip.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module for managing Fortigate devices via API 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | ANSIBLE_METADATA = {'metadata_version': '1.0', 11 | 'status': ['preview'], 12 | 'supported_by': 'community'} 13 | 14 | DOCUMENTATION = ''' 15 | --- 16 | module: fortios_api_firewall_vip 17 | extends_documentation_fragment: fortios_api_doc 18 | version_added: "2.4" 19 | short_description: Manages Firewall VIP configuration. 20 | description: 21 | - Manages Firewall VIP configuration. 22 | author: 23 | - Will Wagner (@willwagner602) 24 | Eugene Opredelennov (@eoprede) 25 | notes: 26 | - Tested against Fortigate v5.4.5 VM 27 | 28 | options: 29 | vip: 30 | description: 31 | - Full list of VIPs to be applied to the Firewall. Note that any VIP not present in the list will be DELETED. 32 | required: true 33 | suboptions: 34 | name: 35 | description: 36 | - Name of the VIP (must be unique among VIPs and firewall addresses and address groups) 37 | required: true 38 | extip: 39 | description: 40 | - External IP of the pool 41 | required: true 42 | mappedip: 43 | description: 44 | - Mapped IP of the pool 45 | required: true 46 | extintf: 47 | description: 48 | - External interface on which pool will be active 49 | required: false 50 | 51 | ''' 52 | EXAMPLES = ''' 53 | --- 54 | name: set firewall IP pool 55 | fortios_api_firewall_vip: 56 | conn_params: 57 | fortigate_username: admin 58 | fortigate_password: test 59 | fortigate_ip: 1.2.3.4 60 | port: 10080 61 | verify: false 62 | secure: false 63 | proxies: 64 | http: socks5://127.0.0.1:9000 65 | print_current_config: false 66 | vip: 67 | - name: test_vip 68 | extintf: port3 69 | extip: 192.0.5.10 70 | mappedip: 71 | - range: 1.2.3.4 72 | - name: test_vip_range 73 | extintf: port3 74 | extip: 192.0.5.11-192.0.5.12 75 | mappedip: 76 | - range: 1.2.3.5-1.2.3.6 77 | ''' 78 | 79 | RETURN = ''' 80 | proposed: 81 | description: k/v pairs of parameters passed into module and sent to the device for changes 82 | returned: always 83 | type: list 84 | 85 | existing: 86 | description: k/v pairs of existing configuration 87 | returned: always 88 | type: list 89 | 90 | end_state: 91 | description: k/v pairs of configuration after module execution 92 | returned: always 93 | type: list 94 | 95 | changed: 96 | description: check to see if a change was made on the device 97 | returned: always 98 | type: boolean 99 | ''' 100 | 101 | from ansible.module_utils.fortios_api import API 102 | 103 | system_global_api_args = { 104 | 'endpoint': 'cmdb/firewall/vip', 105 | 'list_identifier': 'vip', 106 | 'object_identifier': 'name', 107 | 'default_ignore_params': [] 108 | } 109 | 110 | 111 | def main(): 112 | forti_api = API(system_global_api_args) 113 | forti_api.apply_configuration_to_endpoint() 114 | 115 | 116 | if __name__ == "__main__": 117 | main() 118 | -------------------------------------------------------------------------------- /fortios/fortios_api_interface.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module to manage arbitrary objects via API in fortigate devices 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | ANSIBLE_METADATA = {'metadata_version': '1.0', 11 | 'status': ['preview'], 12 | 'supported_by': 'community'} 13 | 14 | DOCUMENTATION = ''' 15 | --- 16 | module: fortios_api_interface 17 | extends_documentation_fragment: fortios_api_doc 18 | version_added: "2.4" 19 | short_description: Manages interface configuration. 20 | description: 21 | - Manages interface configuration. 22 | author: 23 | - Will Wagner (@willwagner602) 24 | Eugene Opredelennov (@eoprede) 25 | notes: 26 | - Tested against Fortigate v5.4.5 VM 27 | - Assumes the list of default (permanent) objects. 28 | 29 | options: 30 | permanent_objects: 31 | description: 32 | - List of all the permanent interfaces, so that module doesn't attempt to delete them. 33 | It varies depending on the FW model and must be accurate for module to work. 34 | required: true 35 | interfaces: 36 | description: 37 | - List of interfaces with specified parameters. If the interface is not specified, 38 | but is in a permanent list, it will be reset to default state. 39 | required: true 40 | suboptions: 41 | name: 42 | description: 43 | - Interface name 44 | required: false 45 | default: null 46 | ip: 47 | description: 48 | - Interface IP address 49 | required: false 50 | default: null 51 | description: 52 | description: 53 | - Interface description 54 | required: false 55 | default: null 56 | vdom: 57 | description: 58 | - Vdom to which the port belongs 59 | required: true 60 | ''' 61 | EXAMPLES = ''' 62 | --- 63 | name: Update interfaces on Fortigate VM (note permanent object list) 64 | fortios_api_interface: 65 | print_current_config: false 66 | conn_params: 67 | fortigate_username: admin 68 | fortigate_password: test 69 | fortigate_ip: 1.2.3.4 70 | port: 10080 71 | verify: false 72 | secure: false 73 | proxies: 74 | http: socks5://127.0.0.1:9000 75 | permanent_objects: 76 | - ssl.root 77 | - port1 78 | - port2 79 | - port3 80 | - port4 81 | - port5 82 | - port6 83 | - port7 84 | - port8 85 | - port9 86 | - port10 87 | interfaces: 88 | - name: port1 89 | allowaccess: ping ssh http 90 | ip: 192.0.2.5 255.255.255.0 91 | type: physical 92 | description: Management 93 | - name: port2 94 | vdom: root 95 | ipv6: 96 | autoconf: disable 97 | dhcp6-client-options: iapd iana dns 98 | dhcp6-prefix-delegation: enable 99 | dhcp6-prefix-hint: "::/60" 100 | ip6-allowaccess: ping 101 | ip6-mode: dhcp 102 | - name: port3 103 | vdom: root 104 | allowaccess: ping https http 105 | type: physical 106 | ip: 192.0.5.4 255.255.255.0 107 | - name: port5 108 | vdom: root 109 | vlanforward: enable 110 | type: physical 111 | - name: testint 112 | vdom: root 113 | allowaccess: ping 114 | ip: 192.0.3.56 255.255.255.0 115 | role: lan 116 | interface: port5 117 | vlanid: 5 118 | vrrp-virtual-mac: enable 119 | 120 | # For unknown reason (most likely API limitation) 121 | # you can not set up VRRP directly from the interface 122 | # module. Use generic module like in example below 123 | 124 | - name: Update vrrp for testint 125 | fortios_api: 126 | endpoint_information: 127 | endpoint: cmdb/system/interface/testint/vrrp 128 | list_identifier: vrrp 129 | object_identifier: vrid 130 | conn_params: "{{ test_fw }}" 131 | vrrp: 132 | - vrid: 1 133 | vrip: 194.0.3.1 134 | priority: 200 135 | 136 | ''' 137 | 138 | RETURN = ''' 139 | proposed: 140 | description: k/v pairs of parameters passed into module and sent to the device for changes 141 | returned: always 142 | type: list 143 | 144 | existing: 145 | description: k/v pairs of existing configuration 146 | returned: always 147 | type: list 148 | 149 | end_state: 150 | description: k/v pairs of configuration after module execution 151 | returned: always 152 | type: list 153 | 154 | changed: 155 | description: check to see if a change was made on the device 156 | returned: always 157 | type: boolean 158 | ''' 159 | 160 | from ansible.module_utils.fortios_api import API 161 | 162 | interface_api_args = { 163 | "endpoint": ["cmdb", "system", "interface"], 164 | "list_identifier": "interfaces", 165 | "object_identifier": "name", 166 | "default_ignore_params": ['macaddr', 'vdom', 'type'] 167 | } 168 | 169 | 170 | def main(): 171 | forti_api = API(interface_api_args) 172 | forti_api.apply_configuration_to_endpoint() 173 | 174 | 175 | if __name__ == "__main__": 176 | main() 177 | -------------------------------------------------------------------------------- /fortios/fortios_api_link_monitor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module for managing Fortigate devices via API 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | ANSIBLE_METADATA = {'metadata_version': '1.0', 11 | 'status': ['preview'], 12 | 'supported_by': 'community'} 13 | 14 | DOCUMENTATION = ''' 15 | --- 16 | module: fortios_api_link_monitor 17 | extends_documentation_fragment: fortios_api_doc 18 | version_added: "2.4" 19 | short_description: Manages Firewall link-monitor configuration. 20 | description: 21 | - Manages Firewall link-monitor configuration. 22 | author: 23 | - Will Wagner (@willwagner602) 24 | Eugene Opredelennov (@eoprede) 25 | notes: 26 | - Tested against Fortigate v5.4.5 VM 27 | 28 | options: 29 | monitor: 30 | description: 31 | - Full list of link-monitors to be configured. 32 | required: true 33 | suboptions: 34 | name: 35 | description: 36 | - Name of the link-monitor 37 | required: true 38 | protocol: 39 | description: 40 | - Protocol for testing 41 | required: true 42 | server: 43 | description: 44 | - List of servers to test 45 | required: true 46 | srcintf: 47 | description: 48 | - Source interface for tests 49 | required: false 50 | 51 | ''' 52 | EXAMPLES = ''' 53 | --- 54 | name: Update link-monitor 55 | fortios_api_link_monitor: 56 | conn_params: 57 | fortigate_username: admin 58 | fortigate_password: test 59 | fortigate_ip: 1.2.3.4 60 | port: 10080 61 | verify: false 62 | secure: false 63 | proxies: 64 | http: socks5://127.0.0.1:9000 65 | monitor: 66 | - name: "google_dns" 67 | protocol: "ping" 68 | server: 69 | - address: 8.8.8.8 70 | srcintf: "port5" 71 | ''' 72 | 73 | RETURN = ''' 74 | proposed: 75 | description: k/v pairs of parameters passed into module and sent to the device for changes 76 | returned: always 77 | type: list 78 | 79 | existing: 80 | description: k/v pairs of existing configuration 81 | returned: always 82 | type: list 83 | 84 | end_state: 85 | description: k/v pairs of configuration after module execution 86 | returned: always 87 | type: list 88 | 89 | changed: 90 | description: check to see if a change was made on the device 91 | returned: always 92 | type: boolean 93 | ''' 94 | 95 | from ansible.module_utils.fortios_api import API 96 | 97 | system_global_api_args = { 98 | 'endpoint': 'cmdb/system/link-monitor', 99 | 'list_identifier': 'monitor', 100 | 'object_identifier': 'name', 101 | 'default_ignore_params': [] 102 | } 103 | 104 | 105 | def main(): 106 | forti_api = API(system_global_api_args) 107 | forti_api.apply_configuration_to_endpoint() 108 | 109 | 110 | if __name__ == "__main__": 111 | main() 112 | -------------------------------------------------------------------------------- /fortios/fortios_api_ntp_server.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module to manage arbitrary objects via API in fortigate devices 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | ANSIBLE_METADATA = {'metadata_version': '1.0', 11 | 'status': ['preview'], 12 | 'supported_by': 'community'} 13 | 14 | DOCUMENTATION = ''' 15 | --- 16 | module: fortios_api_ntp_server 17 | extends_documentation_fragment: fortios_api_doc 18 | version_added: "2.4" 19 | short_description: Manages system ntp servers. 20 | description: 21 | - Manages system ntp servers. 22 | author: 23 | - Will Wagner (@willwagner602) 24 | Eugene Opredelennov (@eoprede) 25 | notes: 26 | - Tested against Fortigate v5.4.5 VM 27 | - Can use all of the parameters supported by Fortigate API 28 | 29 | options: 30 | ntpserver: 31 | description: 32 | - Settings for ntp servers 33 | type: list 34 | required: true 35 | suboptions: 36 | server: 37 | descritpion: 38 | - Server IP or FQDN address 39 | required: true 40 | id: 41 | description: 42 | - ID for the server 43 | required: true 44 | type: int 45 | ''' 46 | EXAMPLES = ''' 47 | --- 48 | name: set system ntp settings 49 | tags: 50 | - ntp 51 | fortios_api_ntp_server: 52 | conn_params: 53 | fortigate_username: admin 54 | fortigate_password: test 55 | fortigate_ip: 1.2.3.4 56 | port: 10080 57 | verify: false 58 | secure: false 59 | proxies: 60 | http: socks5://127.0.0.1:9000 61 | ntpserver: 62 | - authentication: disable 63 | id: 1 64 | server: time.nist.gov 65 | - authentication: disable 66 | id: 2 67 | server: utcnist.colorado.edu 68 | 69 | ''' 70 | 71 | RETURN = ''' 72 | proposed: 73 | description: k/v pairs of parameters passed into module and sent to the device for changes 74 | returned: always 75 | type: list 76 | existing: 77 | description: k/v pairs of existing configuration 78 | returned: always 79 | type: list 80 | end_state: 81 | description: k/v pairs of configuration after module execution 82 | returned: always 83 | type: list 84 | changed: 85 | description: Whether a change was required for the device configuration. 86 | returned: always 87 | type: boolean 88 | msg: 89 | description: A short description of the success of the change and status of the device. 90 | returned: always 91 | type: str 92 | ''' 93 | 94 | from ansible.module_utils.fortios_api import API 95 | 96 | module_args = { 97 | "endpoint": ['cmdb', 'system', 'ntp', 'ntpserver'], 98 | "list_identifier": 'ntpserver', 99 | "object_identifier": "id", 100 | "default_ignore_params": [], 101 | } 102 | 103 | 104 | def main(): 105 | forti_api = API(module_args) 106 | forti_api.apply_configuration_to_endpoint() 107 | 108 | 109 | if __name__ == "__main__": 110 | main() 111 | -------------------------------------------------------------------------------- /fortios/fortios_api_prefix_list.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module for managing Fortigate devices via API 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | ANSIBLE_METADATA = {'metadata_version': '1.0', 11 | 'status': ['preview'], 12 | 'supported_by': 'community'} 13 | 14 | DOCUMENTATION = ''' 15 | --- 16 | module: fortios_api_prefix_list 17 | extends_documentation_fragment: fortios_api_doc 18 | version_added: "2.4" 19 | short_description: Manages router prefix list configuration. 20 | description: 21 | - Manages router prefix list configuration. 22 | author: 23 | - Will Wagner (@willwagner602) 24 | Eugene Opredelennov (@eoprede) 25 | notes: 26 | - Tested against Fortigate v5.4.5 VM 27 | - Can use all of the parameters supported by Fortigate API 28 | 29 | options: 30 | prefixes: 31 | description: 32 | - Full list of prefix lists to be applied to the Firewall. Note that any prefix-list not present in the list will be DELETED. 33 | required: true 34 | suboptions: 35 | name: 36 | description: 37 | - Name of the prefix list 38 | required: true 39 | rule: 40 | description: 41 | - List of rules for the prefix-list 42 | required: true 43 | suboptions: 44 | prefix: 45 | description: 46 | - Prefix in IP netmask format 47 | required: true 48 | ge: 49 | description: 50 | - Greater equal prefix mask length. Broken in 5.4.5 51 | le: 52 | description: 53 | - Lesser equal prefix mask length. Broken in 5.4.5 54 | 55 | ''' 56 | EXAMPLES = ''' 57 | # Note that in 5.4.5 you can't set ge or le with API call. Firewall just sets them to null regardless of what you send 58 | # This has been confirmed by support and I am expecting bug to be fixed in further releases 59 | --- 60 | name: update router prefix-list 61 | tags: 62 | - prefix_list 63 | fortios_api_prefix_list: 64 | conn_params: 65 | fortigate_username: admin 66 | fortigate_password: test 67 | fortigate_ip: 1.2.3.4 68 | port: 10080 69 | verify: false 70 | secure: false 71 | proxies: 72 | http: socks5://127.0.0.1:9000 73 | prefixes: 74 | - name: default_only 75 | rule: 76 | - prefix: 0.0.0.0 0.0.0.0 77 | - name: test_block 78 | rule: 79 | - prefix: 10.254.160.0 255.255.240.0 80 | - prefix: 2.0.0.0 255.0.0.0 81 | 82 | ''' 83 | 84 | RETURN = ''' 85 | proposed: 86 | description: k/v pairs of parameters passed into module 87 | returned: always 88 | type: dict 89 | existing: 90 | description: 91 | - k/v pairs of existing configuration 92 | returned: always 93 | type: dict 94 | end_state: 95 | description: k/v pairs of configuration after module execution 96 | returned: always 97 | type: dict 98 | updates: 99 | description: command sent to the device 100 | returned: always 101 | type: list 102 | changed: 103 | description: check to see if a change was made on the device 104 | returned: always 105 | type: boolean 106 | ''' 107 | 108 | from ansible.module_utils.fortios_api import API 109 | 110 | 111 | prefix_list_api_args = { 112 | 'endpoint': ["cmdb", "router", "prefix-list"], 113 | 'list_identifier': 'prefixes', 114 | 'object_identifier': 'name', 115 | 'default_ignore_params': [], 116 | } 117 | 118 | 119 | def main(): 120 | forti_api = API(prefix_list_api_args) 121 | forti_api.apply_configuration_to_endpoint() 122 | 123 | 124 | if __name__ == "__main__": 125 | main() 126 | -------------------------------------------------------------------------------- /fortios/fortios_api_route_map.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module for managing Fortigate devices via API 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | ANSIBLE_METADATA = {'metadata_version': '1.0', 11 | 'status': ['preview'], 12 | 'supported_by': 'community'} 13 | 14 | DOCUMENTATION = ''' 15 | --- 16 | module: fortios_api_route_map 17 | extends_documentation_fragment: fortios_api_doc 18 | version_added: "2.4" 19 | short_description: Manages router route-map configuration. 20 | description: 21 | - Manages router route-map configuration. 22 | author: 23 | - Will Wagner (@willwagner602) 24 | Eugene Opredelennov (@eoprede) 25 | notes: 26 | - Tested against Fortigate v5.4.5 VM 27 | - Can use all of the parameters supported by Fortigate API 28 | 29 | options: 30 | route-map: 31 | description: 32 | - Full list of route-maps to be applied to the Firewall. Note that any route-maps not present in the list will be DELETED. 33 | required: true 34 | suboptions: 35 | name: 36 | description: 37 | - Name of the route-map list 38 | required: true 39 | rule: 40 | description: 41 | - List of rules for the route-map 42 | required: true 43 | suboptions: 44 | match-ip-address: 45 | description: 46 | - Prefix list to reference for IP address matching 47 | required: true 48 | match-flags: 49 | description: 50 | - Not clear what it is, but is needed when matching something in route-map 51 | set-flags: 52 | description: 53 | - Not clear what it is, but is needed when setting something in route-map 54 | 55 | ''' 56 | EXAMPLES = ''' 57 | # I am not sure what set-flags and match-flags are and they aren't documented well anywhere 58 | # You may have to create a sample rule manually to see which values are assigned and add it to the playbook 59 | --- 60 | name: update router route-map 61 | fortios_api_route_map: 62 | print_current_config: false 63 | conn_params: 64 | fortigate_username: admin 65 | fortigate_password: test 66 | fortigate_ip: 1.2.3.4 67 | port: 10080 68 | verify: false 69 | secure: false 70 | proxies: 71 | http: socks5://127.0.0.1:9000 72 | route-map: 73 | - comments: comment 74 | name: test_default 75 | rule: 76 | - match-flags: 2 77 | match-ip-address: default_only 78 | set-flags: 0 79 | - match-flags: 2 80 | match-ip-address: test_block 81 | set-flags: 2 82 | set-metric: 200 83 | 84 | ''' 85 | 86 | RETURN = ''' 87 | proposed: 88 | description: k/v pairs of parameters passed into module 89 | returned: always 90 | type: dict 91 | existing: 92 | description: 93 | - k/v pairs of existing configuration 94 | returned: always 95 | type: dict 96 | end_state: 97 | description: k/v pairs of configuration after module execution 98 | returned: always 99 | type: dict 100 | updates: 101 | description: command sent to the device 102 | returned: always 103 | type: list 104 | changed: 105 | description: check to see if a change was made on the device 106 | returned: always 107 | type: boolean 108 | ''' 109 | 110 | from ansible.module_utils.fortios_api import API 111 | 112 | 113 | prefix_list_api_args = { 114 | 'endpoint': ["cmdb", "router", "route-map"], 115 | 'list_identifier': 'route-map', 116 | 'object_identifier': 'name', 117 | 'default_ignore_params': [], 118 | } 119 | 120 | 121 | def main(): 122 | forti_api = API(prefix_list_api_args) 123 | forti_api.apply_configuration_to_endpoint() 124 | 125 | 126 | if __name__ == "__main__": 127 | main() 128 | -------------------------------------------------------------------------------- /fortios/fortios_api_router_bgp.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module for managing Fortigate devices via API 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | ANSIBLE_METADATA = {'metadata_version': '1.0', 11 | 'status': ['preview'], 12 | 'supported_by': 'community'} 13 | 14 | DOCUMENTATION = ''' 15 | --- 16 | module: fortios_api_router_bgp 17 | extends_documentation_fragment: fortios_api_doc 18 | version_added: "2.4" 19 | short_description: Manages router BGP configuration. 20 | description: 21 | - Manages router BGP configuration. 22 | author: 23 | - Will Wagner (@willwagner602) 24 | Eugene Opredelennov (@eoprede) 25 | notes: 26 | - Tested against Fortigate v5.4.5 VM 27 | - Can use all of the parameters supported by Fortigate API 28 | 29 | options: 30 | bgp: 31 | description: 32 | - BGP connection parameters, must be a list with 1 object 33 | required: true 34 | suboptions: 35 | as: 36 | description: 37 | - Firewall AS 38 | required: true 39 | router-id: 40 | description: 41 | - Firewall router-id 42 | required: false 43 | default: null 44 | neighbor: 45 | description: 46 | - List of BGP neighbors 47 | required: false 48 | default: null 49 | aggregate-address: 50 | description: 51 | - List of aggregate prefixes 52 | required: false 53 | default: null 54 | network: 55 | description: 56 | - List of network prefixes 57 | required: false 58 | default: null 59 | ''' 60 | EXAMPLES = ''' 61 | # Note that you have to supply the whole redistribute list, even if you need to redistribute just protocol 62 | --- 63 | name: Test BGP 64 | tags: 65 | - bgp 66 | fortios_api_router_bgp: 67 | print_current_config: false 68 | conn_params: 69 | fortigate_username: admin 70 | fortigate_password: test 71 | fortigate_ip: 1.2.3.4 72 | port: 10080 73 | verify: false 74 | secure: false 75 | proxies: 76 | http: socks5://127.0.0.1:9000 77 | bgp: 78 | - as: 65001 79 | router-id: 192.0.5.1 80 | log-neighbour-changes: enable 81 | graceful-restart: enable 82 | neighbor: 83 | - ip: 192.0.5.2 84 | soft-reconfiguration: enable 85 | remote-as: 65002 86 | prefix-list-in: default_only 87 | aggregate-address: 88 | - prefix: 10.254.166.0 255.255.254.0 89 | - prefix: 10.254.164.0 255.255.252.0 90 | network: 91 | - prefix: 10.254.166.0 255.255.255.0 92 | redistribute: 93 | - name: connected 94 | status: enable 95 | - name: rip 96 | status: disable 97 | - name: ospf 98 | status: disable 99 | - name: static 100 | status: disable 101 | - name: isis 102 | status: disable 103 | 104 | ''' 105 | 106 | RETURN = ''' 107 | proposed: 108 | description: k/v pairs of parameters passed into module 109 | returned: always 110 | type: dict 111 | existing: 112 | description: 113 | - k/v pairs of existing configuration 114 | returned: always 115 | type: dict 116 | end_state: 117 | description: k/v pairs of configuration after module execution 118 | returned: always 119 | type: dict 120 | updates: 121 | description: command sent to the device 122 | returned: always 123 | type: list 124 | changed: 125 | description: check to see if a change was made on the device 126 | returned: always 127 | type: boolean 128 | ''' 129 | 130 | from ansible.module_utils.fortios_api import API 131 | 132 | router_bgp_args = { 133 | "endpoint": ["cmdb", "router", "bgp"], 134 | "list_identifier": 'bgp', 135 | "object_identifier": None, 136 | "permanent_objects": [], 137 | "default_ignore_params": [], 138 | } 139 | 140 | 141 | def main(): 142 | forti_api = API(router_bgp_args) 143 | forti_api.apply_configuration_to_endpoint() 144 | 145 | 146 | if __name__ == "__main__": 147 | main() 148 | -------------------------------------------------------------------------------- /fortios/fortios_api_router_ospf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module for managing Fortigate devices via API 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or 6 | # https://www.gnu.org/licenses/gpl-3.0.txt) 7 | 8 | from __future__ import (absolute_import, division, print_function) 9 | __metaclass__ = type 10 | 11 | ANSIBLE_METADATA = {'metadata_version': '1.0', 12 | 'status': ['preview'], 13 | 'supported_by': 'community'} 14 | 15 | DOCUMENTATION = ''' 16 | --- 17 | module: fortios_api_router_ospf 18 | extends_documentation_fragment: fortios_api_doc 19 | version_added: "2.4" 20 | short_description: Manages router BGP configuration. 21 | description: 22 | - Manages router BGP configuration. 23 | author: 24 | - Will Wagner (@willwagner602) 25 | Eugene Opredelennov (@eoprede) 26 | notes: 27 | - Tested against Fortigate v5.4.5 VM 28 | - Can use all of the parameters supported by Fortigate API 29 | 30 | options: 31 | ospf: 32 | description: 33 | - OSPF connection parameters 34 | required: true 35 | suboptions: 36 | default-information-originate: 37 | description: 38 | - Originate default route 39 | required: true 40 | router-id: 41 | description: 42 | - Firewall router-id 43 | required: false 44 | default: null 45 | area: 46 | description: 47 | - List of area IDs 48 | required: false 49 | default: null 50 | network: 51 | description: 52 | - List of network prefixes 53 | required: false 54 | default: null 55 | ''' 56 | EXAMPLES = ''' 57 | --- 58 | name: Test OSPF 59 | tags: 60 | - ospf 61 | fortios_api_router_ospf: 62 | print_current_config: false 63 | conn_params: 64 | fortigate_username: admin 65 | fortigate_password: test 66 | fortigate_ip: 1.2.3.4 67 | port: 10080 68 | verify: false 69 | secure: false 70 | proxies: 71 | http: socks5://127.0.0.1:9000 72 | ospf: 73 | - auto-cost-ref-bandwidth: 100000 74 | default-information-originate: enable 75 | default-information-metric: 150 76 | router-id: 1.2.3.4 77 | area: 78 | - id: 0.0.0.0 79 | network: 80 | - prefix: 192.0.5.0 255.255.255.0 81 | area: 0.0.0.0 82 | ''' 83 | 84 | RETURN = ''' 85 | proposed: 86 | description: k/v pairs of parameters passed into module 87 | returned: always 88 | type: dict 89 | existing: 90 | description: 91 | - k/v pairs of existing configuration 92 | returned: always 93 | type: dict 94 | end_state: 95 | description: k/v pairs of configuration after module execution 96 | returned: always 97 | type: dict 98 | updates: 99 | description: command sent to the device 100 | returned: always 101 | type: list 102 | changed: 103 | description: check to see if a change was made on the device 104 | returned: always 105 | type: boolean 106 | ''' 107 | 108 | from ansible.module_utils.fortios_api import API 109 | 110 | router_bgp_args = { 111 | "endpoint": ["cmdb", "router", "ospf"], 112 | "list_identifier": 'ospf', 113 | "object_identifier": None, 114 | "permanent_objects": [], 115 | "default_ignore_params": [], 116 | } 117 | 118 | 119 | def main(): 120 | forti_api = API(router_bgp_args) 121 | forti_api.apply_configuration_to_endpoint() 122 | 123 | 124 | if __name__ == "__main__": 125 | main() 126 | -------------------------------------------------------------------------------- /fortios/fortios_api_router_ospf_interface.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module for managing Fortigate devices via API 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or 6 | # https://www.gnu.org/licenses/gpl-3.0.txt) 7 | 8 | from __future__ import (absolute_import, division, print_function) 9 | __metaclass__ = type 10 | 11 | ANSIBLE_METADATA = {'metadata_version': '1.0', 12 | 'status': ['preview'], 13 | 'supported_by': 'community'} 14 | 15 | DOCUMENTATION = ''' 16 | --- 17 | module: fortios_api_ospf_interface 18 | extends_documentation_fragment: fortios_api_doc 19 | version_added: "2.4" 20 | short_description: Manages router ospf interface information 21 | description: 22 | - Manages router ospf interface information 23 | author: 24 | - Will Wagner (@willwagner602) 25 | Eugene Opredelennov (@eoprede) 26 | notes: 27 | - Tested against Fortigate v5.4.5 VM 28 | - Can use all of the parameters supported by Fortigate API 29 | 30 | options: 31 | interface: 32 | description: 33 | - OSPF interface parameters, must be a list of interface objects 34 | ''' 35 | EXAMPLES = ''' 36 | # Sample interface 37 | fortios_api_router_ospf_interface: 38 | conn_params: 39 | fortigate_username: admin 40 | fortigate_password: test 41 | fortigate_ip: 1.2.3.4 42 | port: 10080 43 | verify: false 44 | secure: false 45 | proxies: 46 | http: socks5://127.0.0.1:9000 47 | interface: 48 | - name: "test" 49 | interface: "port3" 50 | authentication: md5 51 | md5-key: "1 test" 52 | cost: 100 53 | priority: 200 54 | ''' 55 | 56 | RETURN = ''' 57 | proposed: 58 | description: k/v pairs of parameters passed into module and sent to the device for changes 59 | returned: always 60 | type: list 61 | sample: '[{"authentication": "md5", "cost": 100, "interface": "port3", "md5-key": "1 test", "name": "test", "priority": 200}]' 62 | existing: 63 | description: k/v pairs of existing configuration 64 | returned: always 65 | type: list 66 | sample: '[]' 67 | end_state: 68 | description: k/v pairs of configuration after module execution 69 | returned: always 70 | type: list 71 | sample: '[{"authentication": "md5", "authentication-key": "ENC XXXX", "bfd": "global", "cost": 100, 72 | "database-filter-out": "disable", "dead-interval": 0, "hello-interval": 0, "hello-multiplier": 0, 73 | "interface": "port3", "ip": "0.0.0.0", "md5-key": "1 * ", "mtu": 0, "mtu-ignore": "disable", 74 | "name": "test", "network-type": "broadcast", "prefix-length": 0, "priority": 200, "q_origin_key": "test", 75 | "resync-timeout": 40, "retransmit-interval": 5, "status": "enable", "transmit-delay": 1}]' 76 | changed: 77 | description: Whether a change was required for the device configuration. 78 | returned: always 79 | type: boolean 80 | sample: true 81 | msg: 82 | description: A short description of the success of the change and status of the device. 83 | returned: always 84 | type: str 85 | sample: "Configuration updated." 86 | ''' 87 | 88 | from ansible.module_utils.fortios_api import API 89 | 90 | router_ospf_ospf_interface_args = { 91 | "endpoint": ['cmdb', 'router', 'ospf', 'ospf-interface'], 92 | "list_identifier": 'interface', 93 | "object_identifier": "name", 94 | "permanent_objects": [], 95 | "default_ignore_params": [], 96 | "match_ignore_params": ["md5-key"] 97 | } 98 | 99 | 100 | def main(): 101 | forti_api = API(router_ospf_ospf_interface_args) 102 | forti_api.apply_configuration_to_endpoint() 103 | 104 | 105 | if __name__ == "__main__": 106 | main() 107 | -------------------------------------------------------------------------------- /fortios/fortios_api_snmp_community.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module to manage arbitrary objects via API in fortigate devices 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or 6 | # https://www.gnu.org/licenses/gpl-3.0.txt) 7 | 8 | from __future__ import (absolute_import, division, print_function) 9 | __metaclass__ = type 10 | 11 | ANSIBLE_METADATA = {'metadata_version': '1.0', 12 | 'status': ['preview'], 13 | 'supported_by': 'community'} 14 | 15 | DOCUMENTATION = ''' 16 | --- 17 | module: fortios_api_snmp_community 18 | extends_documentation_fragment: fortios_api_doc 19 | version_added: "2.4" 20 | short_description: Manages firewall SNMP Community parameters 21 | description: 22 | - Manages firewall SNMP Community parameters 23 | author: 24 | - Will Wagner (@willwagner602) 25 | Eugene Opredelennov (@eoprede) 26 | notes: 27 | - Tested against Fortigate v5.4.5 VM 28 | - Can use all of the parameters supported by Fortigate API 29 | 30 | options: 31 | community: 32 | description: 33 | - Set of SNMP Comunity parameters 34 | required: true 35 | type: list 36 | suboptions: 37 | id: 38 | description: 39 | - ID for object 40 | required: true 41 | type: int 42 | events: 43 | description: 44 | - Events to generate SNMP events 45 | required: false 46 | type: str 47 | hosts: 48 | description: 49 | - List of SNMP hosts for SNMP traps and pulls 50 | type: list 51 | required: false 52 | suboptions: 53 | id: 54 | description: 55 | - ID for object 56 | required: true 57 | type: int 58 | ip: 59 | description: 60 | - IP address for the host 61 | required: true 62 | type: str 63 | name: 64 | description: 65 | - SNMP community name 66 | required: true 67 | type: str 68 | 69 | 70 | ''' 71 | EXAMPLES = ''' 72 | --- 73 | name: set system snmp sysinfo 74 | tags: 75 | - snmp 76 | fortios_api_snmp_sysinfo: 77 | conn_params: 78 | fortigate_username: admin 79 | fortigate_password: test 80 | fortigate_ip: 1.2.3.4 81 | port: 10080 82 | verify: false 83 | secure: false 84 | proxies: 85 | http: socks5://127.0.0.1:9000 86 | sysinfo: 87 | - status: enable 88 | 89 | 90 | --- 91 | name: set system snmp sysinfo 92 | tags: 93 | - snmp 94 | fortios_api_snmp_community: 95 | conn_params: 96 | fortigate_username: admin 97 | fortigate_password: test 98 | fortigate_ip: 1.2.3.4 99 | port: 10080 100 | verify: false 101 | secure: false 102 | proxies: 103 | http: socks5://127.0.0.1:9000 104 | community: 105 | - id: 1 106 | events: cpu-high mem-low log-full intf-ip vpn-tun-up vpn-tun-down ha-switch ha-hb-failure 107 | ips-signature ips-anomaly av-virus av-oversize av-pattern av-fragmented fm-if-change 108 | bgp-established bgp-backward-transition ha-member-up ha-member-down ent-conf-change 109 | av-conserve av-bypass av-oversize-passed av-oversize-blocked ips-pkg-update 110 | ips-fail-open faz-disconnect fswctl-session-up fswctl-session-down load-balance-real-server-down 111 | hosts: 112 | - id: 1 113 | ip: 10.0.0.1 255.255.255.255 114 | - id: 2 115 | ip: 10.0.0.2 255.255.255.255 116 | name: public 117 | status: enable 118 | trap-v1-status: enable 119 | trap-v2c-status: enable 120 | 121 | ''' 122 | 123 | RETURN = ''' 124 | proposed: 125 | description: k/v pairs of parameters passed into module 126 | returned: always 127 | type: dict 128 | existing: 129 | description: 130 | - k/v pairs of existing configuration 131 | returned: always 132 | type: dict 133 | end_state: 134 | description: k/v pairs of configuration after module execution 135 | returned: always 136 | type: dict 137 | updates: 138 | description: command sent to the device 139 | returned: always 140 | type: list 141 | changed: 142 | description: check to see if a change was made on the device 143 | returned: always 144 | type: boolean 145 | ''' 146 | 147 | from ansible.module_utils.fortios_api import API 148 | 149 | system_global_api_args = { 150 | 'endpoint': ['cmdb', 'system.snmp', 'community'], 151 | 'list_identifier': 'community', 152 | 'object_identifier': 'id', 153 | 'default_ignore_params': []} 154 | 155 | 156 | def main(): 157 | forti_api = API(system_global_api_args) 158 | forti_api.apply_configuration_to_endpoint() 159 | 160 | 161 | if __name__ == "__main__": 162 | main() 163 | -------------------------------------------------------------------------------- /fortios/fortios_api_snmp_sysinfo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module to manage arbitrary objects via API in fortigate devices 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or 6 | # https://www.gnu.org/licenses/gpl-3.0.txt) 7 | 8 | from __future__ import (absolute_import, division, print_function) 9 | __metaclass__ = type 10 | 11 | ANSIBLE_METADATA = {'metadata_version': '1.0', 12 | 'status': ['preview'], 13 | 'supported_by': 'community'} 14 | 15 | DOCUMENTATION = ''' 16 | --- 17 | module: fortios_api_snmp_sysinfo 18 | extends_documentation_fragment: fortios_api_doc 19 | version_added: "2.4" 20 | short_description: Manages firewall SNMP Sysinfo parameters 21 | description: 22 | - Manages firewall SNMP Sysinfo parameters 23 | author: 24 | - Will Wagner (@willwagner602) 25 | Eugene Opredelennov (@eoprede) 26 | notes: 27 | - Tested against Fortigate v5.4.5 VM 28 | - Can use all of the parameters supported by Fortigate API 29 | 30 | options: 31 | sysinfo: 32 | description: 33 | - Set of SNMP Sysinfo parameters 34 | required: true 35 | type: list 36 | suboptions: 37 | status: 38 | description: 39 | - SNMP Status 40 | required: false 41 | options: ['enable','disable'] 42 | 43 | ''' 44 | EXAMPLES = ''' 45 | --- 46 | name: set system snmp sysinfo 47 | tags: 48 | - snmp 49 | fortios_api_snmp_sysinfo: 50 | conn_params: 51 | fortigate_username: admin 52 | fortigate_password: test 53 | fortigate_ip: 1.2.3.4 54 | port: 10080 55 | verify: false 56 | secure: false 57 | proxies: 58 | http: socks5://127.0.0.1:9000 59 | sysinfo: 60 | - status: enable 61 | 62 | ''' 63 | 64 | RETURN = ''' 65 | proposed: 66 | description: k/v pairs of parameters passed into module 67 | returned: always 68 | type: dict 69 | existing: 70 | description: 71 | - k/v pairs of existing configuration 72 | returned: always 73 | type: dict 74 | end_state: 75 | description: k/v pairs of configuration after module execution 76 | returned: always 77 | type: dict 78 | updates: 79 | description: command sent to the device 80 | returned: always 81 | type: list 82 | changed: 83 | description: check to see if a change was made on the device 84 | returned: always 85 | type: boolean 86 | ''' 87 | 88 | from ansible.module_utils.fortios_api import API 89 | 90 | system_global_api_args = { 91 | 'endpoint': ['cmdb', 'system.snmp', 'sysinfo'], 92 | 'list_identifier': 'sysinfo', 93 | 'object_identifier': '', 94 | 'default_ignore_params': []} 95 | 96 | 97 | def main(): 98 | forti_api = API(system_global_api_args) 99 | forti_api.apply_configuration_to_endpoint() 100 | 101 | 102 | if __name__ == "__main__": 103 | main() 104 | -------------------------------------------------------------------------------- /fortios/fortios_api_syslogd_setting.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module to manage arbitrary objects via API in fortigate devices 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | ANSIBLE_METADATA = {'metadata_version': '1.0', 11 | 'status': ['preview'], 12 | 'supported_by': 'community'} 13 | 14 | DOCUMENTATION = ''' 15 | --- 16 | module: fortios_api_syslogd_setting 17 | extends_documentation_fragment: fortios_api_doc 18 | version_added: "2.4" 19 | short_description: Manages system syslog configuration. 20 | description: 21 | - Manages system syslog configuration. 22 | author: 23 | - Will Wagner (@willwagner602) 24 | Eugene Opredelennov (@eoprede) 25 | notes: 26 | - Tested against Fortigate v5.4.5 VM 27 | - Can use all of the parameters supported by Fortigate API 28 | 29 | options: 30 | setting: 31 | description: 32 | - Settings for syslogd 33 | type: list 34 | required: true 35 | suboptions: 36 | server: 37 | descritpion: 38 | - Server IP address 39 | required: true 40 | status: 41 | description: 42 | - Whether server is enabled or disabled 43 | options: ['enable','disable'] 44 | required: false 45 | ''' 46 | EXAMPLES = ''' 47 | # For some reason Fortigate decided to make each syslogd setting is a different API endpoint. 48 | # If you need more than 1 syslog destination, use generalized fortigate_api module with endpoing cmdb/log.syslogdX/setting 49 | --- 50 | name: set system syslog setting 51 | tags: 52 | - syslog 53 | fortios_api_syslogd_setting: 54 | conn_params: 55 | fortigate_username: admin 56 | fortigate_password: test 57 | fortigate_ip: 1.2.3.4 58 | port: 10080 59 | verify: false 60 | secure: false 61 | proxies: 62 | http: socks5://127.0.0.1:9000 63 | setting: 64 | - server: 10.0.0.1 65 | status: enable 66 | ''' 67 | 68 | RETURN = ''' 69 | proposed: 70 | description: k/v pairs of parameters passed into module and sent to the device for changes 71 | returned: always 72 | type: list 73 | existing: 74 | description: k/v pairs of existing configuration 75 | returned: always 76 | type: list 77 | end_state: 78 | description: k/v pairs of configuration after module execution 79 | returned: always 80 | type: list 81 | changed: 82 | description: Whether a change was required for the device configuration. 83 | returned: always 84 | type: boolean 85 | msg: 86 | description: A short description of the success of the change and status of the device. 87 | returned: always 88 | type: str 89 | ''' 90 | 91 | from ansible.module_utils.fortios_api import API 92 | 93 | api_syslogd_setting_args = { 94 | "endpoint": ['cmdb/log.syslogd/setting'], 95 | "list_identifier": 'setting', 96 | "object_identifier": "", 97 | "default_ignore_params": [], 98 | } 99 | 100 | 101 | def main(): 102 | forti_api = API(api_syslogd_setting_args) 103 | forti_api.apply_configuration_to_endpoint() 104 | 105 | 106 | if __name__ == "__main__": 107 | main() 108 | -------------------------------------------------------------------------------- /fortios/fortios_api_system_admin.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module to manage arbitrary objects via API in fortigate devices 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | ANSIBLE_METADATA = {'metadata_version': '1.0', 11 | 'status': ['preview'], 12 | 'supported_by': 'community'} 13 | 14 | DOCUMENTATION = ''' 15 | --- 16 | module: fortios_api_system_admin 17 | extends_documentation_fragment: fortios_api_doc 18 | version_added: "2.4" 19 | short_description: Manages system administration configuration. 20 | description: 21 | - Manages system administration configuration. 22 | author: 23 | - Will Wagner (@willwagner602) 24 | Eugene Opredelennov (@eoprede) 25 | notes: 26 | - Tested against Fortigate v5.4.5 VM 27 | - Can use all of the parameters supported by Fortigate API 28 | 29 | options: 30 | admins: 31 | description: 32 | - System administrator parameters, must be a list of system admin objects. 33 | type: list 34 | required: true 35 | suboptions: 36 | name: 37 | descritpion: 38 | - User account name 39 | required: true 40 | password: 41 | description: 42 | - Password in unencrypted form 43 | accprofile: 44 | description: 45 | - Profile for this admin 46 | trsuthostX: 47 | description: 48 | - IP ranges that are allowed to connect with this account. It appears that 10 is the limit 49 | ''' 50 | EXAMPLES = ''' 51 | # Note that "admin" entry must be present if you want to keep default admin user, 52 | # otherwise it will get deleted. 53 | --- 54 | - name: Update system admin 55 | ignore_errors: true 56 | fortios_api_system_admin: 57 | conn_params: 58 | fortigate_username: admin 59 | fortigate_password: test 60 | fortigate_ip: 1.2.3.4 61 | port: 10080 62 | verify: false 63 | secure: false 64 | proxies: 65 | http: socks5://127.0.0.1:9000 66 | admins: 67 | - name: test_admin 68 | comments: test_update 69 | password: test1 70 | accprofile: prof_admin 71 | trusthost1: 192.168.0.0 255.255.0.0 72 | - name: admin 73 | comments: manually configured admin 74 | ''' 75 | 76 | RETURN = ''' 77 | proposed: 78 | description: k/v pairs of parameters passed into module and sent to the device for changes 79 | returned: always 80 | type: list 81 | sample: '[{"accprofile": "prof_admin", "comments": "test_update", "name": "test_admin", "password": "test"}, {"name": "admin"}]' 82 | existing: 83 | description: k/v pairs of existing configuration 84 | returned: always 85 | type: list 86 | sample: '[]' 87 | end_state: 88 | description: k/v pairs of configuration after module execution 89 | returned: always 90 | type: list 91 | changed: 92 | description: Whether a change was required for the device configuration. 93 | returned: always 94 | type: boolean 95 | sample: true 96 | msg: 97 | description: A short description of the success of the change and status of the device. 98 | returned: always 99 | type: str 100 | sample: "Configuration updated." 101 | ''' 102 | 103 | from ansible.module_utils.fortios_api import API 104 | 105 | router_ospf_ospf_interface_args = { 106 | "endpoint": ['cmdb', 'system', 'admin'], 107 | "list_identifier": 'admins', 108 | "object_identifier": "name", 109 | "permanent_objects": ["admin"], 110 | "default_ignore_params": [], 111 | "match_ignore_params": ['password'] 112 | } 113 | 114 | 115 | def main(): 116 | forti_api = API(router_ospf_ospf_interface_args) 117 | forti_api.apply_configuration_to_endpoint() 118 | 119 | 120 | if __name__ == "__main__": 121 | main() 122 | -------------------------------------------------------------------------------- /fortios/fortios_api_system_dns.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module to manage arbitrary objects via API in fortigate devices 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | ANSIBLE_METADATA = {'metadata_version': '1.0', 11 | 'status': ['preview'], 12 | 'supported_by': 'community'} 13 | 14 | DOCUMENTATION = ''' 15 | --- 16 | module: fortios_api_system_dns 17 | extends_documentation_fragment: fortios_api_doc 18 | version_added: "2.4" 19 | short_description: Manages firewall system DNS parameters 20 | description: 21 | - Manages firewall system DNS parameters 22 | author: 23 | - Will Wagner (@willwagner602) 24 | Eugene Opredelennov (@eoprede) 25 | notes: 26 | - Tested against Fortigate v5.4.5 VM 27 | - Can use all of the parameters supported by Fortigate API 28 | 29 | options: 30 | dns: 31 | description: 32 | - Set of DNS parameters 33 | required: true 34 | type: list 35 | suboptions: 36 | primary: 37 | description: 38 | - Primary DNS 39 | required: false 40 | secondary: 41 | description: 42 | - Secondary DNS 43 | required: false 44 | source-ip: 45 | description: 46 | - Source IP for DNS requests 47 | required: false 48 | 49 | ''' 50 | EXAMPLES = ''' 51 | --- 52 | name: set system dns 53 | fortios_api_system_dns: 54 | conn_params: 55 | fortigate_username: admin 56 | fortigate_password: test 57 | fortigate_ip: 1.2.3.4 58 | port: 10080 59 | verify: false 60 | secure: false 61 | proxies: 62 | http: socks5://127.0.0.1:9000 63 | dns: 64 | - primary: 8.8.8.8 65 | secondary: 8.8.4.4 66 | source-ip: 192.0.2.5 67 | 68 | ''' 69 | 70 | RETURN = ''' 71 | proposed: 72 | description: k/v pairs of parameters passed into module 73 | returned: always 74 | type: dict 75 | existing: 76 | description: 77 | - k/v pairs of existing configuration 78 | returned: always 79 | type: dict 80 | end_state: 81 | description: k/v pairs of configuration after module execution 82 | returned: always 83 | type: dict 84 | updates: 85 | description: command sent to the device 86 | returned: always 87 | type: list 88 | changed: 89 | description: check to see if a change was made on the device 90 | returned: always 91 | type: boolean 92 | ''' 93 | 94 | from ansible.module_utils.fortios_api import API 95 | 96 | system_global_api_args = { 97 | 'endpoint': ["cmdb", "system", "dns"], 98 | 'list_identifier': 'dns', 99 | 'object_identifier': '', 100 | 'default_ignore_params': []} 101 | 102 | 103 | def main(): 104 | forti_api = API(system_global_api_args) 105 | forti_api.apply_configuration_to_endpoint() 106 | 107 | 108 | if __name__ == "__main__": 109 | main() 110 | -------------------------------------------------------------------------------- /fortios/fortios_api_system_global.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module to manage arbitrary objects via API in fortigate devices 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | ANSIBLE_METADATA = {'metadata_version': '1.0', 11 | 'status': ['preview'], 12 | 'supported_by': 'community'} 13 | 14 | DOCUMENTATION = ''' 15 | --- 16 | module: fortios_api_system_global 17 | extends_documentation_fragment: fortios_api_doc 18 | version_added: "2.4" 19 | short_description: Manages firewall system global parameters 20 | description: 21 | - Manages firewall system global parameters 22 | author: 23 | - Will Wagner (@willwagner602) 24 | Eugene Opredelennov (@eoprede) 25 | notes: 26 | - Tested against Fortigate v5.4.5 VM 27 | - Can use all of the parameters supported by Fortigate API 28 | 29 | options: 30 | global: 31 | description: 32 | - Set of global parameters 33 | required: true 34 | type: dict 35 | suboptions: 36 | hostname: 37 | description: 38 | - Hostname settings for the firewall 39 | required: false 40 | admintimeout: 41 | description: 42 | - Timeout for admin session 43 | required: false 44 | ''' 45 | EXAMPLES = ''' 46 | --- 47 | name: set system global setup 48 | tags: 49 | - hostname 50 | fortios_api_system_global: 51 | print_current_config: false 52 | conn_params: 53 | fortigate_username: admin 54 | fortigate_password: test 55 | fortigate_ip: 1.2.3.4 56 | port: 10080 57 | verify: false 58 | secure: false 59 | proxies: 60 | http: socks5://127.0.0.1:9000 61 | global: 62 | - admintimeout: 10 63 | hostname: FW-test 64 | timezone: '80' 65 | 66 | ''' 67 | 68 | RETURN = ''' 69 | proposed: 70 | description: k/v pairs of parameters passed into module 71 | returned: always 72 | type: dict 73 | existing: 74 | description: 75 | - k/v pairs of existing configuration 76 | returned: always 77 | type: dict 78 | end_state: 79 | description: k/v pairs of configuration after module execution 80 | returned: always 81 | type: dict 82 | updates: 83 | description: command sent to the device 84 | returned: always 85 | type: list 86 | changed: 87 | description: check to see if a change was made on the device 88 | returned: always 89 | type: boolean 90 | ''' 91 | 92 | from ansible.module_utils.fortios_api import API 93 | 94 | system_global_api_args = { 95 | 'endpoint': ["cmdb", "system", "global"], 96 | 'list_identifier': 'global', 97 | 'object_identifier': '', 98 | 'default_ignore_params': [], 99 | } 100 | 101 | 102 | def main(): 103 | forti_api = API(system_global_api_args) 104 | forti_api.apply_configuration_to_endpoint() 105 | 106 | 107 | if __name__ == "__main__": 108 | main() 109 | -------------------------------------------------------------------------------- /fortios/fortios_api_system_ha.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module to manage arbitrary objects via API in fortigate devices 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or 6 | # https://www.gnu.org/licenses/gpl-3.0.txt) 7 | 8 | from __future__ import (absolute_import, division, print_function) 9 | __metaclass__ = type 10 | 11 | ANSIBLE_METADATA = {'metadata_version': '1.0', 12 | 'status': ['preview'], 13 | 'supported_by': 'community'} 14 | 15 | DOCUMENTATION = ''' 16 | --- 17 | module: fortios_api_system_ha 18 | extends_documentation_fragment: fortios_api_doc 19 | version_added: "2.4" 20 | short_description: Manages firewall ha parameters. 21 | description: 22 | - Manages firewall ha parameters 23 | author: 24 | - Will Wagner (@willwagner602) 25 | Eugene Opredelennov (@eoprede) 26 | notes: 27 | - Tested against Fortigate v5.4.5 VM 28 | - Can use all of the parameters supported by Fortigate API 29 | 30 | options: 31 | ha: 32 | description: 33 | - Set of ha parameters 34 | required: true 35 | type: list 36 | suboptions: 37 | mode: 38 | description: 39 | - Mode of operation 40 | options: ['standalone','a-a','a-p'] 41 | required: false 42 | ''' 43 | EXAMPLES = ''' 44 | # Please note that my test VM hangs once I apply HA config (be it via API or CLI) 45 | # This module SHOULD work, but it hasn't been properly tested 46 | --- 47 | name: set system ha setup 48 | fortios_api_system_ha: 49 | conn_params: 50 | fortigate_username: admin 51 | fortigate_password: test 52 | fortigate_ip: 1.2.3.4 53 | port: 10080 54 | verify: false 55 | secure: false 56 | proxies: 57 | http: socks5://127.0.0.1:9000 58 | ha: 59 | - group-name: testha 60 | hbdev: '"port10" 1 ' 61 | mode: standalone 62 | priority: 200 63 | 64 | ''' 65 | 66 | RETURN = ''' 67 | proposed: 68 | description: k/v pairs of parameters passed into module 69 | returned: always 70 | type: dict 71 | existing: 72 | description: 73 | - k/v pairs of existing configuration 74 | returned: always 75 | type: dict 76 | end_state: 77 | description: k/v pairs of configuration after module execution 78 | returned: always 79 | type: dict 80 | updates: 81 | description: command sent to the device 82 | returned: always 83 | type: list 84 | changed: 85 | description: check to see if a change was made on the device 86 | returned: always 87 | type: boolean 88 | ''' 89 | 90 | from ansible.module_utils.fortios_api import API 91 | 92 | system_global_api_args = { 93 | 'endpoint': ["cmdb", "system", "ha"], 94 | 'list_identifier': 'ha', 95 | 'object_identifier': '', 96 | 'default_ignore_params': [], 97 | "match_ignore_params": ['password', 'key'] 98 | } 99 | 100 | 101 | def main(): 102 | forti_api = API(system_global_api_args) 103 | forti_api.apply_configuration_to_endpoint() 104 | 105 | 106 | if __name__ == "__main__": 107 | main() 108 | -------------------------------------------------------------------------------- /fortios/fortios_api_system_ntp.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module to manage arbitrary objects via API in fortigate devices 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | ANSIBLE_METADATA = {'metadata_version': '1.0', 11 | 'status': ['preview'], 12 | 'supported_by': 'community'} 13 | 14 | DOCUMENTATION = ''' 15 | --- 16 | module: fortios_api_system_ntp 17 | extends_documentation_fragment: fortios_api_doc 18 | version_added: "2.4" 19 | short_description: Manages system ntp configuration. 20 | description: 21 | - Manages system syslog configuration. 22 | author: 23 | - Will Wagner (@willwagner602) 24 | Eugene Opredelennov (@eoprede) 25 | notes: 26 | - Tested against Fortigate v5.4.5 VM 27 | - Can use all of the parameters supported by Fortigate API 28 | 29 | options: 30 | ntp: 31 | description: Settings for ntp 32 | type: dict 33 | required: true 34 | suboptions: 35 | type: 36 | descritpion: Type of NTP servers 37 | required: true 38 | options: ['fortiguard','custom'] 39 | 40 | ''' 41 | EXAMPLES = ''' 42 | # Note that if you are using custom NTP servers 43 | # you have to set them up first with fortios_api_ntp_server 44 | --- 45 | name: set system ntp settings 46 | fortios_api_system_ntp: 47 | conn_params: 48 | fortigate_username: admin 49 | fortigate_password: test 50 | fortigate_ip: 1.2.3.4 51 | port: 10080 52 | verify: false 53 | secure: false 54 | proxies: 55 | http: socks5://127.0.0.1:9000 56 | ntp: 57 | - type: custom 58 | 59 | ''' 60 | 61 | RETURN = ''' 62 | proposed: 63 | description: k/v pairs of parameters passed into module and sent to the device for changes 64 | returned: always 65 | type: list 66 | existing: 67 | description: k/v pairs of existing configuration 68 | returned: always 69 | type: list 70 | end_state: 71 | description: k/v pairs of configuration after module execution 72 | returned: always 73 | type: list 74 | changed: 75 | description: Whether a change was required for the device configuration. 76 | returned: always 77 | type: boolean 78 | msg: 79 | description: A short description of the success of the change and status of the device. 80 | returned: always 81 | type: str 82 | ''' 83 | 84 | from ansible.module_utils.fortios_api import API 85 | 86 | module_args = { 87 | "endpoint": ['cmdb', 'system', 'ntp'], 88 | "list_identifier": 'ntp', 89 | "object_identifier": "", 90 | "default_ignore_params": [], 91 | } 92 | 93 | 94 | def main(): 95 | forti_api = API(module_args) 96 | forti_api.apply_configuration_to_endpoint() 97 | 98 | 99 | if __name__ == "__main__": 100 | main() 101 | -------------------------------------------------------------------------------- /fortios/fortios_api_system_vdom.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Ansible module for managing Fortigate devices via API 4 | # (c) 2017, Will Wagner and Eugene Opredelennov 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | ANSIBLE_METADATA = {'metadata_version': '1.0', 11 | 'status': ['preview'], 12 | 'supported_by': 'community'} 13 | 14 | DOCUMENTATION = ''' 15 | --- 16 | module: fortios_api_system_vdom 17 | extends_documentation_fragment: fortios_api_doc 18 | version_added: "2.4" 19 | short_description: Manages Firewall vdom configuration. 20 | description: 21 | - Manages Firewall vdom configuration. 22 | author: 23 | - Will Wagner (@willwagner602) 24 | Eugene Opredelennov (@eoprede) 25 | notes: 26 | - Tested against Fortigate v5.4.5 VM 27 | 28 | options: 29 | vdoms: 30 | description: 31 | - Full list of vdoms to be configured. 32 | required: true 33 | suboptions: 34 | name: 35 | description: 36 | - Name of the vdom 37 | required: true 38 | 39 | ''' 40 | EXAMPLES = ''' 41 | #Due to limitatons of the Fortigate VM, this module was not fully tested. 42 | --- 43 | name: Update link-monitor 44 | fortios_api_link_monitor: 45 | conn_params: 46 | fortigate_username: admin 47 | fortigate_password: test 48 | fortigate_ip: 1.2.3.4 49 | port: 10080 50 | verify: false 51 | secure: false 52 | proxies: 53 | http: socks5://127.0.0.1:9000 54 | vdoms: 55 | - name: "root" 56 | ''' 57 | 58 | RETURN = ''' 59 | proposed: 60 | description: k/v pairs of parameters passed into module and sent to the device for changes 61 | returned: always 62 | type: list 63 | 64 | existing: 65 | description: k/v pairs of existing configuration 66 | returned: always 67 | type: list 68 | 69 | end_state: 70 | description: k/v pairs of configuration after module execution 71 | returned: always 72 | type: list 73 | 74 | changed: 75 | description: check to see if a change was made on the device 76 | returned: always 77 | type: boolean 78 | ''' 79 | 80 | from ansible.module_utils.fortios_api import API 81 | 82 | system_global_api_args = { 83 | 'endpoint': 'cmdb/system/vdom', 84 | 'list_identifier': 'vdoms', 85 | 'object_identifier': 'name', 86 | 'default_ignore_params': [] 87 | } 88 | 89 | 90 | def main(): 91 | forti_api = API(system_global_api_args) 92 | forti_api.apply_configuration_to_endpoint() 93 | 94 | 95 | if __name__ == "__main__": 96 | main() 97 | --------------------------------------------------------------------------------