diff --git a/.github/workflows/tests_role_ravendb_node.yml b/.github/workflows/tests_role_ravendb_node.yml
index 756a00a..cd02945 100644
--- a/.github/workflows/tests_role_ravendb_node.yml
+++ b/.github/workflows/tests_role_ravendb_node.yml
@@ -1,12 +1,72 @@
-name: ravendb_node role tests
+name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
+ schedule:
+ - cron: "0 10 * * 1" # every Monday at 10:00 UTC
jobs:
+ sanity:
+ name: Ansible Sanity Tests
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ include:
+ - python-version: "3.9"
+ ansible-core: stable-2.15
+ - python-version: "3.10"
+ ansible-core: stable-2.15
+ - python-version: "3.11"
+ ansible-core: stable-2.15
+
+ - python-version: "3.10"
+ ansible-core: stable-2.16
+ - python-version: "3.11"
+ ansible-core: stable-2.16
+ - python-version: "3.12"
+ ansible-core: stable-2.16
+
+ - python-version: "3.10"
+ ansible-core: stable-2.17
+ - python-version: "3.11"
+ ansible-core: stable-2.17
+ - python-version: "3.12"
+ ansible-core: stable-2.17
+
+ - python-version: "3.11"
+ ansible-core: devel
+ - python-version: "3.12"
+ ansible-core: devel
+ - python-version: "3.13"
+ ansible-core: devel
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: Fix collection path for ansible-test #should be removed once we restructre
+ run: |
+ mkdir -p ansible_collections/ravendb/ravendb
+ rsync -av --exclude ansible_collections ./ ansible_collections/ravendb/ravendb
+ cd ansible_collections/ravendb/ravendb
+
+ - name: Set up Python ${{ matrix.python-version }}
+ uses: actions/setup-python@v5
+ with:
+ python-version: ${{ matrix.python-version }}
+
+ - name: Install dependencies
+ run: |
+ python -m pip install --upgrade pip
+ pip install "ansible-core@https://github.com/ansible/ansible/archive/${{ matrix.ansible-core }}.tar.gz"
+
+ - name: Run ansible-test sanity
+ working-directory: ansible_collections/ravendb/ravendb
+ run: |
+ ansible-test sanity --python ${{ matrix.python-version }} --docker -v --color
+
test-debian-setup-scenarios:
runs-on: ubuntu-latest
steps:
@@ -118,7 +178,7 @@ jobs:
- name: Build ansible galaxy collection
run: |
ansible-galaxy collection build .
- ansible-galaxy collection install ./ravendb-community-*.tar.gz --force -p ./
+ ansible-galaxy collection install ./ravendb-ravendb-*.tar.gz --force -p ./
- name: Set up .NET environment variables
run: |
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..83931b7
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,18 @@
+# Changelog
+
+All notable changes to this project will be documented in this file.
+
+This project follows the [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) principles and the [Ansible collection changelog format](https://docs.ansible.com/ansible/latest/dev_guide/collections_changelogs.html).
+
+The full changelog is maintained in [changelogs/changelog.yml](./changelogs/changelog.yml).
+
+## [1.0.0] - Initial Release
+
+### Added
+- Initial release of the `ravendb.ravendb` Ansible Collection.
+- Added `ravendb_node` role for setting up RavenDB servers.
+- Added `ravendb_python_client_prerequisites` role for managing Python dependencies.
+- Added modules:
+ - `ravendb.ravendb.database` for managing RavenDB databases.
+ - `ravendb.ravendb.index` for managing RavenDB indexes and index modes.
+ - `ravendb.ravendb.node` for adding nodes to a RavenDB cluster.
\ No newline at end of file
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
new file mode 100644
index 0000000..2864762
--- /dev/null
+++ b/CODE_OF_CONDUCT.md
@@ -0,0 +1,3 @@
+# Community Code of Conduct
+
+Please see the official [Ansible Community Code of Conduct](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html).
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..e72bfdd
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ Copyright (C)
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+.
\ No newline at end of file
diff --git a/README.md b/README.md
index 5daae4c..210bd99 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,122 @@
-# Ansible Collection - gregolsky.ravendb
+# RavenDB Community Collection
-Documentation for the collection.
-# ansible-collection-ravendb
+[](https://docs.ansible.com/ansible/devel/collections/ravendb/ravendb/)
+
+This repo contains the `ravendb.ravendb` Ansible Collection. The collection includes many modules and plugins to work with RavenDB.
+The modules present in Ansible 2.15.
+If you like this collection please give us a rating on [Ansible Galaxy](https://galaxy.ansible.com/ravendb/ravendb).
+
+## Code of Conduct
+
+We follow [Ansible Code of Conduct](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html) in all our interactions within this project.
+
+If you encounter abusive behavior violating the [Ansible Code of Conduct](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html), please refer to the [policy violations](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html#policy-violations) section of the Code of Conduct for information on how to raise a complaint.
+
+## Communication
+
+* Join the Ansible forum:
+ * [Get Help](https://forum.ansible.com/c/help/6): get help or help others. Please add appropriate tags if you start new discussions, for example the `ravendb` tag.
+ * [Social Spaces](https://forum.ansible.com/c/chat/4): gather and interact with fellow enthusiasts.
+ * [News & Announcements](https://forum.ansible.com/c/news/5): track project-wide announcements including social events.
+
+* The Ansible [Bullhorn newsletter](https://docs.ansible.com/ansible/devel/community/communication.html#the-bullhorn): used to announce releases and important changes.
+
+For more information about communication, see the [Ansible communication guide](https://docs.ansible.com/ansible/devel/community/communication.html).
+
+## Tested with Ansible
+
+Tested with the current ansible-core 2.15, ansible-core 2.16, ansible-core 2.17, and ansible-core 2.18 releases, and the current development version of ansible-core. Ansible/ansible-base versions before 2.15.0 are not supported.
+
+## Requirements
+
+- This collection is tested against the most recent two RavenDB releases, currently 6.2.X and 7.0.X.
+- [ravendb-python-client](https://pypi.org/project/ravendb/) - latest version supported only. Please upgrade your ravendb-python-client driver version if you encounter difficulties.
+- [requests](https://pypi.org/project/requests/);
+
+All modules and plugins require Python 3.9 or later.
+
+## Using this collection
+
+Before using the RavenDB community collection, you need to install the collection with the `ansible-galaxy` CLI:
+
+ ansible-galaxy collection install ravendb.ravendb
+
+See [Ansible Using collections](https://docs.ansible.com/ansible/latest/user_guide/collections_using.html) for more details.
+
+
+## Usage Examples
+
+Examples for each module and feature included in this collection can be found in the playbooks/ directory.
+
+
+## Collection contents
+
+### Roles
+
+These roles prepare servers with Debian-based and RHEL-based distributions to run RavenDB.
+
+- `ravendb.ravendb.ravendb_node`: Installs and configures a RavenDB server node. Handles service setup, secure and unsecured deployments, certificate management, and prerequisites installation.
+- `ravendb.ravendb_python_client_prerequisites`: Installs the required Python packages (such as the RavenDB Python client library) needed to run Ansible modules that interact with RavenDB clusters.
+
+### Plugins
+
+#### Modules
+
+These modules manage RavenDB clusters, databases, and indexes:
+
+- `ravendb.ravendb.database`: Creates or deletes RavenDB databases, including support for secured and unsecured servers, replication factor settings, and certificate authentication.
+- `ravendb.ravendb.index`: Creates, updates, or deletes RavenDB indexes, including support for multi-map indexes and managing index modes (enable, disable, pause, resume, reset).
+- `ravendb.ravendb.node`: Adds nodes to an existing RavenDB cluster, supporting both regular members and watcher nodes.
+
+
+## ravendb.ravendb Role Tags
+
+### General role tags
+
+These tags are used across roles for categorizing tasks:
+
+| Tag | Description |
+|-------------------|-----------------------------------------------------------------------------|
+| `ravendb` | Tasks specific to managing RavenDB. |
+| `debian` | Tasks targeting Debian-based systems. |
+| `redhat` | Tasks targeting RedHat-based systems. |
+| `pkg` | Package installation tasks (e.g., `apt`, `yum`). |
+| `binaries` | Handling RavenDB binaries and unpacking operations. |
+| `config` | Configuration tasks including system settings and `settings.json`. |
+| `service_mgmt` | Service-related operations (e.g., start, stop, restart). |
+| `user` | Creating and managing `ravendb` user and group. |
+| `download` | Tasks involving downloading resources like `.deb` or `.tar.bz2` files. |
+| `self_signed` | Tasks specific to setting up self-signed certificates. |
+| `secured` | Tasks for Let's Encrypt/secured RavenDB setup. |
+| `ravendb_settings`| Overrides and manipulations on RavenDB configuration files. |
+
+### CI-related tags
+
+| Tag | Description |
+|------------|----------------------------------------------------------------------|
+| `molecule` | Used to mark tasks that are conditional when running Molecule tests. |
+
+
+## Release notes
+
+Please refer to CHANGELOG.md of this repository.
+
+
+## Running the integration and unit tests
+TODO
+
+## More information
+
+- [Ansible Collection overview](https://github.com/ansible-collections/overview)
+- [Ansible User guide](https://docs.ansible.com/ansible/latest/user_guide/index.html)
+- [Ansible Developer guide](https://docs.ansible.com/ansible/latest/dev_guide/index.html)
+- [Ansible Collections Checklist](https://github.com/ansible-collections/overview/blob/master/collection_requirements.rst)
+- [Ansible Community code of conduct](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html)
+- [The Bullhorn (the Ansible Contributor newsletter)](https://us19.campaign-archive.com/home/?u=56d874e027110e35dea0e03c1&id=d6635f5420)
+- [Changes impacting Contributors](https://github.com/ansible-collections/overview/issues/45)
+
+
+## Licensing
+
+This collection is licensed under the [GNU General Public License v3.0 or later (GPL-3.0-or-later)](https://www.gnu.org/licenses/gpl-3.0.html).
+See the LICENSE file of this repository for full details.
\ No newline at end of file
diff --git a/changelogs/changelog.yml b/changelogs/changelog.yml
new file mode 100644
index 0000000..995f8fa
--- /dev/null
+++ b/changelogs/changelog.yml
@@ -0,0 +1,13 @@
+releases:
+ - name: "Initial Release"
+ tag: "v1.0.0"
+ version: "1.0.0"
+ changes:
+ - major_changes:
+ - Initial release of the `ravendb.ravendb` collection.
+ - Added `ravendb_node` role for setting up RavenDB servers.
+ - Added `ravendb_python_client_prerequisites` role for Python dependency management.
+ - Added modules:
+ - "`ravendb.ravendb.database` to manage RavenDB databases."
+ - "`ravendb.ravendb.index` to manage RavenDB indexes and index modes."
+ - "`ravendb.ravendb.node` to add nodes to a RavenDB cluster."
\ No newline at end of file
diff --git a/galaxy.yml b/galaxy.yml
index 49aa865..76b6db8 100644
--- a/galaxy.yml
+++ b/galaxy.yml
@@ -1,63 +1,27 @@
-### REQUIRED
-# The namespace of the collection. This can be a company/brand/organization or product namespace under which all
-# content lives. May only contain alphanumeric lowercase characters and underscores. Namespaces cannot start with
-# underscores or numbers and cannot contain consecutive underscores
namespace: ravendb
-
-# The name of the collection. Has the same character restrictions as 'namespace'
-name: community
-
-# The version of the collection. Must be compatible with semantic versioning
+name: ravendb
version: 1.0.0
-
-# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
-
-# A list of the collection's content authors. Can be just the name or in the format 'Full Name (url)
-# @nicks:irc/im.site#channel'
authors:
-- Grzegorz Lachowski
-- Omer Ratsaby
-
-
-### OPTIONAL but strongly recommended
-# A short summary description of the collection
-description: your collection description
-
-# Either a single license or a list of licenses for content inside of a collection. Ansible Galaxy currently only
-# accepts L(SPDX,https://spdx.org/licenses/) licenses. This key is mutually exclusive with 'license_file'
+- Grzegorz Lachowski
+- Omer Ratsaby
+description: An Ansible collection for deploying, configuring, and managing RavenDB clusters on Linux-based environments.
license:
-- GPL-2.0-or-later
-
-# The path to the license file for the collection. This path is relative to the root of the collection. This key is
-# mutually exclusive with 'license'
+- GPL-3.0-or-later
license_file: ''
-
-# A list of tags you want to associate with the collection for indexing/searching. A tag name has the same character
-# requirements as 'namespace' and 'name'
-tags: []
-
-# Collections that this collection requires to be installed for it to be usable. The key of the dict is the
-# collection label 'namespace.name'. The value is a version range
-# L(specifiers,https://python-semanticversion.readthedocs.io/en/latest/#requirement-specification). Multiple version
-# range specifiers can be set and are separated by ','
+tags:
+ - ravendb
+ - database
+ - cluster
+ - nosql
+ - devops
+ - automation
+ - ansible
+ - ubuntu
+ - rhel
dependencies: {}
-
-# The URL of the originating SCM repository
repository: http://example.com/repository
-
-# The URL to any online docs
documentation: http://docs.example.com
-
-# The URL to the homepage of the collection/project
homepage: http://example.com
-
-# The URL to the collection issue tracker
-issues: http://example.com/issue/tracker
-
-# A list of file glob-like patterns used to filter any files or directories that should not be included in the build
-# artifact. A pattern is matched from the relative path of the file or directory of the collection directory. This
-# uses 'fnmatch' to match the files or directories. Some directories and files like 'galaxy.yml', '*.pyc', '*.retry',
-# and '.git' are always filtered
-build_ignore: []
-
+issues: https://issues.hibernatingrhinos.com
+build_ignore: []
\ No newline at end of file
diff --git a/meta/runtime.yml b/meta/runtime.yml
index 2d9ceca..aa31034 100644
--- a/meta/runtime.yml
+++ b/meta/runtime.yml
@@ -1,4 +1 @@
-requires_ansible: '>=2.10'
-
-dependencies:
- - name: ravendb.community.ravendb_python_client_prerequisites
+requires_ansible: '>=2.15.0'
diff --git a/playbooks/databases/ravendb_create_database.yml b/playbooks/databases/ravendb_create_database.yml
index 166d1e0..4b78d82 100644
--- a/playbooks/databases/ravendb_create_database.yml
+++ b/playbooks/databases/ravendb_create_database.yml
@@ -4,11 +4,11 @@
gather_facts: no
roles:
- - ravendb.community.ravendb_python_client_prerequisites
+ - ravendb.ravendb.ravendb_python_client_prerequisites
tasks:
- name: Ensure RavenDB database is present (check mode)
- ravendb.community.database:
+ ravendb.ravendb.database:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
replication_factor: 3
@@ -16,16 +16,15 @@
check_mode: yes
- name: Ensure RavenDB database is present
- ravendb.community.database:
+ ravendb.ravendb.database:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
replication_factor: 3
state: present
- name: Ensure RavenDB database is present (idempotency check)
- ravendb.community.database:
+ ravendb.ravendb.database:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
replication_factor: 3
state: present
-
diff --git a/playbooks/databases/ravendb_create_database_secured_self_signed.yml b/playbooks/databases/ravendb_create_database_secured_self_signed.yml
index 5963c4d..1bfa3ed 100644
--- a/playbooks/databases/ravendb_create_database_secured_self_signed.yml
+++ b/playbooks/databases/ravendb_create_database_secured_self_signed.yml
@@ -4,12 +4,12 @@
gather_facts: no
roles:
- - ravendb.community.ravendb_python_client_prerequisites
+ - ravendb.ravendb.ravendb_python_client_prerequisites
tasks:
- name: Ensure RavenDB database is present with secure connection (check mode)
become: true
- ravendb.community.database:
+ ravendb.ravendb.database:
url: "http://{{ ansible_host }}:443"
database_name: "my_secured_database"
replication_factor: 1
@@ -20,7 +20,7 @@
- name: Ensure RavenDB database is present with secure connection
become: true
- ravendb.community.database:
+ ravendb.ravendb.database:
url: "http://{{ ansible_host }}:443"
database_name: "my_secured_database"
replication_factor: 1
@@ -30,7 +30,7 @@
- name: Ensure RavenDB database is present with secure connection (idempotency check)
become: true
- ravendb.community.database:
+ ravendb.ravendb.database:
url: "http://{{ ansible_host }}:443"
database_name: "my_secured_database"
replication_factor: 1
diff --git a/playbooks/databases/ravendb_delete_database.yml b/playbooks/databases/ravendb_delete_database.yml
index ab9c694..1438387 100644
--- a/playbooks/databases/ravendb_delete_database.yml
+++ b/playbooks/databases/ravendb_delete_database.yml
@@ -4,26 +4,24 @@
gather_facts: no
roles:
- - ravendb.community.ravendb_python_client_prerequisites
+ - ravendb.ravendb.ravendb_python_client_prerequisites
tasks:
- name: Ensure RavenDB database is absent (check mode)
- ravendb.community.database:
+ ravendb.ravendb.database:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
state: absent
check_mode: yes
- name: Ensure RavenDB database is absent
- ravendb.community.database:
+ ravendb.ravendb.database:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
state: absent
- name: Ensure RavenDB database is absent (idempotency check)
- ravendb.community.database:
+ ravendb.ravendb.database:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
- state: absent
-
-
+ state: absent
\ No newline at end of file
diff --git a/playbooks/databases/ravendb_delete_database_secured_self_signed.yml b/playbooks/databases/ravendb_delete_database_secured_self_signed.yml
index 5cc4823..cace65a 100644
--- a/playbooks/databases/ravendb_delete_database_secured_self_signed.yml
+++ b/playbooks/databases/ravendb_delete_database_secured_self_signed.yml
@@ -4,12 +4,12 @@
gather_facts: no
roles:
- - ravendb.community.ravendb_python_client_prerequisites
+ - ravendb.ravendb.ravendb_python_client_prerequisites
tasks:
- name: Ensure RavenDB database is absent with secure connection (check mode)
become: true
- ravendb.community.database:
+ ravendb.ravendb.database:
url: "http://{{ ansible_host }}:443"
database_name: "my_secured_database"
replication_factor: 1
@@ -20,7 +20,7 @@
- name: Ensure RavenDB database is absent with secure connection
become: true
- ravendb.community.database:
+ ravendb.ravendb.database:
url: "http://{{ ansible_host }}:443"
database_name: "my_secured_database"
replication_factor: 1
@@ -30,7 +30,7 @@
- name: Ensure RavenDB database is absent with secure connection (idempotency check)
become: true
- ravendb.community.database:
+ ravendb.ravendb.database:
url: "http://{{ ansible_host }}:443"
database_name: "my_secured_database"
replication_factor: 1
diff --git a/playbooks/indexes/ravendb_create_index.yml b/playbooks/indexes/ravendb_create_index.yml
index 6a8fec9..a5a633d 100644
--- a/playbooks/indexes/ravendb_create_index.yml
+++ b/playbooks/indexes/ravendb_create_index.yml
@@ -7,11 +7,11 @@
ravendb_venv_path: "/opt/ravendb_venv" # override default venv path
roles:
- - ravendb.community.ravendb_python_client_prerequisites
+ - ravendb.ravendb.ravendb_python_client_prerequisites
tasks:
- name: Ensure RavenDB Index is present (check mode)
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "UsersByName"
@@ -31,7 +31,7 @@
check_mode: yes
- name: Ensure RavenDB Index is present
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "UsersByName"
@@ -50,7 +50,7 @@
state: present
- name: Ensure RavenDB Index is present (idempotency check)
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "UsersByName"
diff --git a/playbooks/indexes/ravendb_create_multimap_index.yml b/playbooks/indexes/ravendb_create_multimap_index.yml
index 40455d4..8072538 100644
--- a/playbooks/indexes/ravendb_create_multimap_index.yml
+++ b/playbooks/indexes/ravendb_create_multimap_index.yml
@@ -4,11 +4,11 @@
gather_facts: no
roles:
- - ravendb.community.ravendb_python_client_prerequisites
+ - ravendb.ravendb.ravendb_python_client_prerequisites
tasks:
- name: Ensure RavenDB Index is present (check mode)
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "UsersAndOrdersByName"
@@ -31,7 +31,7 @@
check_mode: yes
- name: Ensure RavenDB Index is present
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "UsersAndOrdersByName"
@@ -53,7 +53,7 @@
state: present
- name: Ensure RavenDB Index is present (idempotency check)
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "UsersAndOrdersByName"
diff --git a/playbooks/indexes/ravendb_delete_index.yml b/playbooks/indexes/ravendb_delete_index.yml
index 430a56b..8759ddb 100644
--- a/playbooks/indexes/ravendb_delete_index.yml
+++ b/playbooks/indexes/ravendb_delete_index.yml
@@ -4,11 +4,11 @@
gather_facts: no
roles:
- - ravendb.community.ravendb_python_client_prerequisites
+ - ravendb.ravendb.ravendb_python_client_prerequisites
tasks:
- name: Ensure RavenDB index is absent (check mode)
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "UsersByName"
@@ -16,19 +16,15 @@
check_mode: yes
- name: Ensure RavenDB index is absent
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
index_name: "UsersByName"
database_name: "my_database"
state: absent
- name: Ensure RavenDB index is absent (idempotency check)
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
index_name: "UsersByName"
database_name: "my_database"
- state: absent
-
-
-
-
+ state: absent
\ No newline at end of file
diff --git a/playbooks/indexes/ravendb_disable_index.yml b/playbooks/indexes/ravendb_disable_index.yml
index 2fff32e..deb5ca2 100644
--- a/playbooks/indexes/ravendb_disable_index.yml
+++ b/playbooks/indexes/ravendb_disable_index.yml
@@ -4,11 +4,11 @@
gather_facts: no
roles:
- - ravendb.community.ravendb_python_client_prerequisites
+ - ravendb.ravendb.ravendb_python_client_prerequisites
tasks:
- name: Ensure RavenDB Index is disabled (check mode)
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "Orders/ByCompany"
@@ -17,7 +17,7 @@
check_mode: yes
- name: Ensure RavenDB Index is disabled
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "Orders/ByCompany"
@@ -25,7 +25,7 @@
cluster_wide: true
- name: Ensure RavenDB Index is disabled (idempotency check)
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "Orders/ByCompany"
diff --git a/playbooks/indexes/ravendb_enable_index.yml b/playbooks/indexes/ravendb_enable_index.yml
index a279ada..8cbdfd6 100644
--- a/playbooks/indexes/ravendb_enable_index.yml
+++ b/playbooks/indexes/ravendb_enable_index.yml
@@ -4,11 +4,11 @@
gather_facts: no
roles:
- - ravendb.community.ravendb_python_client_prerequisites
+ - ravendb.ravendb.ravendb_python_client_prerequisites
tasks:
- name: Ensure RavenDB Index is enabled (check mode)
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "Orders/ByCompany"
@@ -17,7 +17,7 @@
check_mode: yes
- name: Ensure RavenDB Index is enabled
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "Orders/ByCompany"
@@ -25,7 +25,7 @@
cluster_wide: true
- name: Ensure RavenDB Index is enabled (idempotency check)
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "Orders/ByCompany"
diff --git a/playbooks/indexes/ravendb_pause_index.yml b/playbooks/indexes/ravendb_pause_index.yml
index 8148a0f..caad8e5 100644
--- a/playbooks/indexes/ravendb_pause_index.yml
+++ b/playbooks/indexes/ravendb_pause_index.yml
@@ -4,11 +4,11 @@
gather_facts: no
roles:
- - ravendb.community.ravendb_python_client_prerequisites
+ - ravendb.ravendb.ravendb_python_client_prerequisites
tasks:
- name: Ensure RavenDB Index is paused (check mode)
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "Orders/ByCompany"
@@ -16,14 +16,14 @@
check_mode: yes
- name: Ensure RavenDB Index is paused
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "Orders/ByCompany"
mode: paused
- name: Ensure RavenDB Index is pasued (idempotency check)
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "Orders/ByCompany"
diff --git a/playbooks/indexes/ravendb_reset_index.yml b/playbooks/indexes/ravendb_reset_index.yml
index ffce91b..5b28f10 100644
--- a/playbooks/indexes/ravendb_reset_index.yml
+++ b/playbooks/indexes/ravendb_reset_index.yml
@@ -4,11 +4,11 @@
gather_facts: no
roles:
- - ravendb.community.ravendb_python_client_prerequisites
+ - ravendb.ravendb.ravendb_python_client_prerequisites
tasks:
- name: Ensure RavenDB Index is reset (check mode)
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "Orders/ByCompany"
@@ -16,14 +16,14 @@
check_mode: yes
- name: Ensure RavenDB Index is reset
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "Orders/ByCompany"
mode: reset
- name: Ensure RavenDB Index is reset (idempotency check)
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "Orders/ByCompany"
diff --git a/playbooks/indexes/ravendb_resume_index.yml b/playbooks/indexes/ravendb_resume_index.yml
index 4dd973a..c619b72 100644
--- a/playbooks/indexes/ravendb_resume_index.yml
+++ b/playbooks/indexes/ravendb_resume_index.yml
@@ -4,11 +4,11 @@
gather_facts: no
roles:
- - ravendb.community.ravendb_python_client_prerequisites
+ - ravendb.ravendb.ravendb_python_client_prerequisites
tasks:
- name: Ensure RavenDB Index is resumed (check mode)
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "Orders/ByCompany"
@@ -16,14 +16,14 @@
check_mode: yes
- name: Ensure RavenDB Index is resumed
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "Orders/ByCompany"
mode: resumed
- name: Ensure RavenDB Index is resumed (idempotency check)
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "Orders/ByCompany"
diff --git a/playbooks/indexes/ravendb_update_index.yml b/playbooks/indexes/ravendb_update_index.yml
index 1042bc6..2d6304a 100644
--- a/playbooks/indexes/ravendb_update_index.yml
+++ b/playbooks/indexes/ravendb_update_index.yml
@@ -4,11 +4,11 @@
gather_facts: no
roles:
- - ravendb.community.ravendb_python_client_prerequisites
+ - ravendb.ravendb.ravendb_python_client_prerequisites
tasks:
- name: Ensure RavenDB Index is present
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "UsersByName"
@@ -18,7 +18,7 @@
state: present
- name: Update RavenDB Index definiton (check mode)
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "UsersByName"
@@ -39,7 +39,7 @@
- name: Update RavenDB Index definiton
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "UsersByName"
@@ -59,7 +59,7 @@
- name: Update RavenDB Index definiton (idempotency check)
- ravendb.community.index:
+ ravendb.ravendb.index:
url: "http://{{ ansible_host }}:8080"
database_name: "my_database"
index_name: "UsersByName"
diff --git a/playbooks/node/ravendb_add_nodes.yml b/playbooks/node/ravendb_add_nodes.yml
index 007ff97..8f3b3fe 100644
--- a/playbooks/node/ravendb_add_nodes.yml
+++ b/playbooks/node/ravendb_add_nodes.yml
@@ -6,7 +6,7 @@
tasks:
- name: Join Node B as Watcher
- ravendb.community.node:
+ ravendb.ravendb.node:
node:
tag: B
type: "Watcher"
@@ -15,7 +15,7 @@
- name: Join Node C as Member
- ravendb.community.node:
+ ravendb.ravendb.node:
node:
tag: C
url: "http://192.168.118.77:8080"
diff --git a/plugins/modules/TODO_ravendb_backup.py b/plugins/modules/TODO_ravendb_backup.py
deleted file mode 100644
index e69de29..0000000
diff --git a/plugins/modules/TODO_ravendb_client_certificate.py b/plugins/modules/TODO_ravendb_client_certificate.py
deleted file mode 100644
index e69de29..0000000
diff --git a/plugins/modules/TODO_ravendb_task.py b/plugins/modules/TODO_ravendb_task.py
deleted file mode 100644
index e69de29..0000000
diff --git a/plugins/modules/database.py b/plugins/modules/database.py
index 5dab765..7a2a592 100644
--- a/plugins/modules/database.py
+++ b/plugins/modules/database.py
@@ -1,13 +1,165 @@
-from ansible.module_utils.basic import AnsibleModule
-from ravendb import DocumentStore, GetDatabaseNamesOperation
-from ravendb.serverwide.operations.common import CreateDatabaseOperation, DeleteDatabaseOperation
-from ravendb.serverwide.database_record import DatabaseRecord
-from ravendb.exceptions.raven_exceptions import RavenException
-from urllib.parse import urlparse
-import re
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# Copyright (c), RavenDB
+# GNU General Public License v3.0 or later (see COPYING or
+# https://www.gnu.org/licenses/gpl-3.0.txt)
+
+from __future__ import absolute_import, division, print_function
+__metaclass__ = type
+
+DOCUMENTATION = '''
+---
+module: database
+short_description: Manage RavenDB databases
+description:
+ - This module allows you to create or delete a RavenDB database.
+ - It supports providing a replication factor and secured connections using certificates.
+ - Check mode is supported to simulate database creation or deletion without applying changes.
+version_added: "1.0.0"
+author: "Omer Ratsaby (@thegoldenplatypus)"
+options:
+ url:
+ description:
+ - URL of the RavenDB server.
+ - Must include the scheme (http or https), hostname and port.
+ required: true
+ type: str
+ database_name:
+ description:
+ - Name of the database to be created or deleted.
+ - Must be a valid name containing only letters, numbers, dashes, and underscores.
+ required: true
+ type: str
+ replication_factor:
+ description:
+ - Number of server nodes to replicate the database to.
+ - Must be a positive integer.
+ - Only used when creating a database.
+ required: false
+ default: 1
+ type: int
+ certificate_path:
+ description:
+ - Path to a client certificate (PEM format) for secured communication.
+ - Optional, but recommended for secure connections.
+ required: false
+ type: str
+ ca_cert_path:
+ description:
+ - Path to a trusted CA certificate file to verify the RavenDB server's certificate.
+ - Optional if the server certificate is trusted by system CA store.
+ required: false
+ type: str
+ state:
+ description:
+ - Desired state of the database.
+ - If C(present), the database will be created if it does not exist.
+ - If C(absent), the database will be deleted if it exists.
+ required: false
+ type: str
+ choices:
+ - present
+ - absent
+ default: present
+requirements:
+ - python >= 3.9
+ - ravendb python client
+ - ASP.NET Core Runtime
+ - Role ravendb.ravendb.ravendb_python_client_prerequisites must be installed before using this module.
+seealso:
+ - name: RavenDB documentation
+ description: Official RavenDB documentation
+ link: https://ravendb.net/docs
+notes:
+ - The role C(ravendb.ravendb.ravendb_python_client_prerequisites) must be applied before using this module.
+ - Requires the ASP.NET Core Runtime to be installed on the target system.
+'''
+
+EXAMPLES = '''
+- name: Create a RavenDB database
+ ravendb.ravendb.database:
+ url: "http://{{ ansible_host }}:8080"
+ database_name: "my_database"
+ replication_factor: 3
+ state: present
+
+- name: Delete a RavenDB database
+ ravendb.ravendb.database:
+ url: "http://{{ ansible_host }}:8080"
+ database_name: "my_database"
+ state: absent
+
+- name: Create a RavenDB database (secured server with self-signed certificates)
+ become: true
+ ravendb.ravendb.database:
+ url: "http://{{ ansible_host }}:443"
+ database_name: "my_secured_database"
+ replication_factor: 1
+ certificate_path: "combined_raven_cert.pem"
+ ca_cert_path: "ca_certificate.pem"
+ state: present
+
+- name: Delete a RavenDB database (secured server with self-signed certificates)
+ become: true
+ ravendb.ravendb.database:
+ url: "http://{{ ansible_host }}:443"
+ database_name: "my_secured_database"
+ certificate_path: "/etc/ravendb/security/combined_raven_cert.pem"
+ ca_cert_path: "/etc/ravendb/security/ca_certificate.pem"
+ state: absent
+
+- name: Simulate creating a RavenDB database (check mode)
+ ravendb.ravendb.database:
+ url: "http://{{ ansible_host }}:8080"
+ database_name: "my_database"
+ replication_factor: 3
+ state: present
+ check_mode: yes
+
+- name: Simulate deleting a RavenDB database (check mode)
+ ravendb.ravendb.database:
+ url: "http://{{ ansible_host }}:8080"
+ database_name: "my_database"
+ state: absent
+ check_mode: yes
+'''
+
+RETURN = '''
+changed:
+ description: Indicates if any change was made (or would have been made in check mode).
+ type: bool
+ returned: always
+ sample: true
+
+msg:
+ description: Human-readable message describing the result or error.
+ type: str
+ returned: always
+ sample: Database 'my_database' created successfully.
+ version_added: "1.0.0"
+'''
+
+import traceback
import os
-
-def create_store(url, certificate_path, ca_cert_path):
+import re
+from urllib.parse import urlparse
+from ansible.module_utils.basic import AnsibleModule, missing_required_lib
+
+LIB_IMP_ERR = None
+try:
+ from ravendb import DocumentStore, GetDatabaseNamesOperation
+ from ravendb.serverwide.operations.common import CreateDatabaseOperation, DeleteDatabaseOperation
+ from ravendb.serverwide.database_record import DatabaseRecord
+ from ravendb.exceptions.raven_exceptions import RavenException
+ HAS_LIB = True
+except ImportError:
+ HAS_LIB = False
+ LIB_IMP_ERR = traceback.format_exc()
+
+
+def create_store(url, certificate_path, ca_cert_path):
+ """Create and initialize a RavenDB DocumentStore with optional client and CA certificates."""
store = DocumentStore(urls=[url])
if certificate_path and ca_cert_path:
store.certificate_pem_path = certificate_path
@@ -17,10 +169,16 @@ def create_store(url, certificate_path, ca_cert_path):
def get_existing_databases(store):
+ """Retrieve the list of existing RavenDB databases from the server."""
return store.maintenance.server.send(GetDatabaseNamesOperation(0, 128))
def handle_present_state(store, database_name, replication_factor, check_mode):
+ """
+ Ensure the specified database exists.
+
+ Returns a tuple: (changed: bool, message: str)
+ """
existing_databases = get_existing_databases(store)
if database_name in existing_databases:
@@ -39,6 +197,10 @@ def handle_present_state(store, database_name, replication_factor, check_mode):
def handle_absent_state(store, database_name, check_mode):
+ """
+ Ensure the specified database is absent.
+ Returns a tuple: (changed: bool, message: str)
+ """
existing_databases = get_existing_databases(store)
if database_name not in existing_databases:
@@ -50,44 +212,66 @@ def handle_absent_state(store, database_name, check_mode):
delete_database_operation = DeleteDatabaseOperation(database_name)
store.maintenance.server.send(delete_database_operation)
return True, f"Database '{database_name}' deleted successfully."
-
+
+
def is_valid_url(url):
+ """Return True if the given URL contains a valid scheme and netloc."""
parsed = urlparse(url)
return all([parsed.scheme, parsed.netloc])
+
def is_valid_database_name(name):
+ """Check if the database name is valid (letters, numbers, dashes, underscores)."""
return bool(re.match(r"^[a-zA-Z0-9_-]+$", name))
+
def is_valid_replication_factor(factor):
+ """Return True if replication factor is a positive integer."""
return isinstance(factor, int) and factor > 0
+
def is_valid_bool(value):
+ """Return True if the value is a boolean."""
return isinstance(value, bool)
+
def validate_paths(*paths):
+ """
+ Validate that all given file paths exist on the filesystem.
+ Returns a tuple: (valid: bool, error_msg: Optional[str])
+ """
for path in paths:
if path and not os.path.isfile(path):
return False, f"Path does not exist: {path}"
return True, None
+
def is_valid_state(state):
+ """Return True if the state is either 'present' or 'absent'."""
return state in ['present', 'absent']
+
def main():
module_args = dict(
- url=dict(type='str', required=True),
- database_name=dict(type='str', required=True),
- replication_factor=dict(type='int', default=1),
- certificate_path=dict(type='str', required=False),
- ca_cert_path=dict(type='str', required=False),
- state=dict(type='str', choices=['present', 'absent'], default='present')
- )
+ url=dict(
+ type='str', required=True), database_name=dict(
+ type='str', required=True), replication_factor=dict(
+ type='int', default=1), certificate_path=dict(
+ type='str', required=False), ca_cert_path=dict(
+ type='str', required=False), state=dict(
+ type='str', choices=[
+ 'present', 'absent'], default='present'))
module = AnsibleModule(
argument_spec=module_args,
supports_check_mode=True
)
+ if not HAS_LIB:
+ module.fail_json(
+ msg=missing_required_lib("ravendb"),
+ exception=LIB_IMP_ERR)
+
url = module.params['url']
database_name = module.params['database_name']
replication_factor = module.params['replication_factor']
@@ -99,27 +283,31 @@ def main():
module.fail_json(msg=f"Invalid URL: {url}")
if not is_valid_database_name(database_name):
- module.fail_json(msg=f"Invalid database name: {database_name}. Only letters, numbers, dashes, and underscores are allowed.")
+ module.fail_json(
+ msg=f"Invalid database name: {database_name}. Only letters, numbers, dashes, and underscores are allowed.")
if not is_valid_replication_factor(replication_factor):
- module.fail_json(msg=f"Invalid replication factor: {replication_factor}. Must be a positive integer.")
-
+ module.fail_json(
+ msg=f"Invalid replication factor: {replication_factor}. Must be a positive integer.")
valid, error_msg = validate_paths(certificate_path, ca_cert_path)
if not valid:
module.fail_json(msg=error_msg)
if not is_valid_state(desired_state):
- module.fail_json(msg=f"Invalid state: {desired_state}. Must be 'present' or 'absent'.")
+ module.fail_json(
+ msg=f"Invalid state: {desired_state}. Must be 'present' or 'absent'.")
try:
store = create_store(url, certificate_path, ca_cert_path)
check_mode = module.check_mode
if desired_state == 'present':
- changed, message = handle_present_state(store, database_name, replication_factor, check_mode)
+ changed, message = handle_present_state(
+ store, database_name, replication_factor, check_mode)
elif desired_state == 'absent':
- changed, message = handle_absent_state(store, database_name, check_mode)
+ changed, message = handle_absent_state(
+ store, database_name, check_mode)
module.exit_json(changed=changed, msg=message)
diff --git a/plugins/modules/index.py b/plugins/modules/index.py
index 0e94be6..74e2bcb 100644
--- a/plugins/modules/index.py
+++ b/plugins/modules/index.py
@@ -1,17 +1,248 @@
-import sys
-import os
-import re
-from ansible.module_utils.basic import AnsibleModule
-from ravendb import DocumentStore, AbstractIndexCreationTask
-from ravendb.documents.indexes.abstract_index_creation_tasks import AbstractMultiMapIndexCreationTask
-from ravendb.documents.operations.indexes import (
- GetIndexesOperation, DeleteIndexOperation, EnableIndexOperation, DisableIndexOperation,
- StartIndexOperation, StopIndexOperation, GetIndexingStatusOperation, ResetIndexOperation)
-from ravendb.documents.indexes.definitions import IndexRunningStatus
-from ravendb.exceptions.raven_exceptions import RavenException
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# Copyright (c), RavenDB
+# GNU General Public License v3.0 or later (see COPYING or
+# https://www.gnu.org/licenses/gpl-3.0.txt)
+
+from __future__ import absolute_import, division, print_function
+__metaclass__ = type
+
+DOCUMENTATION = '''
+---
+module: index
+short_description: Manage RavenDB indexes
+description:
+ - This module allows you to create, delete, pause, resume, enable, disable, or reset RavenDB indexes.
+ - Supports check mode to simulate changes without applying them.
+ - Can create dynamic single-map and multi-map indexes based on a provided index definition.
+version_added: "1.0.0"
+author: "Omer Ratsaby (@thegoldenplatypus)"
+options:
+ url:
+ description:
+ - URL of the RavenDB server.
+ - Must include the scheme (http or https), hostname and port.
+ required: true
+ type: str
+ database_name:
+ description:
+ - Name of the database where the index resides/should be reside.
+ required: true
+ type: str
+ index_name:
+ description:
+ - Name of the index to create, delete, or modify.
+ - Must consist only of letters, numbers, dashes, and underscores.
+ required: true
+ type: str
+ index_definition:
+ description:
+ - Dictionary defining the index (maps and optional reduce).
+ - Required when creating a new index.
+ required: false
+ type: dict
+ certificate_path:
+ description:
+ - Path to a client certificate (PEM format) for secured communication.
+ required: false
+ type: str
+ ca_cert_path:
+ description:
+ - Path to a trusted CA certificate file to verify the RavenDB server's certificate.
+ required: false
+ type: str
+ state:
+ description:
+ - Desired state of the index.
+ - If C(present), the index will be created if it does not exist.
+ - If C(absent), the index will be deleted if it exists.
+ required: false
+ type: str
+ choices:
+ - present
+ - absent
+ mode:
+ description:
+ - Operational mode to apply to an existing index.
+ required: false
+ type: str
+ choices:
+ - resumed
+ - paused
+ - enabled
+ - disabled
+ - reset
+ cluster_wide:
+ description:
+ - Whether to apply enable/disable operations cluster-wide.
+ required: false
+ type: bool
+ default: false
+requirements:
+ - python >= 3.9
+ - ravendb python client
+ - ASP.NET Core Runtime
+ - Role ravendb.ravendb.ravendb_python_client_prerequisites must be installed before using this module.
+seealso:
+ - name: RavenDB documentation
+ description: Official RavenDB documentation
+ link: https://ravendb.net/docs
+notes:
+ - The role C(ravendb.ravendb.ravendb_python_client_prerequisites) must be applied before using this module.
+ - Requires the ASP.NET Core Runtime to be installed on the target system.
+'''
+
+EXAMPLES = '''
+- name: Create a RavenDB index with map and reduce
+ ravendb.ravendb.index:
+ url: "http://{{ ansible_host }}:8080"
+ database_name: "my_database"
+ index_name: "UsersByName"
+ index_definition:
+ map:
+ - "from c in docs.Users select new { c.name, count = 5 }"
+ reduce: >
+ from result in results
+ group result by result.name
+ into g
+ select new
+ {
+ name = g.Key,
+ count = g.Sum(x => x.count)
+ }
+ state: present
+
+- name: Create a RavenDB multi-map index
+ ravendb.ravendb.index:
+ url: "http://{{ ansible_host }}:8080"
+ database_name: "my_database"
+ index_name: "UsersAndOrdersByName"
+ index_definition:
+ map:
+ - "from c in docs.Users select new { Name = c.name, UserCount = 1, OrderCount = 0, TotalCount = 1 }"
+ - "from o in docs.Orders select new { Name = o.customer, UserCount = 0, OrderCount = 1, TotalCount = 1 }"
+ reduce: >
+ from result in results
+ group result by result.Name
+ into g
+ select new
+ {
+ Name = g.Key,
+ UserCount = g.Sum(x => x.UserCount),
+ OrderCount = g.Sum(x => x.OrderCount),
+ TotalCount = g.Sum(x => x.TotalCount)
+ }
+ state: present
+
+- name: Delete a RavenDB index
+ ravendb.ravendb.index:
+ url: "http://{{ ansible_host }}:8080"
+ database_name: "my_database"
+ index_name: "UsersByName"
+ state: absent
+
+- name: Disable a RavenDB index (cluster-wide)
+ ravendb.ravendb.index:
+ url: "http://{{ ansible_host }}:8080"
+ database_name: "my_database"
+ index_name: "Orders/ByCompany"
+ mode: disabled
+ cluster_wide: true
+
+- name: Enable a RavenDB index
+ ravendb.ravendb.index:
+ url: "http://{{ ansible_host }}:8080"
+ database_name: "my_database"
+ index_name: "Orders/ByCompany"
+ mode: enabled
+
+- name: Pause a RavenDB index
+ ravendb.ravendb.index:
+ url: "http://{{ ansible_host }}:8080"
+ database_name: "my_database"
+ index_name: "Orders/ByCompany"
+ mode: paused
+
+- name: Resume a RavenDB index
+ ravendb.ravendb.index:
+ url: "http://{{ ansible_host }}:8080"
+ database_name: "my_database"
+ index_name: "Orders/ByCompany"
+ mode: resumed
+
+- name: Reset a RavenDB index
+ ravendb.ravendb.index:
+ url: "http://{{ ansible_host }}:8080"
+ database_name: "my_database"
+ index_name: "Orders/ByCompany"
+ mode: reset
+
+- name: Update an existing RavenDB index definition
+ ravendb.ravendb.index:
+ url: "http://{{ ansible_host }}:8080"
+ database_name: "my_database"
+ index_name: "UsersByName"
+ index_definition:
+ map:
+ - "from c in docs.Users select new { c.name, count = 13 }"
+ reduce: >
+ from result in results
+ group result by result.name
+ into g
+ select new
+ {
+ name = g.Key,
+ count = g.Sum(x => x.count)
+ }
+ state: present
+'''
+
+RETURN = '''
+changed:
+ description: Indicates if any change was made (or would have been made in check mode).
+ type: bool
+ returned: always
+ sample: true
+
+msg:
+ description: Human-readable message describing the result or error.
+ type: str
+ returned: always
+ sample: Index 'Products_ByName' created successfully.
+ version_added: "1.0.0"
+'''
+
+import traceback
from urllib.parse import urlparse
+import re
+import os
+import sys
+from ansible.module_utils.basic import AnsibleModule, missing_required_lib
+
+LIB_IMP_ERR = None
+try:
+ from ravendb import DocumentStore, AbstractIndexCreationTask
+ from ravendb.documents.indexes.abstract_index_creation_tasks import AbstractMultiMapIndexCreationTask
+ from ravendb.documents.operations.indexes import (
+ GetIndexesOperation,
+ DeleteIndexOperation,
+ EnableIndexOperation,
+ DisableIndexOperation,
+ StartIndexOperation,
+ StopIndexOperation,
+ GetIndexingStatusOperation,
+ ResetIndexOperation)
+ from ravendb.documents.indexes.definitions import IndexRunningStatus
+ from ravendb.exceptions.raven_exceptions import RavenException
+ HAS_LIB = True
+except ImportError:
+ HAS_LIB = False
+ LIB_IMP_ERR = traceback.format_exc()
+
def create_dynamic_index(name, definition):
+ """Dynamically create a single-map index class based on the given definition."""
class DynamicIndex(AbstractIndexCreationTask):
def __init__(self):
super(DynamicIndex, self).__init__()
@@ -23,7 +254,9 @@ def __init__(self):
DynamicIndex.__name__ = name
return DynamicIndex
+
def create_dynamic_multimap_index(name, definition):
+ """Dynamically create a multi-map index class based on the given definition."""
class DynamicIndex(AbstractMultiMapIndexCreationTask):
def __init__(self):
super(DynamicIndex, self).__init__()
@@ -39,7 +272,9 @@ def __init__(self):
DynamicIndex.__name__ = name
return DynamicIndex
+
def initialize_ravendb_store(params):
+ """Create and initialize a RavenDB DocumentStore from Ansible module parameters."""
url = params['url']
database_name = params['database_name']
certificate_path = params.get('certificate_path')
@@ -53,7 +288,12 @@ def initialize_ravendb_store(params):
store.initialize()
return store
+
def reconcile_state(store, params, check_mode):
+ """
+ Determine and apply the required state (present, absent, or mode-only) to an index.
+ Returns a tuple: (status, changed, message)
+ """
database_name = params['database_name']
index_name = params['index_name']
desired_state = params.get('state')
@@ -61,21 +301,45 @@ def reconcile_state(store, params, check_mode):
cluster_wide = params['cluster_wide']
database_maintenance = store.maintenance.for_database(database_name)
- existing_indexes = database_maintenance.send(GetIndexesOperation(0, sys.maxsize))
+ existing_indexes = database_maintenance.send(
+ GetIndexesOperation(0, sys.maxsize))
existing_index_names = [i.name for i in existing_indexes]
-
+
if desired_state == 'absent':
- return handle_absent_state(database_maintenance, index_name, existing_index_names, check_mode)
+ return handle_absent_state(
+ database_maintenance,
+ index_name,
+ existing_index_names,
+ check_mode)
if desired_state == 'present':
- return handle_present_state( store, database_name, params, index_name, existing_indexes, existing_index_names, check_mode)
+ return handle_present_state(
+ store,
+ database_name,
+ params,
+ index_name,
+ existing_indexes,
+ existing_index_names,
+ check_mode)
if desired_mode and desired_state is None:
- return handle_mode_only(store, index_name, desired_mode, cluster_wide, check_mode, existing_index_names)
+ return handle_mode_only(
+ store,
+ index_name,
+ desired_mode,
+ cluster_wide,
+ check_mode,
+ existing_index_names)
return "error", False, "Invalid state or mode combination."
-def handle_absent_state(database_maintenance, index_name, existing_index_names, check_mode):
+
+def handle_absent_state(
+ database_maintenance,
+ index_name,
+ existing_index_names,
+ check_mode):
+ """Delete the index if it exists. Respect Ansible check mode."""
if index_name not in existing_index_names:
return "ok", False, f"Index '{index_name}' is already absent."
@@ -85,17 +349,31 @@ def handle_absent_state(database_maintenance, index_name, existing_index_names,
database_maintenance.send(DeleteIndexOperation(index_name))
return "ok", True, f"Index '{index_name}' deleted successfully."
-def handle_present_state(store, database_name, params, index_name, existing_indexes, existing_index_names, check_mode):
-
+
+def handle_present_state(
+ store,
+ database_name,
+ params,
+ index_name,
+ existing_indexes,
+ existing_index_names,
+ check_mode):
+ """Create or update the index if needed. Respect Ansible check mode."""
index_definition = params.get('index_definition')
desired_mode = params.get('mode')
cluster_wide = params['cluster_wide']
if index_name in existing_index_names:
- existing_index = next(i for i in existing_indexes if i.name == index_name)
+ existing_index = next(
+ i for i in existing_indexes if i.name == index_name)
if index_matches(existing_index, index_definition):
if desired_mode:
- return apply_mode(store, index_name, desired_mode, cluster_wide, check_mode)
+ return apply_mode(
+ store,
+ index_name,
+ desired_mode,
+ cluster_wide,
+ check_mode)
return "ok", False, f"Index '{index_name}' already exists and matches definition."
if check_mode:
@@ -108,19 +386,30 @@ def handle_present_state(store, database_name, params, index_name, existing_inde
return "ok", True, f"Index '{index_name}' created successfully."
-def handle_mode_only(store, index_name, desired_mode, cluster_wide, check_mode, existing_index_names):
-
+def handle_mode_only(
+ store,
+ index_name,
+ desired_mode,
+ cluster_wide,
+ check_mode,
+ existing_index_names):
+ """Apply only the desired index mode if the index already exists."""
if index_name not in existing_index_names:
return "error", False, f"Index '{index_name}' does not exist. Cannot apply mode."
-
- return apply_mode(store, index_name, desired_mode, cluster_wide, check_mode)
+ return apply_mode(
+ store,
+ index_name,
+ desired_mode,
+ cluster_wide,
+ check_mode)
def create_index(store, database_name, index_name, index_definition):
-
+ """Create an index, handling both single-map and multi-map definitions."""
if len(index_definition.get("map")) > 1:
- DynamicIndexClass = create_dynamic_multimap_index(index_name, index_definition)
+ DynamicIndexClass = create_dynamic_multimap_index(
+ index_name, index_definition)
else:
DynamicIndexClass = create_dynamic_index(index_name, index_definition)
index = DynamicIndexClass()
@@ -128,8 +417,9 @@ def create_index(store, database_name, index_name, index_definition):
def index_matches(existing_index, index_definition):
-
- existing_maps = set(map(str.strip, existing_index.maps)) if existing_index.maps else set()
+ """Check if an existing index matches the expected definition (map/reduce)."""
+ existing_maps = set(map(str.strip, existing_index.maps)
+ ) if existing_index.maps else set()
existing_reduce = getattr(existing_index, 'reduce', None)
expected_maps = set(map(str.strip, index_definition.get("map", [])))
@@ -142,20 +432,21 @@ def index_matches(existing_index, index_definition):
def enable_index(store, index_name, cluster_wide, check_mode):
-
+ """Enable a RavenDB index, optionally cluster-wide. Respect check mode."""
if check_mode:
return "ok", True, f"Index '{index_name}' would be enabled {' cluster-wide' if cluster_wide else ''}."
-
+
enable_index_operation = EnableIndexOperation(index_name, cluster_wide)
store.maintenance.send(enable_index_operation)
return "ok", True, f"Index '{index_name}' enabled successfully {' cluster-wide' if cluster_wide else ''}."
+
def disable_index(store, index_name, cluster_wide, check_mode):
-
+ """Disable a RavenDB index, optionally cluster-wide. Respect check mode."""
if check_mode:
return "ok", True, f"Index '{index_name}' would be disabled {' cluster-wide' if cluster_wide else ''}."
-
+
disable_index_operation = DisableIndexOperation(index_name, cluster_wide)
store.maintenance.send(disable_index_operation)
@@ -163,7 +454,7 @@ def disable_index(store, index_name, cluster_wide, check_mode):
def resume_index(store, index_name, check_mode):
-
+ """Resume a paused RavenDB index. Respect check mode."""
indexing_status = store.maintenance.send(GetIndexingStatusOperation())
index = [x for x in indexing_status.indexes if x.name == index_name][0]
if index.status == IndexRunningStatus.RUNNING:
@@ -171,7 +462,7 @@ def resume_index(store, index_name, check_mode):
if check_mode:
return "ok", True, f"Index '{index_name}' would be resumed."
-
+
resume_index_operation = StartIndexOperation(index_name)
store.maintenance.send(resume_index_operation)
@@ -179,7 +470,7 @@ def resume_index(store, index_name, check_mode):
def pause_index(store, index_name, check_mode):
-
+ """Pause a running RavenDB index. Respect check mode."""
indexing_status = store.maintenance.send(GetIndexingStatusOperation())
index = [x for x in indexing_status.indexes if x.name == index_name][0]
if index.status == IndexRunningStatus.PAUSED:
@@ -187,17 +478,18 @@ def pause_index(store, index_name, check_mode):
if check_mode:
return "ok", True, f"Index '{index_name}' would be paused."
-
+
pause_index_operation = StopIndexOperation(index_name)
store.maintenance.send(pause_index_operation)
return "ok", True, f"Index '{index_name}' paused successfully."
-
+
+
def reset_index(store, index_name, check_mode):
-
+ """Reset an existing index. Respect check mode."""
if check_mode:
return "ok", True, f"Index '{index_name}' would be reset."
-
+
reset_index_operation = ResetIndexOperation(index_name)
store.maintenance.send(reset_index_operation)
@@ -205,42 +497,57 @@ def reset_index(store, index_name, check_mode):
def apply_mode(store, index_name, mode, cluster_wide, check_mode):
-
- match mode:
- case 'enabled':
- return enable_index(store, index_name, cluster_wide, check_mode)
- case 'disabled':
- return disable_index(store, index_name, cluster_wide, check_mode)
- case 'resumed':
- return resume_index(store, index_name, check_mode)
- case 'paused':
- return pause_index(store, index_name, check_mode)
- case 'reset':
- return reset_index(store, index_name, check_mode)
+ """Dispatch index mode operation based on the given mode string."""
+ if mode == 'enabled':
+ return enable_index(store, index_name, cluster_wide, check_mode)
+ elif mode == 'disabled':
+ return disable_index(store, index_name, cluster_wide, check_mode)
+ elif mode == 'resumed':
+ return resume_index(store, index_name, check_mode)
+ elif mode == 'paused':
+ return pause_index(store, index_name, check_mode)
+ elif mode == 'reset':
+ return reset_index(store, index_name, check_mode)
+ else:
+ return "error", False, f"Unsupported mode '{mode}' specified."
+
def is_valid_url(url):
+ """Return True if the URL has a valid scheme and network location."""
parsed = urlparse(url)
return all([parsed.scheme, parsed.netloc])
+
def is_valid_name(name):
+ """Return True if the name contains only alphanumeric characters, dashes, or underscores."""
return bool(re.match(r"^[a-zA-Z0-9_-]+$", name))
+
def is_valid_dict(value):
+ """Return True if the value is a dictionary or None."""
return isinstance(value, dict) or value is None
+
def is_valid_bool(value):
+ """Return True if the value is a boolean."""
return isinstance(value, bool)
+
def validate_paths(*paths):
+ """Check if all provided file paths exist. Return (True, None) or (False, error message)."""
for path in paths:
if path and not os.path.isfile(path):
return False, f"Path does not exist: {path}"
return True, None
+
def is_valid_state(state):
+ """Return True if the state is one of: None, 'present', 'absent'."""
return state in [None, 'present', 'absent']
+
def is_valid_mode(mode):
+ """Return True if the mode is one of: None, 'resumed', 'paused', 'enabled', 'disabled', 'reset'."""
return mode in [None, 'resumed', 'paused', 'enabled', 'disabled', 'reset']
@@ -262,6 +569,11 @@ def main():
supports_check_mode=True
)
+ if not HAS_LIB:
+ module.fail_json(
+ msg=missing_required_lib("ravendb"),
+ exception=LIB_IMP_ERR)
+
url = module.params['url']
database_name = module.params['database_name']
index_name = module.params['index_name']
@@ -276,32 +588,39 @@ def main():
module.fail_json(msg=f"Invalid URL: {url}")
if not is_valid_name(database_name):
- module.fail_json(msg=f"Invalid database name: {database_name}. Only letters, numbers, dashes, and underscores are allowed.")
+ module.fail_json(
+ msg=f"Invalid database name: {database_name}. Only letters, numbers, dashes, and underscores are allowed.")
if not is_valid_name(index_name):
- module.fail_json(msg=f"Invalid index name: {index_name}. Only letters, numbers, dashes, and underscores are allowed.")
+ module.fail_json(
+ msg=f"Invalid index name: {index_name}. Only letters, numbers, dashes, and underscores are allowed.")
if not is_valid_dict(index_definition):
- module.fail_json(msg=f"Invalid index definition: Must be a dictionary.")
+ module.fail_json(
+ msg="Invalid index definition: Must be a dictionary.")
valid, error_msg = validate_paths(certificate_path, ca_cert_path)
if not valid:
module.fail_json(msg=error_msg)
if not is_valid_state(state):
- module.fail_json(msg=f"Invalid state: {state}. Must be 'present' or 'absent'.")
+ module.fail_json(
+ msg=f"Invalid state: {state}. Must be 'present' or 'absent'.")
if not is_valid_mode(mode):
- module.fail_json(msg=f"Invalid mode: {mode}. Must be one of 'resumed', 'paused', 'enabled', 'disabled', 'reset'.")
+ module.fail_json(
+ msg=f"Invalid mode: {mode}. Must be one of 'resumed', 'paused', 'enabled', 'disabled', 'reset'.")
if not is_valid_bool(cluster_wide):
- module.fail_json(msg=f"Invalid cluster_wide flag: {cluster_wide}. Must be a boolean.")
+ module.fail_json(
+ msg=f"Invalid cluster_wide flag: {cluster_wide}. Must be a boolean.")
try:
store = initialize_ravendb_store(module.params)
check_mode = module.check_mode
- type, changed, message = reconcile_state(store, module.params, check_mode)
+ type, changed, message = reconcile_state(
+ store, module.params, check_mode)
if type == "error":
module.fail_json(changed=changed, msg=message)
@@ -316,5 +635,6 @@ def main():
if 'store' in locals():
store.close()
+
if __name__ == '__main__':
main()
diff --git a/plugins/modules/node.py b/plugins/modules/node.py
index 9668a90..39852c0 100644
--- a/plugins/modules/node.py
+++ b/plugins/modules/node.py
@@ -1,18 +1,114 @@
-from ansible.module_utils.basic import AnsibleModule
-import requests
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# Copyright (c), RavenDB
+# GNU General Public License v3.0 or later (see COPYING or
+# https://www.gnu.org/licenses/gpl-3.0.txt)
+
+from __future__ import absolute_import, division, print_function
+__metaclass__ = type
+
+DOCUMENTATION = '''
+---
+module: node
+short_description: Add a RavenDB node to an existing cluster
+description:
+ - This module adds a RavenDB node to a cluster, either as a member or a watcher.
+ - Requires specifying the leader node's URL.
+ - Supports check mode to simulate the addition without applying changes.
+version_added: "1.0.0"
+author: "Omer Ratsaby (@thegoldenplatypus)"
+options:
+ node:
+ description:
+ - Dictionary containing the node details to add.
+ - Must include C(tag), C(url), and C(leader_url).
+ - Optionally, set C(type) to "Watcher" to add the node as a watcher instead of a full member.
+ required: true
+ type: dict
+requirements:
+ - python >= 3.9
+ - requests
+ - Role ravendb.ravendb.ravendb_python_client_prerequisites must be installed before using this module.
+seealso:
+ - name: RavenDB documentation
+ description: Official RavenDB documentation
+ link: https://ravendb.net/docs
+notes:
+ - The node C(tag) must be an uppercase, non-empty alphanumeric string.
+ - URLs must be valid HTTP or HTTPS addresses.
+ - Check mode is fully supported and simulates joining the node without actually performing the action.
+'''
+
+EXAMPLES = '''
+- name: Join Node B as a Watcher
+ ravendb.ravendb.node:
+ node:
+ tag: B
+ type: "Watcher"
+ url: "http://192.168.118.120:8080"
+ leader_url: "http://192.168.117.90:8080"
+
+- name: Join Node C as a Member
+ ravendb.ravendb.node:
+ node:
+ tag: C
+ url: "http://192.168.118.77:8080"
+ leader_url: "http://192.168.117.90:8080"
+
+- name: Simulate adding Node D (check mode)
+ ravendb.ravendb.node:
+ node:
+ tag: D
+ url: "http://192.168.118.200:8080"
+ leader_url: "http://192.168.117.90:8080"
+ check_mode: yes
+'''
+
+RETURN = '''
+changed:
+ description: Indicates if the cluster topology was changed or would have changed (check mode).
+ type: bool
+ returned: always
+ sample: true
+
+msg:
+ description: Human-readable message describing the result or error.
+ type: str
+ returned: always
+ sample: Node B added to the cluster
+ version_added: "1.0.0"
+'''
+
from urllib.parse import urlparse
+from ansible.module_utils.basic import AnsibleModule
+
def is_valid_url(url):
+ """Return True if the given URL is a string with a valid HTTP or HTTPS scheme and a network location."""
if not isinstance(url, str):
return False
parsed = urlparse(url)
return all([parsed.scheme in ["http", "https"], parsed.netloc])
+
def is_valid_tag(tag):
+ """Return True if the tag is a non-empty uppercase alphanumeric string."""
return isinstance(tag, str) and tag.isalnum() and tag.isupper()
-def add_node(node,check_mode):
+def add_node(node, check_mode):
+ """
+ Add a new node to a RavenDB cluster by making an HTTP PUT request to the leader node.
+
+ Args:
+ node (dict): Dictionary containing 'url', 'tag', 'leader_url', and 'type' fields.
+ check_mode (bool): If True, simulate adding the node without making changes.
+
+ Returns:
+ dict: Result dictionary with keys 'changed', 'msg', and optionally 'error'.
+ """
+ import requests
url = node.get("url")
tag = node.get("tag")
leader_url = node.get("leader_url")
@@ -20,22 +116,28 @@ def add_node(node,check_mode):
if not leader_url:
return {"changed": False, "msg": "Leader URL must be specified"}
-
+
if not is_valid_url(leader_url):
return {"changed": False, "msg": f"Invalid Leader URL: {leader_url}"}
-
+
if not is_valid_tag(tag):
- return {"changed": False, "msg": "Invalid tag: Node tag must be an uppercase non-empty alphanumeric string"}
+ return {
+ "changed": False,
+ "msg": "Invalid tag: Node tag must be an uppercase non-empty alphanumeric string"}
if not is_valid_url(url):
- return {"changed": False, "msg": "Invalid URL: must be a valid HTTP(S) URL"}
-
+ return {
+ "changed": False,
+ "msg": "Invalid URL: must be a valid HTTP(S) URL"}
+
headers = {"Content-Type": "application/json"}
if check_mode:
- return {"changed": True, "msg": f"Node {tag} would be added to the cluster"}
+ return {
+ "changed": True,
+ "msg": f"Node {tag} would be added to the cluster"}
try:
-
+
add_url = f"{leader_url}/admin/cluster/node?url={url}&tag={tag}"
if is_watcher:
add_url += "&watcher=true"
@@ -44,14 +146,22 @@ def add_node(node,check_mode):
response.raise_for_status()
except requests.HTTPError as e:
- error_message = response.json().get("Message", response.text) if response.content else str(e)
- return {"changed": False, "msg": f"Failed to add node {tag}", "error": error_message}
+ error_message = response.json().get(
+ "Message", response.text) if response.content else str(e)
+ return {
+ "changed": False,
+ "msg": f"Failed to add node {tag}",
+ "error": error_message}
except requests.RequestException as e:
- return {"changed": False, "msg": f"Failed to add node {tag}", "error": str(e)}
+ return {
+ "changed": False,
+ "msg": f"Failed to add node {tag}",
+ "error": str(e)}
return {"changed": True, "msg": f"Node {tag} added to the cluster"}
+
def main():
module_args = {
"node": {"type": "dict", "required": True},
@@ -61,7 +171,7 @@ def main():
node = module.params["node"]
try:
- changed,message = add_node(node, module.check_mode)
+ changed, message = add_node(node, module.check_mode)
module.exit_json(changed=changed, msg=message)
except Exception as e:
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..a51c12f
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,7 @@
+requests>=2.20.0
+ravendb>=7.0.0
+ansible>=2.15.0
+molecule>=6.0.0
+molecule-plugins[docker]>=23.3.1
+ansible-lint>=6.0.0
+yamllint>=1.26.0
\ No newline at end of file
diff --git a/roles/ravendb_node/molecule/update/converge.yml b/roles/ravendb_node/molecule/update/converge.yml
index d81e74b..c2ac090 100644
--- a/roles/ravendb_node/molecule/update/converge.yml
+++ b/roles/ravendb_node/molecule/update/converge.yml
@@ -51,5 +51,4 @@
vars:
ravendb_state: present
ravendb_version_minor: 6.2
- ravendb_settings_preset: default
-
+ ravendb_settings_preset: default
\ No newline at end of file
diff --git a/roles/ravendb_node/tasks/debian.yml b/roles/ravendb_node/tasks/debian.yml
index 543654f..939edad 100644
--- a/roles/ravendb_node/tasks/debian.yml
+++ b/roles/ravendb_node/tasks/debian.yml
@@ -44,5 +44,4 @@
ansible.builtin.get_url:
url: "{{ ravendb_download_url }}"
dest: /tmp/ravendb.deb
- tags: download
-
+ tags: download
\ No newline at end of file
diff --git a/roles/ravendb_node/tasks/ravendb_secure_self_sign_setup.yml b/roles/ravendb_node/tasks/ravendb_secure_self_sign_setup.yml
index a7f5954..55d2126 100644
--- a/roles/ravendb_node/tasks/ravendb_secure_self_sign_setup.yml
+++ b/roles/ravendb_node/tasks/ravendb_secure_self_sign_setup.yml
@@ -1,4 +1,3 @@
-
- name: Ensure RavenDB server certificate file is present
assert:
that:
diff --git a/roles/ravendb_node/tasks/uninstall.yml b/roles/ravendb_node/tasks/uninstall.yml
index 8e736d4..ccc517a 100644
--- a/roles/ravendb_node/tasks/uninstall.yml
+++ b/roles/ravendb_node/tasks/uninstall.yml
@@ -73,5 +73,4 @@
changed_when: false
- name: Clean up Python prerequisites
- import_tasks: ravendb_python_client_prerequisites_uninstall.yml
-
+ import_tasks: ravendb_python_client_prerequisites_uninstall.yml
\ No newline at end of file
diff --git a/roles/ravendb_python_client_prerequisites/tasks/main.yml b/roles/ravendb_python_client_prerequisites/tasks/main.yml
index 96189d9..1b304f8 100644
--- a/roles/ravendb_python_client_prerequisites/tasks/main.yml
+++ b/roles/ravendb_python_client_prerequisites/tasks/main.yml
@@ -73,3 +73,15 @@
ansible.builtin.command:
cmd: "{{ ravendb_venv_path }}/bin/pip install ravendb"
when: ravendb_installed.rc == 1
+
+- name: Check if requests is installed in virtual environment
+ command: "{{ ravendb_venv_path }}/bin/pip show requests"
+ register: requests_installed
+ failed_when: requests_installed.rc != 0 and requests_installed.rc != 1
+ changed_when: false
+
+- name: Install requests in virtual environment
+ become: true
+ ansible.builtin.command:
+ cmd: "{{ ravendb_venv_path }}/bin/pip install requests"
+ when: requests_installed.rc == 1
\ No newline at end of file
diff --git a/tests/unit/test_cluster.py b/tests/unit/test_cluster.py
index 3564039..4abe57b 100644
--- a/tests/unit/test_cluster.py
+++ b/tests/unit/test_cluster.py
@@ -1,10 +1,15 @@
+# Copyright (c), RavenDB
+# GNU General Public License v3.0 or later (see COPYING or
+# https://www.gnu.org/licenses/gpl-3.0.txt)
+
from unittest import TestCase
from unittest.mock import patch, Mock
-from ansible_collections.ravendb.community.plugins.modules.node import *
+from ansible_collections.ravendb.ravendb.plugins.modules.node import add_node, is_valid_url, is_valid_tag
import requests
+
class TestAddNodeWithRavenDB(TestCase):
-
+
def setUp(self):
self.leader_url = "http://localhost:8080"
@@ -19,12 +24,11 @@ def test_add_node_success(self):
mock_response = Mock()
mock_response.raise_for_status = Mock()
mock_put.return_value = mock_response
-
+
result = add_node(node, check_mode=False)
self.assertTrue(result["changed"])
self.assertEqual(result["msg"], "Node B added to the cluster")
-
def test_add_node_check_mode(self):
node = {
"url": "http://localhost:8081",
@@ -34,8 +38,7 @@ def test_add_node_check_mode(self):
}
result = add_node(node, check_mode=True)
self.assertTrue(result["changed"])
- self.assertEqual(result["msg"], "Node B would be added to the cluster")
-
+ self.assertEqual(result["msg"], "Node B would be added to the cluster")
def test_add_node_invalid_url(self):
node = {
@@ -46,9 +49,10 @@ def test_add_node_invalid_url(self):
}
result = add_node(node, check_mode=False)
self.assertFalse(result["changed"])
- self.assertEqual(result["msg"], "Invalid URL: must be a valid HTTP(S) URL")
+ self.assertEqual(
+ result["msg"],
+ "Invalid URL: must be a valid HTTP(S) URL")
-
def test_add_node_invalid_tag(self):
node = {
"url": "http://localhost:8081",
@@ -58,7 +62,9 @@ def test_add_node_invalid_tag(self):
}
result = add_node(node, check_mode=False)
self.assertFalse(result["changed"])
- self.assertEqual(result["msg"], "Invalid tag: Node tag must be an uppercase non-empty alphanumeric string")
+ self.assertEqual(
+ result["msg"],
+ "Invalid tag: Node tag must be an uppercase non-empty alphanumeric string")
def test_add_watcher_node(self):
node = {
@@ -71,12 +77,11 @@ def test_add_watcher_node(self):
mock_response = Mock()
mock_response.raise_for_status = Mock()
mock_put.return_value = mock_response
-
+
result = add_node(node, check_mode=False)
self.assertTrue(result["changed"])
self.assertEqual(result["msg"], "Node D added to the cluster")
-
def test_add_already_added_node(self):
node = {
"url": "http://localhost:8081",
@@ -86,15 +91,15 @@ def test_add_already_added_node(self):
}
with patch("requests.put") as mock_put:
mock_response = Mock()
- mock_response.raise_for_status.side_effect = requests.HTTPError("System.InvalidOperationException: Can't add a new node")
+ mock_response.raise_for_status.side_effect = requests.HTTPError(
+ "System.InvalidOperationException: Can't add a new node")
mock_put.return_value = mock_response
-
+
result = add_node(node, check_mode=False)
self.assertFalse(result["changed"])
self.assertIn("Failed to add node A", result["msg"])
-
def test_add_node_with_existing_tag_different_url(self):
node = {
"url": "http://localhost:9090",
@@ -104,13 +109,15 @@ def test_add_node_with_existing_tag_different_url(self):
}
with patch("requests.put") as mock_put:
mock_response = Mock()
- mock_response.raise_for_status.side_effect = requests.HTTPError("System.InvalidOperationException: Was requested to modify the topology for node...")
+ mock_response.raise_for_status.side_effect = requests.HTTPError(
+ "System.InvalidOperationException: Was requested to modify the topology for node...")
mock_put.return_value = mock_response
-
+
result = add_node(node, check_mode=False)
self.assertFalse(result["changed"])
self.assertIn("Failed to add node A", result["msg"])
+
class TestValidationFunctions(TestCase):
def test_valid_url(self):
self.assertTrue(is_valid_url("https://example.com"))
diff --git a/tests/unit/test_database.py b/tests/unit/test_database.py
index 6d069c0..3ba9a08 100644
--- a/tests/unit/test_database.py
+++ b/tests/unit/test_database.py
@@ -1,70 +1,93 @@
-import sys
+# Copyright (c), RavenDB
+# GNU General Public License v3.0 or later (see COPYING or
+# https://www.gnu.org/licenses/gpl-3.0.txt)
+
+import os
from ravendb_test_driver import RavenTestDriver
from unittest import TestCase
-from ansible_collections.ravendb.community.plugins.modules.database import *
+from ansible_collections.ravendb.ravendb.plugins.modules.database import (
+ handle_present_state,
+ handle_absent_state,
+ is_valid_url,
+ is_valid_database_name,
+ is_valid_replication_factor,
+ validate_paths,
+ is_valid_state,
+ is_valid_database_name,
+ is_valid_replication_factor,
+ is_valid_state
+)
+
class TestDBStateValidator(TestCase):
def setUp(self):
- super().setUp()
- self.test_driver = RavenTestDriver()
+ super().setUp()
+ self.test_driver = RavenTestDriver()
def test_create_database(self):
-
- store = self.test_driver.get_document_store(database="test_create_database")
- db_name="test_db"
- replication_factor=1
- check_mode=False
+ store = self.test_driver.get_document_store(
+ database="test_create_database")
+
+ db_name = "test_db"
+ replication_factor = 1
+ check_mode = False
- changed, message = handle_present_state(store, db_name, replication_factor, check_mode)
+ changed, message = handle_present_state(
+ store, db_name, replication_factor, check_mode)
self.assertTrue(changed)
self.assertIn(f"Database '{db_name}' created successfully.", message)
def test_create_already_created_database(self):
-
- store = self.test_driver.get_document_store(database="test_create_already_created_database")
- db_name="test_db1"
- replication_factor=1
- check_mode=False
+ store = self.test_driver.get_document_store(
+ database="test_create_already_created_database")
- changed, message = handle_present_state(store, db_name, replication_factor, check_mode)
- changed, message = handle_present_state(store, db_name, replication_factor, check_mode)
+ db_name = "test_db1"
+ replication_factor = 1
+ check_mode = False
+
+ changed, message = handle_present_state(
+ store, db_name, replication_factor, check_mode)
+ changed, message = handle_present_state(
+ store, db_name, replication_factor, check_mode)
self.assertFalse(changed)
self.assertIn(f"Database '{db_name}' already exists.", message)
-
def test_delete_database(self):
-
- store = self.test_driver.get_document_store(database="test_delete_database")
- db_name="test_db2"
- replication_factor=1
- check_mode=False
+ store = self.test_driver.get_document_store(
+ database="test_delete_database")
- changed, message = handle_present_state(store, db_name, replication_factor, check_mode)
+ db_name = "test_db2"
+ replication_factor = 1
+ check_mode = False
+
+ changed, message = handle_present_state(
+ store, db_name, replication_factor, check_mode)
changed, message = handle_absent_state(store, db_name, check_mode)
self.assertTrue(changed)
self.assertIn(f"Database '{db_name}' deleted successfully.", message)
-
def test_delete_non_exist_database(self):
-
- store = self.test_driver.get_document_store(database="test_delete_non_exist_database")
- db_name="test_db3"
- check_mode=False
+ store = self.test_driver.get_document_store(
+ database="test_delete_non_exist_database")
+
+ db_name = "test_db3"
+ check_mode = False
changed, message = handle_absent_state(store, db_name, check_mode)
self.assertFalse(changed)
self.assertIn(f"Database '{db_name}' does not exist.", message)
+
class TestValidationFunctions(TestCase):
-
+
def test_valid_url(self):
self.assertTrue(is_valid_url("https://example.com"))
self.assertTrue(is_valid_url("http://localhost:8080"))
@@ -90,8 +113,11 @@ def test_valid_certificate_paths(self):
with open("test_ca.pem", "w") as f:
f.write("dummy CA content")
- self.assertEqual(validate_paths("test_cert.pem", "test_ca.pem"), (True, None))
- self.assertEqual(validate_paths("non_existing.pem"), (False, "Path does not exist: non_existing.pem"))
+ self.assertEqual(
+ validate_paths(
+ "test_cert.pem", "test_ca.pem"), (True, None))
+ self.assertEqual(validate_paths("non_existing.pem"),
+ (False, "Path does not exist: non_existing.pem"))
os.remove("test_cert.pem")
os.remove("test_ca.pem")
@@ -100,4 +126,4 @@ def test_valid_state(self):
self.assertTrue(is_valid_state("present"))
self.assertTrue(is_valid_state("absent"))
self.assertFalse(is_valid_state("running"))
- self.assertFalse(is_valid_state(""))
\ No newline at end of file
+ self.assertFalse(is_valid_state(""))
diff --git a/tests/unit/test_index.py b/tests/unit/test_index.py
index 1085b52..092d8ba 100644
--- a/tests/unit/test_index.py
+++ b/tests/unit/test_index.py
@@ -1,54 +1,70 @@
+# Copyright (c), RavenDB
+# GNU General Public License v3.0 or later (see COPYING or
+# https://www.gnu.org/licenses/gpl-3.0.txt)
+
+import os
import sys
from ravendb_test_driver import RavenTestDriver
from unittest import TestCase
-from ansible_collections.ravendb.community.plugins.modules.index import *
+from ansible_collections.ravendb.ravendb.plugins.modules.index import (
+ reconcile_state,
+ is_valid_url,
+ is_valid_name,
+ is_valid_dict,
+ validate_paths,
+ is_valid_state,
+ is_valid_mode,
+ is_valid_bool
+)
from ravendb.documents.operations.indexes import GetIndexesOperation
INDEX_DEFINITION = {
- "map": [
- "from c in docs.Users select new { Name = c.name, UserCount = 1, OrderCount = 0, TotalCount = 1 }"]
- }
+ "map": [
+ "from c in docs.Users select new { Name = c.name, UserCount = 1, OrderCount = 0, TotalCount = 1 }"]
+}
UPDATED_INDEX_DEFINITION = {
- "map": [
- "from c in docs.Users select new { Name = c.name, UserCount = 1, OrderCount = 0, TotalCount = 3 }"]
- }
+ "map": [
+ "from c in docs.Users select new { Name = c.name, UserCount = 1, OrderCount = 0, TotalCount = 3 }"]
+}
MAP_REDUCE_INDEX_DEFINITION = {
- "map": [
- "from c in docs.Users select new { Name = c.name, UserCount = 1, OrderCount = 0, TotalCount = 1 }"],
- "reduce": """
+ "map": [
+ "from c in docs.Users select new { Name = c.name, UserCount = 1, OrderCount = 0, TotalCount = 1 }"],
+ "reduce": """
from result in results
group result by result.Name
into g
- select new
- {
- Name = g.Key,
+ select new
+ {
+ Name = g.Key,
UserCount = g.Sum(x => x.UserCount),
OrderCount = g.Sum(x => x.OrderCount),
TotalCount = g.Sum(x => x.TotalCount)
}
- """
-
+ """
+
}
-MULTI_MAP_INDEX_DEFINITION ={
+MULTI_MAP_INDEX_DEFINITION = {
"map": ["from c in docs.Users select new { Name = c.name, UserCount = 1, OrderCount = 0, TotalCount = 1 }",
"from o in docs.Orders select new { Name = o.customer, UserCount = 0, OrderCount = 1, TotalCount = 1 }"
- ]
+ ]
}
+
class TestReconcileState(TestCase):
index_name = "test/index"
def setUp(self):
- super().setUp()
- self.test_driver = RavenTestDriver()
+ super().setUp()
+ self.test_driver = RavenTestDriver()
def test_create_index(self):
- store = self.test_driver.get_document_store(database="test_create_index")
+ store = self.test_driver.get_document_store(
+ database="test_create_index")
params = {
"database_name": store.database,
@@ -58,13 +74,15 @@ def test_create_index(self):
"cluster_wide": False,
}
- status, changed, message = reconcile_state(store, params, check_mode=False)
+ status, changed, message = reconcile_state(
+ store, params, check_mode=False)
self.assertEqual(status, "ok")
self.assertTrue(changed)
self.assertIn("Index 'test_index' created successfully.", message)
def test_create_already_exists_index(self):
- store = self.test_driver.get_document_store(database="test_create_already_exists_index")
+ store = self.test_driver.get_document_store(
+ database="test_create_already_exists_index")
params = {
"database_name": store.database,
@@ -74,19 +92,21 @@ def test_create_already_exists_index(self):
"cluster_wide": False,
}
- _, changed, message = reconcile_state(store, params, check_mode=False)
+ result, changed, message = reconcile_state(store, params, check_mode=False)
self.assertTrue(changed)
self.assertIn("Index 'myindex' created successfully.", message)
- # self.test_driver.wait_for_user_to_continue_the_test(store)
-
- _, changed, message = reconcile_state(store, params, check_mode=False)
+ # self.test_driver.wait_for_user_to_continue_the_test(store)
+
+ result, changed, message = reconcile_state(store, params, check_mode=False)
self.assertFalse(changed)
- self.assertIn("Index 'myindex' already exists and matches definition.", message)
-
+ self.assertIn(
+ "Index 'myindex' already exists and matches definition.",
+ message)
def test_update_existing_index_with_modified_map(self):
- store = self.test_driver.get_document_store(database="test_update_existing_index_with_modified_map")
+ store = self.test_driver.get_document_store(
+ database="test_update_existing_index_with_modified_map")
params = {
"database_name": store.database,
@@ -96,19 +116,22 @@ def test_update_existing_index_with_modified_map(self):
"cluster_wide": False,
}
- status, changed, message = reconcile_state(store, params, check_mode=False)
+ status, changed, message = reconcile_state(
+ store, params, check_mode=False)
self.assertEqual(status, "ok")
self.assertTrue(changed)
self.assertIn("Index 'test/index' created successfully.", message)
- params["index_definition"]=UPDATED_INDEX_DEFINITION
- status, changed, message = reconcile_state(store, params, check_mode=False)
+ params["index_definition"] = UPDATED_INDEX_DEFINITION
+ status, changed, message = reconcile_state(
+ store, params, check_mode=False)
self.assertEqual(status, "ok")
self.assertTrue(changed)
self.assertIn("Index 'test/index' created successfully.", message)
database_maintenance = store.maintenance.for_database(store.database)
- existing_indexes = database_maintenance.send(GetIndexesOperation(0, sys.maxsize))
+ existing_indexes = database_maintenance.send(
+ GetIndexesOperation(0, sys.maxsize))
index = existing_indexes[0]
existing_maps = list(map(str.strip, index.maps)) if index.maps else []
@@ -117,7 +140,8 @@ def test_update_existing_index_with_modified_map(self):
self.assertEqual(existing_maps[0], expected_map_definition[0])
def test_update_existing_map_index_into_multi_map_index(self):
- store = self.test_driver.get_document_store(database="test_update_existing_map_index_into_multi_map_index")
+ store = self.test_driver.get_document_store(
+ database="test_update_existing_map_index_into_multi_map_index")
params = {
"database_name": store.database,
@@ -127,30 +151,34 @@ def test_update_existing_map_index_into_multi_map_index(self):
"cluster_wide": False,
}
- status, changed, message = reconcile_state(store, params, check_mode=False)
+ status, changed, message = reconcile_state(
+ store, params, check_mode=False)
self.assertEqual(status, "ok")
self.assertTrue(changed)
self.assertIn("Index 'test/index' created successfully.", message)
- params["index_definition"]=MULTI_MAP_INDEX_DEFINITION
- status, changed, message = reconcile_state(store, params, check_mode=False)
+ params["index_definition"] = MULTI_MAP_INDEX_DEFINITION
+ status, changed, message = reconcile_state(
+ store, params, check_mode=False)
self.assertEqual(status, "ok")
self.assertTrue(changed)
self.assertIn("Index 'test/index' created successfully.", message)
database_maintenance = store.maintenance.for_database(store.database)
- existing_indexes = database_maintenance.send(GetIndexesOperation(0, sys.maxsize))
+ existing_indexes = database_maintenance.send(
+ GetIndexesOperation(0, sys.maxsize))
index = existing_indexes[0]
- existing_maps = sorted(list(map(str.strip, index.maps)) if index.maps else [])
+ existing_maps = sorted(
+ list(map(str.strip, index.maps)) if index.maps else [])
expected_map_definition = sorted(MULTI_MAP_INDEX_DEFINITION["map"])
-
+
self.assertEqual(existing_maps[0], expected_map_definition[0])
self.assertEqual(existing_maps[1], expected_map_definition[1])
-
def test_update_existing_map_index_into_map_reduce_index(self):
- store = self.test_driver.get_document_store(database="test_update_existing_map_index_into_map_reduce_index")
+ store = self.test_driver.get_document_store(
+ database="test_update_existing_map_index_into_map_reduce_index")
params = {
"database_name": store.database,
@@ -160,32 +188,36 @@ def test_update_existing_map_index_into_map_reduce_index(self):
"cluster_wide": False,
}
- status, changed, message = reconcile_state(store, params, check_mode=False)
+ status, changed, message = reconcile_state(
+ store, params, check_mode=False)
self.assertEqual(status, "ok")
self.assertTrue(changed)
self.assertIn("Index 'test/index' created successfully.", message)
- params["index_definition"]=MAP_REDUCE_INDEX_DEFINITION
- status, changed, message = reconcile_state(store, params, check_mode=False)
+ params["index_definition"] = MAP_REDUCE_INDEX_DEFINITION
+ status, changed, message = reconcile_state(
+ store, params, check_mode=False)
self.assertEqual(status, "ok")
self.assertTrue(changed)
self.assertIn("Index 'test/index' created successfully.", message)
database_maintenance = store.maintenance.for_database(store.database)
- existing_indexes = database_maintenance.send(GetIndexesOperation(0, sys.maxsize))
+ existing_indexes = database_maintenance.send(
+ GetIndexesOperation(0, sys.maxsize))
index = existing_indexes[0]
existing_maps = list(map(str.strip, index.maps)) if index.maps else []
existing_reduce = getattr(index, 'reduce', None)
expected_map_definition = MAP_REDUCE_INDEX_DEFINITION["map"]
- expected_redcue_definition=MAP_REDUCE_INDEX_DEFINITION["reduce"]
+ expected_redcue_definition = MAP_REDUCE_INDEX_DEFINITION["reduce"]
self.assertEqual(existing_maps[0], expected_map_definition[0])
self.assertEqual(existing_reduce, expected_redcue_definition)
def test_delete_index(self):
- store = self.test_driver.get_document_store(database="test_delete_index")
+ store = self.test_driver.get_document_store(
+ database="test_delete_index")
params = {
"database_name": store.database,
@@ -195,19 +227,22 @@ def test_delete_index(self):
"cluster_wide": False,
}
- status, changed, message = reconcile_state(store, params, check_mode=False)
+ status, changed, message = reconcile_state(
+ store, params, check_mode=False)
self.assertEqual(status, "ok")
self.assertTrue(changed)
self.assertIn("Index 'test/index' created successfully.", message)
- params["state"]="absent"
- status, changed, message = reconcile_state(store, params, check_mode=False)
+ params["state"] = "absent"
+ status, changed, message = reconcile_state(
+ store, params, check_mode=False)
self.assertEqual(status, "ok")
self.assertTrue(changed)
self.assertIn("Index 'test/index' deleted successfully.", message)
- def test_delete_nonexistent_index (self):
- store = self.test_driver.get_document_store(database="test_delete_nonexistent_index")
+ def test_delete_nonexistent_index(self):
+ store = self.test_driver.get_document_store(
+ database="test_delete_nonexistent_index")
params = {
"database_name": store.database,
@@ -217,15 +252,16 @@ def test_delete_nonexistent_index (self):
"cluster_wide": False,
}
- params["state"]="absent"
- status, changed, message = reconcile_state(store, params, check_mode=False)
+ params["state"] = "absent"
+ status, changed, message = reconcile_state(
+ store, params, check_mode=False)
self.assertEqual(status, "ok")
self.assertFalse(changed)
self.assertIn("Index 'test/index' is already absent.", message)
class TestValidationFunctions(TestCase):
-
+
def test_valid_url(self):
self.assertTrue(is_valid_url("https://example.com"))
self.assertTrue(is_valid_url("http://localhost:8080"))
@@ -256,8 +292,11 @@ def test_valid_certificate_paths(self):
with open("test_ca.pem", "w") as f:
f.write("dummy CA content")
- self.assertEqual(validate_paths("test_cert.pem", "test_ca.pem"), (True, None))
- self.assertEqual(validate_paths("non_existing.pem"), (False, "Path does not exist: non_existing.pem"))
+ self.assertEqual(
+ validate_paths(
+ "test_cert.pem", "test_ca.pem"), (True, None))
+ self.assertEqual(validate_paths("non_existing.pem"),
+ (False, "Path does not exist: non_existing.pem"))
os.remove("test_cert.pem")
os.remove("test_ca.pem")
@@ -281,4 +320,4 @@ def test_valid_cluster_wide(self):
self.assertTrue(is_valid_bool(True))
self.assertTrue(is_valid_bool(False))
self.assertFalse(is_valid_bool(1))
- self.assertFalse(is_valid_bool("true"))
\ No newline at end of file
+ self.assertFalse(is_valid_bool("true"))
diff --git a/tests/unit/test_index_modes.py b/tests/unit/test_index_modes.py
index 1d7076e..b2e3e14 100644
--- a/tests/unit/test_index_modes.py
+++ b/tests/unit/test_index_modes.py
@@ -1,6 +1,14 @@
-from ansible_collections.ravendb.community.plugins.modules.index import (
- enable_index, disable_index, resume_index, pause_index, reset_index, create_dynamic_index
-)
+# Copyright (c), RavenDB
+# GNU General Public License v3.0 or later (see COPYING or
+# https://www.gnu.org/licenses/gpl-3.0.txt)
+
+from ansible_collections.ravendb.ravendb.plugins.modules.index import (
+ enable_index,
+ disable_index,
+ resume_index,
+ pause_index,
+ reset_index,
+ create_dynamic_index)
from ravendb_test_driver import RavenTestDriver
from unittest import TestCase
from ravendb.documents.indexes.definitions import IndexRunningStatus
@@ -9,121 +17,149 @@
class TestIndexModes(TestCase):
- index_name = "TestIndex"
- index_definition = {
- "map": [
- "from c in docs.Users select new { c.name, count = 1 }"
- ],
- "reduce": """
+ index_name = "TestIndex"
+ index_definition = {
+ "map": [
+ "from c in docs.Users select new { c.name, count = 1 }"
+ ],
+ "reduce": """
from result in results
- group result by result.name
- into g
- select new
- {
- name = g.Key,
- count = g.Sum(x => x.count)
+ group result by result.name
+ into g
+ select new
+ {
+ name = g.Key,
+ count = g.Sum(x => x.count)
}
"""
- }
+ }
- def setUp(self):
- super().setUp()
- self.test_driver = RavenTestDriver()
+ def setUp(self):
+ super().setUp()
+ self.test_driver = RavenTestDriver()
- def create_and_execute_index(self, store):
- DynamicIndexClass = create_dynamic_index(self.index_name, self.index_definition)
+ def create_and_execute_index(self, store):
+ DynamicIndexClass = create_dynamic_index(
+ self.index_name, self.index_definition)
index = DynamicIndexClass()
index.execute(store, store.database)
- def test_disable_index(self):
- cls=self.__class__
- store=self.test_driver.get_document_store(database="test_disable_index")
- self.create_and_execute_index(store)
-
- status, changed, message = disable_index(store, cls.index_name, cluster_wide=False, check_mode=False)
- self.assertEqual(status, "ok")
- self.assertTrue(changed)
- self.assertIn(f"Index '{cls.index_name}' disbaled successfully", message)
-
- def test_enable_index(self):
- cls=self.__class__
- store=self.test_driver.get_document_store(database="test_enable_index")
- self.create_and_execute_index(store)
-
- status, changed, message = disable_index(store, cls.index_name, cluster_wide=False, check_mode=False)
- status, changed, message = enable_index(store, cls.index_name, cluster_wide=False, check_mode=False)
- self.assertEqual(status, "ok")
- self.assertTrue(changed)
- self.assertIn(f"Index '{cls.index_name}' enabled successfully", message)
-
-
- def test_pause_index(self):
- cls=self.__class__
- store=self.test_driver.get_document_store(database="test_pause_index")
- self.create_and_execute_index(store)
-
- resume_index(store, cls.index_name, check_mode=False)
- status, changed, message = pause_index(store, cls.index_name, check_mode=False)
- self.assertEqual(status, "ok")
- self.assertTrue(changed)
- self.assertIn(f"Index '{cls.index_name}' paused successfully", message)
-
- indexing_status = store.maintenance.send(GetIndexingStatusOperation())
- paused_index = [x for x in indexing_status.indexes if x.name == cls.index_name][0]
- self.assertEqual(paused_index.status, IndexRunningStatus.PAUSED)
-
- def test_pause_already_paused_index(self):
- cls=self.__class__
- store=self.test_driver.get_document_store(database="test_pause_already_paused_index")
- self.create_and_execute_index(store)
-
- pause_index(store, cls.index_name, check_mode=False)
- status, changed, message = pause_index(store, cls.index_name, check_mode=False)
- self.assertEqual(status, "ok")
- self.assertFalse(changed)
- self.assertIn(f"Index '{cls.index_name}' is already paused", message)
-
- indexing_status = store.maintenance.send(GetIndexingStatusOperation())
- paused_index = [x for x in indexing_status.indexes if x.name == cls.index_name][0]
- self.assertEqual(paused_index.status, IndexRunningStatus.PAUSED)
-
- def test_resume_index(self):
- cls=self.__class__
- store=self.test_driver.get_document_store(database="test_resume_index")
- self.create_and_execute_index(store)
-
- pause_index(store, cls.index_name, check_mode=False)
- status, changed, message = resume_index(store, cls.index_name, check_mode=False)
- self.assertEqual(status, "ok")
- self.assertTrue(changed)
- self.assertIn(f"Index '{cls.index_name}' resumed successfully", message)
-
- indexing_status = store.maintenance.send(GetIndexingStatusOperation())
- resumed_index = [x for x in indexing_status.indexes if x.name == cls.index_name][0]
- self.assertEqual(resumed_index.status, IndexRunningStatus.RUNNING)
-
- def test_resume_already_resumed_index(self):
- cls=self.__class__
- store=self.test_driver.get_document_store(database="test_resume_already_resumed_index")
- self.create_and_execute_index(store)
-
- status, changed, message = resume_index(store, cls.index_name, check_mode=False)
-
- status, changed, message = resume_index(store, cls.index_name, check_mode=False)
- self.assertEqual(status, "ok")
- self.assertFalse(changed)
- self.assertIn(f"Index '{cls.index_name}' is already resumed and executing", message)
-
- indexing_status = store.maintenance.send(GetIndexingStatusOperation())
- resumed_index = [x for x in indexing_status.indexes if x.name == cls.index_name][0]
- self.assertEqual(resumed_index.status, IndexRunningStatus.RUNNING)
-
- def test_reset_index(self):
- cls=self.__class__
- store=self.test_driver.get_document_store(database="test_reset_index")
- self.create_and_execute_index(store)
-
- status, changed, message = reset_index(store, cls.index_name, check_mode=False)
- self.assertEqual(status, "ok")
- self.assertTrue(changed)
- self.assertIn(f"Index '{cls.index_name}' reset successfully", message)
+ def test_disable_index(self):
+ cls = self.__class__
+ store = self.test_driver.get_document_store(
+ database="test_disable_index")
+ self.create_and_execute_index(store)
+
+ status, changed, message = disable_index(
+ store, cls.index_name, cluster_wide=False, check_mode=False)
+ self.assertEqual(status, "ok")
+ self.assertTrue(changed)
+ self.assertIn(
+ f"Index '{cls.index_name}' disbaled successfully",
+ message)
+
+ def test_enable_index(self):
+ cls = self.__class__
+ store = self.test_driver.get_document_store(
+ database="test_enable_index")
+ self.create_and_execute_index(store)
+
+ status, changed, message = disable_index(
+ store, cls.index_name, cluster_wide=False, check_mode=False)
+ status, changed, message = enable_index(
+ store, cls.index_name, cluster_wide=False, check_mode=False)
+ self.assertEqual(status, "ok")
+ self.assertTrue(changed)
+ self.assertIn(
+ f"Index '{cls.index_name}' enabled successfully",
+ message)
+
+ def test_pause_index(self):
+ cls = self.__class__
+ store = self.test_driver.get_document_store(
+ database="test_pause_index")
+ self.create_and_execute_index(store)
+
+ resume_index(store, cls.index_name, check_mode=False)
+ status, changed, message = pause_index(
+ store, cls.index_name, check_mode=False)
+ self.assertEqual(status, "ok")
+ self.assertTrue(changed)
+ self.assertIn(f"Index '{cls.index_name}' paused successfully", message)
+
+ indexing_status = store.maintenance.send(GetIndexingStatusOperation())
+ paused_index = [
+ x for x in indexing_status.indexes if x.name == cls.index_name][0]
+ self.assertEqual(paused_index.status, IndexRunningStatus.PAUSED)
+
+ def test_pause_already_paused_index(self):
+ cls = self.__class__
+ store = self.test_driver.get_document_store(
+ database="test_pause_already_paused_index")
+ self.create_and_execute_index(store)
+
+ pause_index(store, cls.index_name, check_mode=False)
+ status, changed, message = pause_index(
+ store, cls.index_name, check_mode=False)
+ self.assertEqual(status, "ok")
+ self.assertFalse(changed)
+ self.assertIn(f"Index '{cls.index_name}' is already paused", message)
+
+ indexing_status = store.maintenance.send(GetIndexingStatusOperation())
+ paused_index = [
+ x for x in indexing_status.indexes if x.name == cls.index_name][0]
+ self.assertEqual(paused_index.status, IndexRunningStatus.PAUSED)
+
+ def test_resume_index(self):
+ cls = self.__class__
+ store = self.test_driver.get_document_store(
+ database="test_resume_index")
+ self.create_and_execute_index(store)
+
+ pause_index(store, cls.index_name, check_mode=False)
+ status, changed, message = resume_index(
+ store, cls.index_name, check_mode=False)
+ self.assertEqual(status, "ok")
+ self.assertTrue(changed)
+ self.assertIn(
+ f"Index '{cls.index_name}' resumed successfully",
+ message)
+
+ indexing_status = store.maintenance.send(GetIndexingStatusOperation())
+ resumed_index = [
+ x for x in indexing_status.indexes if x.name == cls.index_name][0]
+ self.assertEqual(resumed_index.status, IndexRunningStatus.RUNNING)
+
+ def test_resume_already_resumed_index(self):
+ cls = self.__class__
+ store = self.test_driver.get_document_store(
+ database="test_resume_already_resumed_index")
+ self.create_and_execute_index(store)
+
+ status, changed, message = resume_index(
+ store, cls.index_name, check_mode=False)
+
+ status, changed, message = resume_index(
+ store, cls.index_name, check_mode=False)
+ self.assertEqual(status, "ok")
+ self.assertFalse(changed)
+ self.assertIn(
+ f"Index '{cls.index_name}' is already resumed and executing",
+ message)
+
+ indexing_status = store.maintenance.send(GetIndexingStatusOperation())
+ resumed_index = [
+ x for x in indexing_status.indexes if x.name == cls.index_name][0]
+ self.assertEqual(resumed_index.status, IndexRunningStatus.RUNNING)
+
+ def test_reset_index(self):
+ cls = self.__class__
+ store = self.test_driver.get_document_store(
+ database="test_reset_index")
+ self.create_and_execute_index(store)
+
+ status, changed, message = reset_index(
+ store, cls.index_name, check_mode=False)
+ self.assertEqual(status, "ok")
+ self.assertTrue(changed)
+ self.assertIn(f"Index '{cls.index_name}' reset successfully", message)