From f1cbf7c7611fba5792113f9e89d821998f7e06e2 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Mon, 11 Sep 2017 22:10:17 +0200
Subject: [PATCH] Replace pentadactyl with qutebrowser in new Ansible setup.

---
 ansible/config_new.yml                        | 17 ++++---
 .../apt-mark_new/W530/browser_environment     |  4 ++
 .../apt-mark_new/minimal/browser_environment  |  5 +-
 ansible/tasks/qutebrowser.yml                 | 46 +++++++++++++++++++
 4 files changed, 61 insertions(+), 11 deletions(-)
 create mode 100644 ansible/files/apt-mark_new/W530/browser_environment
 create mode 100644 ansible/tasks/qutebrowser.yml

diff --git a/ansible/config_new.yml b/ansible/config_new.yml
index 1921cbe..8153fc9 100644
--- a/ansible/config_new.yml
+++ b/ansible/config_new.yml
@@ -9,8 +9,9 @@
     with_lines: cat ~/config/ansible/files/dirs_new | sed -e 's/ *#.*$//'
   - name: symlink system files
     file: state=hard force=yes src={{item}} dest={{item|basename|regex_replace('___','/')}}
-    with_fileglob: ~/config/ansible/files/system_new/minimal/*
-    with_fileglob: ~/config/ansible/files/system_new/{{ system_name }}/*
+    with_fileglob:
+    - ~/config/ansible/files/system_new/minimal/*
+    - ~/config/ansible/files/system_new/{{ system_name }}/*
   - name: set hostname for current session
     shell: hostname {{ system_name }} 
 
@@ -65,10 +66,10 @@
   # Config user.
   - name: create user plom with sudo privileges and bash shell
     user: name=plom groups=sudo shell=/bin/bash
-  - name: have config repo in user directory
-    git: repo=https://github.com/plomlompom/config dest=/home/plom/config
-    become_user: plom
-    become_method: su
+  #- name: have config repo in user directory
+  #  git: repo=https://github.com/plomlompom/config dest=/home/plom/config
+  #  become_user: plom
+  #  become_method: su
 
   # Ensure X window environment.
   - name: ensure minimal X window environment
@@ -86,7 +87,9 @@
     apt: name={{item}} state=present
     with_lines: cat ~/config/ansible/files/apt-mark_new/minimal/basic_x_tools | sed -e 's/ *#.*$//'
 
-  # Set up pentadactyl.
+  # Set up qutebrowser.
+  - name: ensure qutebrowser
+    include: tasks/qutebrowser.yml
   - name: ensure browser environment
     apt: name={{item}} state=present
     with_lines: cat ~/config/ansible/files/apt-mark_new/minimal/browser_environment | sed -e 's/ *#.*$//'
diff --git a/ansible/files/apt-mark_new/W530/browser_environment b/ansible/files/apt-mark_new/W530/browser_environment
new file mode 100644
index 0000000..cc9575c
--- /dev/null
+++ b/ansible/files/apt-mark_new/W530/browser_environment
@@ -0,0 +1,4 @@
+iceweasel
+vim-gtk  # used by pentadactyl for text editing
+xul-ext-noscript
+xul-ext-pentadactyl
diff --git a/ansible/files/apt-mark_new/minimal/browser_environment b/ansible/files/apt-mark_new/minimal/browser_environment
index cc9575c..bbc220a 100644
--- a/ansible/files/apt-mark_new/minimal/browser_environment
+++ b/ansible/files/apt-mark_new/minimal/browser_environment
@@ -1,4 +1 @@
-iceweasel
-vim-gtk  # used by pentadactyl for text editing
-xul-ext-noscript
-xul-ext-pentadactyl
+qutebrowser
diff --git a/ansible/tasks/qutebrowser.yml b/ansible/tasks/qutebrowser.yml
new file mode 100644
index 0000000..fdd4af2
--- /dev/null
+++ b/ansible/tasks/qutebrowser.yml
@@ -0,0 +1,46 @@
+---
+
+- name: Set qutebrowser, python3-pypeg2 facts.
+  set_fact:
+    qutebrowser_deb_url: https://github.com/qutebrowser/qutebrowser/releases/download/v0.11.0/qutebrowser_0.11.0-1_all.deb
+    python3pypeg2_deb_url: https://qutebrowser.org/python3-pypeg2_2.15.2-1_all.deb
+    qutebrowser_deb_path: /tmp/qutebrowser.deb
+    python3pypeg2_deb_path: /tmp/python3-pypeg2.deb
+
+
+- name: Check if qutebrowser is installed.
+  command: dpkg-query -W qutebrowser
+  register: qutebrowser_debcheck
+  failed_when: qutebrowser_debcheck.rc > 1
+  changed_when: qutebrowser_debcheck.rc == 1
+
+- name: Check if qutebrowser-dependency python3-pypeg2 is installed.
+  command: dpkg-query -W python3-pypeg2 
+  register: python3pypeg2_debcheck
+  failed_when: python3pypeg2_debcheck.rc > 1
+  changed_when: python3pypeg2_debcheck.rc == 1
+  when: qutebrowser_debcheck.rc == 1
+
+- name: Download python3-pypeg2 package.
+  get_url: url={{ python3pypeg2_deb_url }} dest={{ python3pypeg2_deb_path }}
+  when: qutebrowser_debcheck.rc == 1 and python3pypeg2_debcheck.rc == 1
+
+- name: Download qutebrowser package.
+  get_url: url={{ qutebrowser_deb_url }} dest={{ qutebrowser_deb_path }}
+  when: qutebrowser_debcheck.rc == 1
+
+# We use command: apt as a workaround because the Ansible apt module installs
+# the Depends of the .deb marked as manual while we want them marked as auto.
+- name: Install python3-pypeg2 package,
+  command: apt install --yes "{{ python3pypeg2_deb_path}}"
+  when: qutebrowser_debcheck.rc == 1 and python3pypeg2_debcheck.rc == 1
+
+- name: Mark python3-pypeg2 package as automatically installed.
+  command: apt-mark auto python3-pypeg2
+  when: qutebrowser_debcheck.rc == 1 and python3pypeg2_debcheck.rc == 1
+
+# We use command: apt as a workaround because the Ansible apt module installs
+# the Depends of the .deb marked as manual while we want them marked as auto.
+- name: Install qutebrowser package.
+  command: apt install --yes "{{ qutebrowser_deb_path}}"
+  when: qutebrowser_debcheck.rc == 1
-- 
2.30.2