From dbb64be223784a727386b08915aa956016504b60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Orduna=20Le=C3=B3n?= Date: Mon, 25 Mar 2024 16:27:20 +0100 Subject: [PATCH] feat: initial commit --- .github/workflows/ci.yml | 22 ++++++++++++++++++ .github/workflows/release.yml | 20 ++++++++++++++++ .yamllint | 7 ++++++ README.md | 37 ++++++++++++++++++++++++++++++ defaults/main.yml | 5 ++++ handlers/main.yml | 5 ++++ meta/main.yml | 20 ++++++++++++++++ tasks/main.yml | 43 +++++++++++++++++++++++++++++++++++ vars/main.yml | 8 +++++++ 9 files changed, 167 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml create mode 100644 .yamllint create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/main.yml create mode 100644 vars/main.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2b42698 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,22 @@ +--- +name: CI + +'on': + pull_request: + push: + branches: + - main + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Check out codebase. + uses: actions/checkout@v4 + + - name: Run ansible-lint + uses: ansible/ansible-lint@main + + - name: Run yamllint + uses: frenck/action-yamllint@v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..0712c00 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,20 @@ +--- +name: Release + +'on': + push: + tags: + - '*' + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Check out codebase. + uses: actions/checkout@v4 + + - name: galaxy + uses: robertdebock/galaxy-action@1.2.0 + with: + galaxy_api_key: ${{ secrets.GALAXY_API_KEY }} diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..15a72c1 --- /dev/null +++ b/.yamllint @@ -0,0 +1,7 @@ +--- +extends: default + +rules: + line-length: + max: 120 + level: warning diff --git a/README.md b/README.md new file mode 100644 index 0000000..de695ea --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# Podman Install + +Ansible role to install podman on Debian based distros using [home:alvistack](https://build.opensuse.org/project/show/home:alvistack) repository. + +## Requirements + +None. + +## Role Variables + +Available variables are listed below, along with default values (see [defaults/main.yml](defaults/main.yml)): + +| Variable | Description | Default value | +| ------------------------- | ------------------------------------------------- | ------------- | +| `podman_install_packages` | List of packages to be installed within the role. | `["podman"]` | +| `podman_service_state` | Podman service's state after role execution. | `started` | +| `podman_service_enabled` | Wheter to enable podman service at boot. | `true` | + +## Dependencies + +None. + +## Example Playbook + +```yaml +- hosts: servers + vars: + podman_install_packages: + - podman>=4.4 + - crun + roles: + - alorle.podman_install +``` + +## License + +MIT diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..40d8906 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,5 @@ +--- +podman_install_packages: + - podman +podman_service_state: started +podman_service_enabled: true diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..2079005 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: Restart podman + ansible.builtin.service: + name: podman.service + state: restarted diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..e0866ab --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,20 @@ +--- +galaxy_info: + role_name: podman_install + namespace: alorle + author: Álvaro Orduna León + description: Ansible Role for Podman Installation on Debian distributions + license: license MIT + min_ansible_version: "2.1" + platforms: + - name: Ubuntu + versions: + - all + - name: Debian + versions: + - all + galaxy_tags: + - system + - podman + - debian + - ubuntu diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..cd8f8ac --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,43 @@ +--- +- name: Ensure os family is Debian. + ansible.builtin.assert: + that: "ansible_os_family =='Debian'" + +- name: Define repository base path. + block: + - name: Define Ubuntu repository base path. + ansible.builtin.set_fact: + repository_base_path: "xUbunut_{{ ansible_facts.distribution_version }}" + when: ansible_facts.distribution == "Ubuntu" + - name: Define Debian repository base path. + ansible.builtin.set_fact: + repository_base_path: "Debian_{{ ansible_facts.distribution_major_version }}" + when: ansible_facts.distribution != "Ubuntu" + +- name: Ensure apt key is installed. + ansible.builtin.apt_key: + id: "{{ podman_apt_key.id | default(omit) }}" + url: "{{ podman_apt_key.url }}" + keyring: "{{ podman_apt_key.keyring }}" + state: "{{ podman_apt_key.state | default('present') }}" + +- name: Ensure apt repository file is present. + ansible.builtin.apt_repository: + filename: "{{ podman_apt_repository.filename }}" + repo: "{{ podman_apt_repository.repo }}" + mode: "{{ podman_apt_repository.mode | default('0644') }}" + state: "{{ podman_apt_repository.state | default('present') }}" + +- name: Ensure apt packages are installed. + ansible.builtin.package: + name: "{{ item }}" + state: present + loop: "{{ podman_install_packages }}" + notify: Restart podman + +- name: Ensure podman is started and enabled at boot. + ansible.builtin.service: + name: podman + state: "{{ podman_service_state }}" + enabled: "{{ podman_service_enabled }}" + ignore_errors: "{{ ansible_check_mode }}" diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..70378ac --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,8 @@ +--- +podman_apt_key: + keyring: /etc/apt/trusted.gpg.d/home_alvistack.gpg + url: http://downloadcontent.opensuse.org/repositories/home:/alvistack/{{ repository_base_path }}/Release.key + +podman_apt_repository: + filename: home:alvistack + repo: deb http://downloadcontent.opensuse.org/repositories/home:/alvistack/{{ repository_base_path }}/ /