ansible / proposals

Repository for sharing and tracking progress on enhancement proposals for Ansible.
Creative Commons Zero v1.0 Universal
92 stars 19 forks source link

clone_packages - module (apt-clone) #180

Closed jifox closed 4 years ago

jifox commented 4 years ago

Proposal: clone_packages - module

Author: Josef Fuchs @jifox

Date: 2020-06-28

Motivation

I need to hold an ubuntu server cluster in sync. Therfore it is essential to have the same software versions installed on all servers. Also updating one system leads to the problem to replicate all the updates.

Problems

Solution proposal

    - name: Read all installed packages from current server and save as local file.
      clone_packages:
         action: clone
         dest: "~/common_software_packages_for_cluster.tar.gz"
      when: is_source_of_truth

    - name: list all packages within locally saved file
      clone_packages:
         action: info
         src: "~/common_software_packages_for_cluster.tar.gz"
      register: res_package_list
      when: is_source_of_truth

    - name: Install all packages with same version from locally saved file
      clone_packages:
         action: restore
         src: "~/common_software_packages_for_cluster.tar.gz"
      register: res_clone_packages
      when: not is_source_of_truth

    - name: Display result
      debug: |
          reboot_required:  {{ res_clone_packages.reboot_required }}
          list_of_changes: {{ res_clone_packages.changed_packages }}

    - name: Show differences
      clone_packages:
         action: restore
         src: "~/common_software_packages_for_cluster.tar.gz"
      check_mode: yes
      when: not is_source_of_truth

Anything else?

It would be nice to see in the result if a reboot is required after the updates

bcoca commented 4 years ago

You can already make mostly the same thing getting the info via package_facts and then feeding to apt/yum/supported package manager. I prefer this as it allows the same functionality independent of specific OS/package format tool.

jifox commented 4 years ago

@bcoca Thanks for the hint, I'll going to use the package_facts.