From 2da55dda3ec713a4b92d5a18e645045183518624 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Fri, 17 Mar 2017 03:07:09 +0100
Subject: [PATCH] Add first stab at ansible config for new thinkpad.

---
 ansible/.config.yml.swp                     | Bin 0 -> 12288 bytes
 ansible/config.yml                          |  23 +++++++++++++
 ansible/files/_etc_apt_apt.conf.d_99mindeps |   4 +++
 ansible/files/_etc_default_console-setup    |   4 +++
 ansible/files/_etc_default_keyboard         |   1 +
 ansible/files/_etc_profile                  |  35 ++++++++++++++++++++
 ansible/run.sh                              |   1 +
 ansible/tasks/.console_init.yml.swp         | Bin 0 -> 12288 bytes
 ansible/tasks/.timezone.yml.swp             | Bin 0 -> 12288 bytes
 ansible/tasks/apt_init.yml                  |  23 +++++++++++++
 ansible/tasks/console_init.yml              |  33 ++++++++++++++++++
 ansible/tasks/hostname.yml                  |  13 ++++++++
 ansible/tasks/initial_purge.yml             |  29 ++++++++++++++++
 ansible/tasks/set_repos.yml                 |  21 ++++++++++++
 ansible/tasks/timezone.yml                  |  10 ++++++
 15 files changed, 197 insertions(+)
 create mode 100644 ansible/.config.yml.swp
 create mode 100644 ansible/config.yml
 create mode 100644 ansible/files/_etc_apt_apt.conf.d_99mindeps
 create mode 100644 ansible/files/_etc_default_console-setup
 create mode 100644 ansible/files/_etc_default_keyboard
 create mode 100644 ansible/files/_etc_profile
 create mode 100644 ansible/run.sh
 create mode 100644 ansible/tasks/.console_init.yml.swp
 create mode 100644 ansible/tasks/.timezone.yml.swp
 create mode 100644 ansible/tasks/apt_init.yml
 create mode 100644 ansible/tasks/console_init.yml
 create mode 100644 ansible/tasks/hostname.yml
 create mode 100644 ansible/tasks/initial_purge.yml
 create mode 100644 ansible/tasks/set_repos.yml
 create mode 100644 ansible/tasks/timezone.yml

