diff --git a/defaults/main.yml b/defaults/main.yml index d1e4f9f129957ab545fc880a9e249f242e0b3bf9..9f1f28de74b56e08b8c74735c5c622d2506dc464 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,3 +1 @@ -ansible_prerequirements_packages: - - python - - lsb-release +minimal_ansible_version: 2.10.2 diff --git a/tasks/main.yml b/tasks/main.yml index e12705c0c570bb1bb9a86f066e8dea6688bc85ca..41fe71991d49aa56eb5d80b0a093a6419a055a28 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,13 +1,39 @@ -- name: PREREQUIREMENTS | Update package index - raw: pacman -Sy - register: command_res +- name: "Check local ansible version >= {{ minimal_ansible_version }}" + delegate_to: localhost + vars: + ansible_connection: local + run_once: true + assert: + msg: "Ansible must be {{ minimal_ansible_version }} or higher" + that: + - ansible_version.string is version(minimal_ansible_version, ">=") + +- name: PREREQUIREMENTS | Get os-release + raw: cat /etc/os-release + register: os_release changed_when: false -- name: PREREQUIREMENTS | Install packages - raw: pacman --needed --noconfirm -S {{ item }} - with_items: '{{ ansible_prerequirements_packages }}' - register: command_res - changed_when: "'there is nothing to do' not in command_res.stdout" +- name: PREREQUIREMENTS | ArchLinux + when: os_release.stdout.find("ID=arch") != -1 + block: + - name: PREREQUIREMENTS | Update package index (pacman) + raw: pacman -Sy + changed_when: false + - name: PREREQUIREMENTS | Install packages (pacman) + raw: pacman --needed --noconfirm -S {{ archlinux_prerequirements_packages|join(" ") }} + register: command_res + changed_when: command_res.stdout.find('there is nothing to do') == -1 + +- name: PREREQUIREMENTS | Ubuntu + when: os_release.stdout.find("ID=ubuntu") + block: + - name: PREREQUIREMENTS | Update package index (apt) + raw: apt update + changed_when: false + - name: PREREQUIREMENTS | Install packages (apt) + raw: apt install -y {{ ubuntu_prerequirements_packages|join(" ") }} + register: command_res + changed_when: command_res.stdout.find('0 upgraded, 0 newly installed, 0 to remove and ') == -1 - name: PREREQUIREMENTS | Gather facts setup: null diff --git a/vars/.gitkeep.yml b/vars/.gitkeep.yml deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..f5e267f824a2e5441f8b449161d8d29da57a3223 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,7 @@ +archlinux_prerequirements_packages: + - python + - lsb-release + +ubuntu_prerequirements_packages: + - python3 + - lsb-release