From 8ff5d38c8ab1bb5b161911045f1658fd80517dae Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Thu, 21 Jan 2021 15:39:56 +0200
Subject: [PATCH] Cleanup of playbooks.

- Set the become parameters in the inventory instead of adding it to all
  of the playbooks.
- Can't group by the package manager in the bootstrap playbook, can'
  gather facts, that's why the bootstrap is needed. Hard-code hosts.
- Delete the toolbox playbook, add the toolbox role to the debian_server
  playbook.
- Update list of playbooks in the pre-commit config.
---
 .pre-commit-config.yaml |  3 ++-
 bootstrap.yaml          | 17 ++++-------------
 debian_server.yaml      |  3 +--
 hosts/all.yaml          |  4 +++-
 kodi.yaml               |  2 --
 router.yaml             |  2 --
 toolbox.yaml            |  8 --------
 7 files changed, 10 insertions(+), 29 deletions(-)
 delete mode 100644 toolbox.yaml

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index ab6af0d..38dca35 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -45,7 +45,8 @@ repos:
     rev: v0.10.0
     hooks:
       - id: ansible-syntax-check
-        files: (bootstrap|update|renew-certs|debian_server|kodi)\.yaml
+        # yamllint disable-line rule:line-length
+        files: (bootstrap|update|renew-certs|debian_server|kodi|router)\.yaml
 
   - repo: https://github.com/ansible/ansible-lint
     rev: v4.3.7
diff --git a/bootstrap.yaml b/bootstrap.yaml
index 62a1a8d..3624722 100644
--- a/bootstrap.yaml
+++ b/bootstrap.yaml
@@ -1,17 +1,8 @@
 ---
-- name: Group hosts by package manager
-  hosts:
-    - all
-  tasks:
-    - name: Group hosts by package manager
-      group_by:
-        key: pkg_mgr_{{ ansible_pkg_mgr }}
-      tags:
-        - always
-
 - name: Bootstrap Debian hosts
   hosts:
-    - pkg_mgr_apt
+    - host01
+    - ns4
   tags:
     - debian
     - update
@@ -21,7 +12,7 @@
 
 - name: Bootstrap OpenWRT hosts
   hosts:
-    - pkg_mgr_opkg
+    - ea6350
   tags:
     - openwrt
     - update
@@ -31,7 +22,7 @@
 
 - name: Bootstrap OpenBSD hosts
   hosts:
-    - pkg_mgr_openbsd_pkg
+    - ns1
   tags:
     - openbsd
     - update
diff --git a/debian_server.yaml b/debian_server.yaml
index 08e53da..cc881ea 100644
--- a/debian_server.yaml
+++ b/debian_server.yaml
@@ -5,5 +5,4 @@
     - ns4
   roles:
     - debian_server
-  become: true
-  become_user: root
+    - toolbox
diff --git a/hosts/all.yaml b/hosts/all.yaml
index bde70e2..fc76f7d 100644
--- a/hosts/all.yaml
+++ b/hosts/all.yaml
@@ -16,8 +16,10 @@ all:
       ansible_host: host01.shore.co.il
   vars:
     # Force usage of Python3.
-    ansible_python_interpreter: python3
+    ansible_become: true
+    ansible_become_user: root
     ansible_connection: ssh
+    ansible_python_interpreter: python3
   children:
     pkg_mgr_apt:
     pkg_mgr_opkg:
diff --git a/kodi.yaml b/kodi.yaml
index c8c0511..0adcc9e 100644
--- a/kodi.yaml
+++ b/kodi.yaml
@@ -3,5 +3,3 @@
     - kodi
   roles:
     - kodi
-  become: true
-  become_user: root
diff --git a/router.yaml b/router.yaml
index 69b6e43..2a10d12 100644
--- a/router.yaml
+++ b/router.yaml
@@ -3,5 +3,3 @@
     - ns1
   roles:
     - router
-  become: true
-  become_user: root
diff --git a/toolbox.yaml b/toolbox.yaml
deleted file mode 100644
index 933c425..0000000
--- a/toolbox.yaml
+++ /dev/null
@@ -1,8 +0,0 @@
----
-- hosts:
-    - ns4
-    - localhost
-  roles:
-    - toolbox
-  become: true
-  become_user: root
-- 
GitLab