-
-
Notifications
You must be signed in to change notification settings - Fork 492
Collection structure migration #903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@vitabaks While this is labelled "WIP", I am waiting for a comment of yours here before doing additional work. In the end, you must work with it :) (and it would also be great if I wouldn't need to do all the refactoring myself). Let me know what you think. |
I’m still unsure about this because I don’t see much benefit in it, but at the same time, I recognize how important it is to you and possibly to others as well. I’ve reread it multiple times to think it through. As I understand it, you’re suggesting wrapping the playbook functionality into a role that calls other roles, similar to how playbooks previously worked, so that the playbook can be executed as a role. However, I’m not a fan of duplicating variables. Previously, the vars directory served as a single point for parameter management, but now it would need to be duplicated for each playbook role. Another important consideration is that the number of playbooks will continue to grow—for example, I’ll soon be adding playbooks for scaling the etcd cluster. |
Probably, also given the discussion has already 6 upvotes. I'd argue that for all folks using ansible in a professional way, having a "sound" role/collection structure is very important.
Essentially, yes. There would be other ways also but this would result in even more file movements. I actually think it is a quite elegant way given the current structure and doesn't result in too much disturbance.
This is true but the main reason for that is that you're overusing roles in general. Many of the roles should be actually tasks within a role. Only the (currently) user-facing playbooks should be roles IMO, everything else should be tasks. In this structure, the duplication of vars/ would be reduced.
Yeah but this would happen anyhow, wouldn't it? I.e. no matter if its a role or a task, the amount of YAML files is independent from it. Essentially it is up to you how much content and tasks you put into one. In the end, it is only about file organization. A big upside to me is the fact that Again, this is just a suggestion which would make it a lot easier for users and make the project look more "professional" as it adheres to a "best practice" ansible structure. This would also allow publishing an official collection on Ansible Galaxy and making it easier to use for people preferring the "command line" approach. |
I'm not an Ansible expert, I'm an expert in Postgres databases, so I'm interested in help achieving this. P.S. Maybe you have ideas on how to avoid duplicating defaults for each paybooks-role, maybe publish them in group_vars? |
I just skimmed over it quickly. There each role seems to have a In general, there shouldn't be any The problem with In your case here, you have super many tasks which are split and re-used throughout different actions. Placing them in their own roles to have a good structure is fine, but it should be publicly stated in the README (or by using a prefix) that only specific ones should be "executed" and others are essentially just "helper" roles. This is why I used the Overall, Ansible allows for many structures (on a technical level) to work. This is both good and bad, as when starting out with a non-standard one, it will work (somehow) but will have its drawbacks. As a user, you usually want to be able to call a role "as-is" and only specify variables which diverge from the defaults (either in
I guess most collections simply adhere to the recommended structures. Not so many need that amount of helper roles as yours does, so often enough, all roles in a collection are actually "callable" by the user. A totally different approach would be to keep the playbooks as is and force users to call them via This approach has the downside that users cannot directly use their own playbook to just call a role but they are forced to call The upside (in your specific case) would be to not having to rewrite your playbooks into roles. |
Using the |
OK. I think the best middleway might be to stick with the playbooks and only move |
@vitabaks This new structure now works allows users to
On the user level, setting custom vars in Users also need to set the The probably trickiest part are your custom [master:vars]
is_master=true
[replica:vars]
is_master=false I added In summary:
- name: Playbook
hosts: etcd_cluster # or other group name
tasks:
- name: Run playbook
ansible.builtin.include_playbook: autobase.autobase.configure_pgcluster |
Co-authored-by: Artem Safiiulin <[email protected]>
I'm thinking of getting rid of the is_master variable in favor of conditions for host groups, this will simplify the configuration. when: inventory_hostname == groups['master'][0] when: inventory_hostname in groups['replica'] |
Yes, this should simplify this and remove the need for the custom inventory entry. |
Btw there is also this GHA here to automatically publish a collection for releases. HTH in case there are issues/questions. |
Indeed, listing all available playbooks including a short description when to use which would be very helpful. Do you want to do this including additional cleanup? From my side, the PR is ready. |
remove "via git"
Thanks for cleaning up and finishing the remaining tasks. You might wanna consider using https://github.com/buluma/ansible_galaxy_collection or a similar action to automate deployments to Ansible Galaxy for every |
I'll take a look at it, thanks. So far, I have manually uploaded for version 2.2.0 -> https://galaxy.ansible.com/ui/repo/published/vitabaks/autobase/ @pat-s Everything seems to be in order, could you also test it? |
I've been using this structure in my envs since I opened the PR. So you can consider it to be tested. Anything that comes up afterwards can also be fixed in subsequent patch PRs. Good thing this is happening overall, I think it's a big day for this project 👍️ |
ref #272
Changes
defaults/
inventory
-> Should be defined by users in the global inventoryconfig_pbcluster.yml
playbook into a role nameduser_pgcluster_config
group_vars
. Vars should be defined in the global user inventoryAdvantages
group_vars
. This allows for a much better overview which variables have been altered in contrast to the defaultsrequirements.yml
and installed viaansible-galaxy
(when published there)Include main variables
and similar tasks as these are implicitly defined indefaults/
Notes
I only converted
config_pbcluster.yml
. All other "action" playbooks can/should be converted in the same way.The naming of the new role is arbitrary, I only used a prefix to distinguish it somehow from the roles which should not be applied directly. Feel free to propose a another naming scheme.
I've successfully applied this new structure in a test project. It yields the same results as when applying the current playbook
config_pbcluster.yml
. Nevertheless, a thorough check/review should be applied, given all the changes and restructurings.The migration of
vars/
intodefaults/
must happen for every role which should be applied by the user as otherwise these are not defined. If they stay invars/
, they will override user-definedgroup_vars
due to Ansible variable precedence. This is the only downside I currently see, but during development, you should be able to use a global replace-all to modify all redundant entries in thedefaults/
files.UPD: #903 (comment)