From 4b33d2fe5de15c64325ce80cde048c3694c81d71 Mon Sep 17 00:00:00 2001 From: Bertrand Lanson Date: Wed, 5 Apr 2023 22:37:40 +0200 Subject: [PATCH] found a better way to install repo and packages using core roles --- defaults/main.yml | 1 - meta/main.yml | 75 ++++++++++--------------------- meta/requirements.yml | 5 +++ molecule/default/requirements.yml | 3 ++ {vars => tasks}/configure.yml | 0 tasks/install.yml | 7 +++ tasks/main.yml | 8 ++++ tasks/prerequisites.yml | 9 ++++ vars/install.yml | 2 - vars/main.yml | 27 +++++++++++ vars/prerequisites.yml | 2 - 11 files changed, 83 insertions(+), 56 deletions(-) create mode 100644 meta/requirements.yml create mode 100644 molecule/default/requirements.yml rename {vars => tasks}/configure.yml (100%) create mode 100644 tasks/install.yml create mode 100644 tasks/prerequisites.yml delete mode 100644 vars/install.yml delete mode 100644 vars/prerequisites.yml diff --git a/defaults/main.yml b/defaults/main.yml index 4d9f1d7..77686c3 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -2,7 +2,6 @@ # defaults file for install_docker install_docker_edition: ce # can be ce or ee (community or enterprise) install_docker_compose: false -install_docker_version: latest install_docker_compose_version: latest install_docker_start_service: true install_docker_python_packages: true diff --git a/meta/main.yml b/meta/main.yml index e53d671..57edcfa 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,53 +1,26 @@ +--- +# meta file for install_docker galaxy_info: - author: your name - namespace: ednxzu - description: your role description - company: your company (optional) + namespace: 'ednxzu' + role_name: 'install_docker' + author: 'Bertrand Lanson' + description: 'Install and configure docker for debian-based distros.' + license: 'license (BSD, MIT)' + min_ansible_version: '2.10' + platforms: + - name: Ubuntu + versions: + - focal + - jammy + - name: Debian + versions: + - bullseye + galaxy_tags: + - 'ubuntu' + - 'debian' + - 'docker' + - 'container' + - 'compose' + - 'containerd' - # If the issue tracker for your role is not on github, uncomment the - # next line and provide a value - # issue_tracker_url: http://example.com/issue/tracker - - # Choose a valid license ID from https://spdx.org - some suggested licenses: - # - BSD-3-Clause (default) - # - MIT - # - GPL-2.0-or-later - # - GPL-3.0-only - # - Apache-2.0 - # - CC-BY-4.0 - license: license (GPL-2.0-or-later, MIT, etc) - - min_ansible_version: 2.1 - - # If this a Container Enabled role, provide the minimum Ansible Container version. - # min_ansible_container_version: - - # - # Provide a list of supported platforms, and for each platform a list of versions. - # If you don't wish to enumerate all versions for a particular platform, use 'all'. - # To view available platforms and versions (or releases), visit: - # https://galaxy.ansible.com/api/v1/platforms/ - # - # platforms: - # - name: Fedora - # versions: - # - all - # - 25 - # - name: SomePlatform - # versions: - # - all - # - 1.0 - # - 7 - # - 99.99 - - galaxy_tags: [] - # List tags for your role here, one per line. A tag is a keyword that describes - # and categorizes the role. Users find roles by searching for tags. Be sure to - # remove the '[]' above, if you add tags to this list. - # - # NOTE: A tag is limited to a single word comprised of alphanumeric characters. - # Maximum 20 tags per role. - -dependencies: [] - # List your role dependencies here, one per line. Be sure to remove the '[]' above, - # if you add dependencies to this list. +dependencies: [] \ No newline at end of file diff --git a/meta/requirements.yml b/meta/requirements.yml new file mode 100644 index 0000000..0ad83a8 --- /dev/null +++ b/meta/requirements.yml @@ -0,0 +1,5 @@ +--- +# meta file for install_docker +roles: + - name: ednxzu.manage_repositories + - name: ednxzu.manage_apt_packages diff --git a/molecule/default/requirements.yml b/molecule/default/requirements.yml new file mode 100644 index 0000000..91e6923 --- /dev/null +++ b/molecule/default/requirements.yml @@ -0,0 +1,3 @@ +roles: + - name: ednxzu.manage_repositories + - name: ednxzu.manage_apt_packages diff --git a/vars/configure.yml b/tasks/configure.yml similarity index 100% rename from vars/configure.yml rename to tasks/configure.yml diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..a578475 --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,7 @@ +--- +# task/install file for install_docker +- name: "Install docker packages" + ansible.builtin.include_role: + name: ednxzu.manage_apt_packages + vars: + manage_apt_packages_list: "{{ install_docker_packages }}" diff --git a/tasks/main.yml b/tasks/main.yml index f423812..88c14bf 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,10 @@ --- # task/main file for install_docker +- name: "Import prerequisites.yml" + ansible.builtin.include_tasks: prerequisites.yml + +- name: "Import install.yml" + ansible.builtin.include_tasks: install.yml + +- name: "Import configure.yml" + ansible.builtin.include_tasks: configure.yml \ No newline at end of file diff --git a/tasks/prerequisites.yml b/tasks/prerequisites.yml new file mode 100644 index 0000000..8bc845d --- /dev/null +++ b/tasks/prerequisites.yml @@ -0,0 +1,9 @@ +--- +# task/prerequisites file for install_docker +- name: "Configure docker repository" + ansible.builtin.include_role: + name: ednxzu.manage_repositories + vars: + manage_repositories_enable_default_repo: false + manage_repositories_enable_custom_repo: true + manage_repositories_custom_repo: "{{ install_docker_repository }}" \ No newline at end of file diff --git a/vars/install.yml b/vars/install.yml deleted file mode 100644 index 558cedb..0000000 --- a/vars/install.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# task/install file for install_docker \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml index 9141382..14585f5 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,29 @@ --- # vars file for install_docker +install_docker_packages: + - name: "docker-{{ install_docker_edition }}" + version: latest + state: present + - name: "docker-{{ install_docker_edition }}-cli" + version: latest + state: present + - name: "docker-{{ install_docker_edition }}-rootless-extras" + version: latest + state: present + - name: "containerd.io" + version: latest + state: present + +install_docker_compose_packages: + - name: + version: + state: "{{ 'present' if install_docker_compose else 'absent' }}" + +install_docker_repository: + - uri: "https://download.docker.com/linux/{{ ansible_distribution|lower }}" + gpg_key: "https://download.docker.com/linux/{{ ansible_distribution|lower }}/gpg" + comments: "ubuntu docker repository" + type: "deb" + suites: "{{ ansible_distribution_release }}" + components: "stable" + filename: "docker" diff --git a/vars/prerequisites.yml b/vars/prerequisites.yml deleted file mode 100644 index 4609f11..0000000 --- a/vars/prerequisites.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# task/prerequisites file for install_docker \ No newline at end of file