---
- name: Install common applications
  apt:
    name: "{{ item }}"
    state: installed
    update_cache: yes
    cache_valid_time: 3600
  with_items: "{{common_apps}}"
  become: yes

- name: Select Vim alternative
  alternatives: name=vim link=/usr/bin/vim path=/usr/bin/vim.gtk3
  become: yes

---
- name: Install common applications
  apt:
    name: "{{ item }}"
    state: installed
    update_cache: yes
    cache_valid_time: 3600
  with_items: "{{common_apps}}"
  become: yes

- name: Check if vim.gtk exists
  stat:
    path: "/usr/bin/vim.gtk"
  register: vimgtk

- name: Check if vim.gtk3 exists
  stat:
    path: "/usr/bin/vim.gtk3"
  register: vimgtk3

- name: Select vim.gtk alternative
  alternatives: name=vim link=/usr/bin/vim path=/usr/bin/vim.gtk
  when: vimgtk.stat.exists
  become: yes

- name: Select vim.gtk3 alternative
  alternatives: name=vim link=/usr/bin/vim path=/usr/bin/vim.gtk3
  when: vimgtk3.stat.exists
  become: yes

Add some variability handling to the vim alternative script.
Add some variability handling to the vim alternative script.