diff --git a/ansible/.config.yml.swp b/ansible/.config.yml.swp
new file mode 100644
index 0000000000000000000000000000000000000000..82d1860cac14319e3032c2418089b907f03995f8
GIT binary patch
literal 12288
zcmeI2F>4e-9K|O#R*69iv2rv*K-k^HAcO-UB(botJA*dL+}=Nz#l4wjXEyOHOs${7
zE@0^wus5yv0sH`3D;B=p+XW5iLAsMS@R*y~H~)G2Teetk25Wl{9_r0_O`$C-^>zF7
z@yW#{_4%q&rE{U4p4E=-ZZykh`CioplhoP$Y?K)5vq3KHFrJL_S<88y1W4e#1gfwf
zZ7!;fJL}E6x^nY|zH<4|d8=_936KB@kN^pg011!)36Q`X5(veDI!5jbZFYS2H*Mie
z-wxT4011!)36KB@kN^pg011!)36KB@%pn0YRO)0=sq0G!kN^L>@Bg2dl==pJfj&W}
z&`0PU^cH#py@oRA0NRCipcUvE^aJ(2Lm!~`P!8=t%|3I;iIGWw1W14cNPq-LfCNZ@
z1W4fjCZMOSlp;5&^z>@K|734B^Cr(-YJ%LeZdG-jk-R8id0Kn=zndoF<J-47<4}C)
z=|n=B_=yiP9=3flk`N|wFeQG(N5%#}o!Y|mdhDe<%u;E#>jGgAX=}!aCe~M_=mCzH
z>#=xmM&h->jKxHni?KuPtoA4$bXBM}whq}?UOI~k_p8zsl59(vXSTU~XiDE}_Q-6S
zS3{VB@y~tIEt(!%uS1+M;E=m_xjf5k7XE57Mfk&@(GHvs(;KQ!)$4!9=*-;?O}IMn
dKvGvj0eOrnpzG=8G=J1=;CmWRP(@LsegWF##BBfo

literal 0
HcmV?d00001

diff --git a/ansible/config.yml b/ansible/config.yml
new file mode 100644
index 0000000..b30e379
--- /dev/null
+++ b/ansible/config.yml
@@ -0,0 +1,23 @@
+---
+- hosts: all
+  user: root
+  become: yes
+  tasks:
+
+  - include: tasks/hostname.yml
+    vars:
+      hostname: w530 
+
+  - include: tasks/apt_init.yml
+
+  - include: tasks/console_init.yml
+
+  - include: tasks/timezone.yml
+    vars:
+       timezone: Europe/Berlin
+
+  - name: ensure boot messages are not cleand on start up
+    replace:
+      dest: /etc/systemd/system/getty.target.wants/getty@tty1.service
+      regexp: '^TTYVTDisallocate=yes.*$'
+      replace: 'TTYVDisallocate=no'
diff --git a/ansible/files/_etc_apt_apt.conf.d_99mindeps b/ansible/files/_etc_apt_apt.conf.d_99mindeps
new file mode 100644
index 0000000..4aaef79
--- /dev/null
+++ b/ansible/files/_etc_apt_apt.conf.d_99mindeps
@@ -0,0 +1,4 @@
+APT::AutoRemove::RecommendsImportant "false";
+APT::AutoRemove::SuggestsImportant "false";
+APT::Install-Recommends "false";
+APT::Install-Suggests "false";
diff --git a/ansible/files/_etc_default_console-setup b/ansible/files/_etc_default_console-setup
new file mode 100644
index 0000000..090d241
--- /dev/null
+++ b/ansible/files/_etc_default_console-setup
@@ -0,0 +1,4 @@
+CHARMAP="UTF-8"
+CODESET="Lat15"
+FONTFACE="Terminus"
+FONTSIZE="6x12"
diff --git a/ansible/files/_etc_default_keyboard b/ansible/files/_etc_default_keyboard
new file mode 100644
index 0000000..b8f918b
--- /dev/null
+++ b/ansible/files/_etc_default_keyboard
@@ -0,0 +1 @@
+XKBLAYOUT="de"
diff --git a/ansible/files/_etc_profile b/ansible/files/_etc_profile
new file mode 100644
index 0000000..5884d7b
--- /dev/null
+++ b/ansible/files/_etc_profile
@@ -0,0 +1,35 @@
+# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
+# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
+
+if [ "`id -u`" -eq 0 ]; then
+  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
+else
+  PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
+fi
+export PATH
+
+if [ "${PS1-}" ]; then
+  if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
+    # The file bash.bashrc already sets the default PS1.
+    # PS1='\h:\w\$ '
+    if [ -f /etc/bash.bashrc ]; then
+      . /etc/bash.bashrc
+    fi
+  else
+    if [ "`id -u`" -eq 0 ]; then
+      PS1='# '
+    else
+      PS1='$ '
+    fi
+  fi
+fi
+
+if [ -d /etc/profile.d ]; then
+  for i in /etc/profile.d/*.sh; do
+    if [ -r $i ]; then
+      . $i
+    fi
+  done
+  unset i
+fi
+export LC_ALL="en_US.UTF-8"
diff --git a/ansible/run.sh b/ansible/run.sh
new file mode 100644
index 0000000..02856c2
--- /dev/null
+++ b/ansible/run.sh
@@ -0,0 +1 @@
+ansible-playbook -i 'localhost,' -c local config.yml
diff --git a/ansible/tasks/.console_init.yml.swp b/ansible/tasks/.console_init.yml.swp
new file mode 100644
index 0000000000000000000000000000000000000000..2d903f7cf2aebca112d5275dce036573dd7279b4
GIT binary patch
literal 12288
zcmeI2KW`H;7>8X3SZFCQAThbHz;L;=6;io@0VE^_CP-o8<XoI!)n}h<M<ELcJ^>qo
zm4S(Y9X<hK=l~KQfQ^s9!0-N~Nkgir8<k#5k50B<zpwAHGMwUWd-vXbzSC+mv~|Wl
zZhd`x^UNCiafvZ!Z77GAwb703YWcFb=Vih;v!<^Gu`phBwTy%Cd%hg>R?Acw6<Xt5
zFH1%9WPl7D+rTQ@-rB5wt5>gV@QW8Z$Id_t$N(8217v^<kO4A42FL&zIJpKwvBF+p
z`=^>$*l3<BbI+zr4>CXo$N(8217v^<kO4A42FL&zAOmFJ1R4-M#@?T0?9M7SkN^KC
z-~WHkG4>PegAd>pcnO|>U9btxgLUwGjj>-~AAA9y!5i=zj6epu;1+0u%K%pl*lF+`
zb-#g6;2n4i9)WT{w*fUWKnBPF86X2>fDDiUGC&5%z<*?b^UUVCFujC(8HNS!GP8&q
zk;{a;p*a}j!E#X)dW`t$wsScXlo@#5cQ)s-3|ZWheKFJ_W{jitqz_3wQ8?RIT2{l}
zWeG2PK2EVHoz7*p7$*nSM@|KKXgR+&QsF7rHWONM`K+)mT<3K$A4I^G3n#rap(<3r
zgfwaAL96rdZnT5ZdTlz8W?Bdx>9Cs5gf@Y7ZoVLSqo|P)Rql{q6k(cJ8b5S$s!(~Z
z4035L@!`tLc68=?r=BBjQPRouzd2{LPtIdcj=NU49&(}Noc|^$oe5fW5R>Wh{BZ@o
eI>GuS78IP<a&*=C$VH`tbh$D@A1WP15&H|vuNL<J

literal 0
HcmV?d00001

diff --git a/ansible/tasks/.timezone.yml.swp b/ansible/tasks/.timezone.yml.swp
new file mode 100644
index 0000000000000000000000000000000000000000..e51c376de33b6daf4f8f3fa24ce45b979ceedc2b
GIT binary patch
literal 12288
zcmeI&ze~eF6bJBEClRc_2G>)OPU%&Ppc$N8Iyfq>*LXFd*Idb+h?eSq(9!=x{|$F{
z{|F}?e2J-G9V*=l--E|-zaB3i$PjYv#(C>h9M&7eZIx*4<mF;_u}ZI-M47cdpPtrk
z4w}XBY5VT;gfg;eC%KX;bxGT3>6Pm`>64zmv#GA%_RO?2Scd=vW)fJY=KfysuI_Aa
ziH-HMnX=#z1Rwwb2tWV=5P$##ATXZ-zF(mSE`6aaf2r&%6MZ>E2LT8`00Izz00bZa
z0SG_<0uX?}915sQqW3D%(FzyO|NqC||DQbm;CSPB=6K?G<QQ?ZIa(aWnK^uBlnem~
zKmY;|fB*y_009U<00I#Bw}9a0yz)8}CP}-LkNe8Up^(}~(%49u{8oFh;IfG4uU#fx
ztTHY0tL{nKv2rjF<E!stIOM&Z#ORO$k*XeNcG^#-<2^3c#)Lvgu@$x78EWGA`@lHs
M-&8*<6a)c%0k1G)bN~PV

literal 0
HcmV?d00001

diff --git a/ansible/tasks/apt_init.yml b/ansible/tasks/apt_init.yml
new file mode 100644
index 0000000..f94a54f
--- /dev/null
+++ b/ansible/tasks/apt_init.yml
@@ -0,0 +1,23 @@
+---
+- include: tasks/set_repos.yml
+
+- name: update package lists
+  apt: 
+    update_cache: yes
+
+- name: write APT config file
+  copy:
+    src: files/_etc_apt_apt.conf.d_99mindeps
+    dest: /etc/apt/apt.conf.d/99mindeps
+
+- name: check for initial_purge_happened flag
+  stat: path=flags/initial_purge_happened
+  register: initial_purge
+
+- name: perform initial purge
+  include: tasks/initial_purge.yml
+  when: initial_purge.stat.exists == False
+
+- name: APT - dist-upgrade
+  apt:
+    upgrade: dist
diff --git a/ansible/tasks/console_init.yml b/ansible/tasks/console_init.yml
new file mode 100644
index 0000000..248ebcc
--- /dev/null
+++ b/ansible/tasks/console_init.yml
@@ -0,0 +1,33 @@
+---
+- name: write terminal config file
+  copy:
+    src: files/_etc_default_console-setup
+    dest: /etc/default/console-setup
+
+- name: write keyboard config file
+  copy:
+    src: files/_etc_default_keyboard
+    dest: /etc/default/keyboard
+
+- name: ensure locales is installed
+  apt:
+     name: locales 
+     state: present
+
+- name: ensure setupcon is installed
+  apt:
+     name: console-setup
+     state: present
+
+- name: generate en_US.UTF-8 locale
+  locale_gen:
+    name: en_US.UTF-8
+    state: present
+
+- name: write /etc/profile (with locale export) 
+  copy:
+    src: files/_etc_profile
+    dest: /etc/profile
+
+- name: run setupcon to apply console settings from /etc/default/
+  command: setupcon
diff --git a/ansible/tasks/hostname.yml b/ansible/tasks/hostname.yml
new file mode 100644
index 0000000..f5e036b
--- /dev/null
+++ b/ansible/tasks/hostname.yml
@@ -0,0 +1,13 @@
+---
+
+- name: set hostname in /etc/hostname
+  shell: echo {{ hostname }} > /etc/hostname
+
+- name: set hostname in /etc/hosts
+  replace:
+    dest: /etc/hosts
+    regexp: '^127\.0\.1\.1.*$'
+    replace: '127.0.1.1        {{ hostname }}'
+
+- name: set hostname for current session
+  shell: hostname {{ hostname }}
diff --git a/ansible/tasks/initial_purge.yml b/ansible/tasks/initial_purge.yml
new file mode 100644
index 0000000..1354170
--- /dev/null
+++ b/ansible/tasks/initial_purge.yml
@@ -0,0 +1,29 @@
+---
+
+- name: collect officially required packages
+  shell: dpkg-query -Wf '${Package} ${Priority}\n' | grep ' required' | sed 's/ required//' > /tmp/list_white_unsorted
+
+- name: add "ifupdown" and "isc-dhcp-client" (to keep internet connection afterwards) and "ansible" (to keep its modules available for continuing the configuration) to required packages
+  shell: echo 'ifupdown' >> /tmp/list_white_unsorted && echo 'isc-dhcp-client' >> /tmp/list_white_unsorted && echo 'ansible' >> /tmp/list_white_unsorted && sort /tmp/list_white_unsorted > /tmp/list_white
+
+- name: collect currently installed packages
+  shell: dpkg-query -Wf '${Package}\n' > /tmp/list_all_packages && sort /tmp/list_all_packages > /tmp/foo && mv /tmp/foo /tmp/list_all_packages
+
+- name: create black list of packages to mark as automatically installed from the difference between the required packages and the packages currently installed
+  shell: comm -3 /tmp/list_all_packages /tmp/list_white > /tmp/list_black
+
+- name: mark all packages from black list as automatically installed
+  shell: apt-mark auto $(cat /tmp/list_black)
+
+- name: purge all packages automatically installed that are not depended on
+  shell: DEBIAN_FRONTEND=noninteractive apt-get -y --purge autoremove
+
+- name: ensure flags directory exists
+  file:
+    path: flags
+    state: directory
+
+- name: set initial_purge_happened flag, so that this whole process does not get repeated
+  file:
+    path: flags/initial_purge_happened
+    state: touch
diff --git a/ansible/tasks/set_repos.yml b/ansible/tasks/set_repos.yml
new file mode 100644
index 0000000..7605883
--- /dev/null
+++ b/ansible/tasks/set_repos.yml
@@ -0,0 +1,21 @@
+---
+
+- name: APT - use stretch repo 
+  apt_repository:
+    repo: deb http://ftp.debian.org/debian/ stretch main contrib non-free
+    state: present
+
+- name: APT - use stretch security updates repo
+  apt_repository:
+    repo: deb http://security.debian.org/ stretch/updates main contrib non-free
+    state: present
+
+- name: APT - use stretch-updates repo
+  apt_repository:
+    repo: deb http://ftp.debian.org/debian/ stretch-updates main contrib non-free
+    state: present
+
+- name: APT - use stretch-backports repo
+  apt_repository:
+    repo: deb http://ftp.debian.org/debian stretch-backports main contrib non-free
+    state: present
diff --git a/ansible/tasks/timezone.yml b/ansible/tasks/timezone.yml
new file mode 100644
index 0000000..d60232b
--- /dev/null
+++ b/ansible/tasks/timezone.yml
@@ -0,0 +1,10 @@
+---
+
+- name: set /etc/timezone
+  shell: echo '{{ timezone }}' > /etc/timezone
+
+- name: set /etc/localtime
+  file:
+    src: /usr/share/zoneinfo/{{ timezone }}
+    path: /etc/localtime
+    state: link
-- 
2.30.2