From: Christian Heller Date: Sat, 18 Mar 2017 02:36:11 +0000 (+0100) Subject: Reorganize and extend ansible attempt. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/static/%7B%7Bdb.prefix%7D%7D/edit?a=commitdiff_plain;h=7c06f62d6342a1e7933625183fc5264315f52d57;p=config Reorganize and extend ansible attempt. --- diff --git a/ansible/config.yml b/ansible/config.yml index b30e379..d157a2a 100644 --- a/ansible/config.yml +++ b/ansible/config.yml @@ -4,20 +4,76 @@ become: yes tasks: - - include: tasks/hostname.yml - vars: - hostname: w530 + # Set hostname. + - name: symlink hostname file + file: state=link force=yes src=/root/config/ansible/files/_etc_hostname dest=/etc/hostname + - name: symlink hosts file + file: state=link force=yes src=/root/config/ansible/files/_etc_hosts dest=/etc/hosts + - name: set hostname for current session + shell: hostname w530 - - include: tasks/apt_init.yml + # Configure package management. + - name: symlink APT sources file + file: state=link force=yes src=/root/config/ansible/files/_etc_apt_sources.list dest=/etc/apt/sources.list + - name: update package lists + apt: update_cache=yes + - name: symlink APT config file + file: state=link force=yes src=/root/config/ansible/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 - - include: tasks/console_init.yml + # Configure console. + - name: symlink terminal config file + file: state=link force=yes src=/root/config/ansible/files/_etc_default_console-setup dest=/etc/default/console-setup + - name: symlink keyboard config file + file: state=link force=yes src=/root/config/ansible/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: symlink /etc/profile (with locale export) + file: state=link force=yes src=/root/config/ansible/files/_etc_profile dest=/etc/profile + - name: run setupcon to apply console settings from /etc/default/ + command: setupcon + - name: ensure boot messages are not cleared on start up + replace: dest=/etc/systemd/system/getty.target.wants/getty@tty1.service regexp='^TTYVTDisallocate=yes.*$' replace='TTYVDisallocate=no' - - include: tasks/timezone.yml - vars: - timezone: Europe/Berlin + # Configure timezone. + - name: symlink timezone file + file: state=link force=yes src=/root/config/ansible/files/_etc_timezone dest=/etc/timezone + - name: set /etc/localtime + file: state=link force=yes src=/usr/share/zoneinfo/Europe/Berlin dest=/etc/localtime - - 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' + # Set up editor + - name: set ~/.vimrc + file: state=link force=yes src=/root/config/ansible/dotfiles/vimrc dest=~/.vimrc + - name: set ~/.vimrc_add + file: state=link force=yes src=/root/config/ansible/dotfiles/vimrc_add dest=~/.vimrc_add + - name: ensure ~/.vimbackups directory + file: path=~/.vimbackups state=directory + - name: ensure vim is installed + apt: name=vim state=present + + # Configure shell. + - name: set ~/.bashrc + file: state=link force=yes src=/root/config/ansible/dotfiles/bashrc dest=~/.bashrc + - name: set ~/.profile + file: state=link force=yes src=/root/config/ansible/dotfiles/profile dest=~/.profile + - name: set ~/.shinit + file: state=link force=yes src=/root/config/ansible/dotfiles/shinit dest=~/.shinit + - name: set ~/.shinit_color + file: state=link force=yes src=/root/config/ansible/dotfiles/shinit_color dest=~/.shinit_color + + # Set up git. + - name: set ~/.gitconfig + file: state=link force=yes src=/root/config/ansible/dotfiles/gitconfig dest=~/.gitconfig + - name: ensure git is installed + apt: name=git state=present diff --git a/ansible/dotfiles/bashrc b/ansible/dotfiles/bashrc new file mode 100644 index 0000000..4dc08f7 --- /dev/null +++ b/ansible/dotfiles/bashrc @@ -0,0 +1,5 @@ +# Bash as a non-login shell in non-POSIX-mode does not read in the startup +# script at the path in $ENV. This forces it to still read in the ~/.shinit +# startup script for non-login shells. + +. ~/.shinit diff --git a/ansible/dotfiles/gitconfig b/ansible/dotfiles/gitconfig new file mode 100644 index 0000000..5cdc162 --- /dev/null +++ b/ansible/dotfiles/gitconfig @@ -0,0 +1,3 @@ +[user] + name = Christian Heller + email = c.heller@plomlompom.de diff --git a/ansible/dotfiles/profile b/ansible/dotfiles/profile new file mode 100644 index 0000000..5a58435 --- /dev/null +++ b/ansible/dotfiles/profile @@ -0,0 +1,6 @@ +# Initialization for login shells. + +# Tell interactive shells to look in ~/.shinit for setup. +ENV=$HOME/.shinit +export ENV +. $ENV diff --git a/ansible/dotfiles/shinit b/ansible/dotfiles/shinit new file mode 100644 index 0000000..25d1396 --- /dev/null +++ b/ansible/dotfiles/shinit @@ -0,0 +1,37 @@ +# Settings for interactive shells. + +# Ensure shell truly is interactive to avoid confusing non-interactive shells. +if [[ $- == *i* ]]; then + + # Fancy colors for ls. + alias ls="ls --color=auto" + + # Use vim as default editor for anything. + export VISUAL=vim + export EDITOR=$VISUAL + + # Colored prompt with username, hostname, date/time, directory. + colornumber=7 # Default to white if no color set via colornumber dotfile. + colornumber_file=~/.shinit_color + if [ -f $colornumber_file ]; then + colornumber=`cat $colornumber_file` + fi + tput_color="$(tput setaf $colornumber)$(tput bold)" + tput_reset="$(tput sgr0)" + # Bash confuses the line length when not told to not count escape sequences. + if [ ! "$BASH" = "" ]; then + tput_color="\[$tput_color\]" + tput_reset="\[$tput_reset\]" + fi + PS1="${tput_color}["\$\(date\ +%Y-%m-%d/%H:%M:%S/%Z\)" $USER@$(hostname):"\$\(pwd\)"]$ $tput_reset" + PS2="${tput_color}> $tput_reset" + PS3="${tput_color}select: $tput_reset" + PS4="${tput_color}+ $tput_reset" + + # Add local additions. + local_shinit_file=~/.shinit_add + if [ -f $local_shinit_file ]; then + . $local_shinit_file + fi + +fi diff --git a/ansible/dotfiles/shinit_color b/ansible/dotfiles/shinit_color new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/ansible/dotfiles/shinit_color @@ -0,0 +1 @@ +1 diff --git a/ansible/dotfiles/vimrc b/ansible/dotfiles/vimrc new file mode 100644 index 0000000..b1434ed --- /dev/null +++ b/ansible/dotfiles/vimrc @@ -0,0 +1,30 @@ +" Activate syntax highlighting. +syntax on +filetype plugin on + +" Number lines. +set number + +" Don't add unsolicited final newline. +set binary + +" Indentation rules (tabs to 4 spaces). +set expandtab +set shiftwidth=2 +set softtabstop=2 + +" Backups. +set backup +set backupdir=~/.vimbackups +let myvar = strftime("%Y-%m-%d_%H-%M-%S") +let myvar = "set backupext=_". myvar +execute myvar + +" Keep syntax highlighting healthy. +autocmd BufEnter * :syntax sync fromstart + +" Mark the 80-th column. +set colorcolumn=80 + +" Source additions +source ~/.vimrc_add diff --git a/ansible/dotfiles/vimrc_add b/ansible/dotfiles/vimrc_add new file mode 100644 index 0000000..e69de29 diff --git a/ansible/files/_etc_apt_sources.list b/ansible/files/_etc_apt_sources.list new file mode 100644 index 0000000..e64d6ee --- /dev/null +++ b/ansible/files/_etc_apt_sources.list @@ -0,0 +1,4 @@ +deb http://ftp.debian.org/debian/ stretch main contrib non-free +deb http://ftp.debian.org/debian/ stretch-updates main contrib non-free +deb http://ftp.debian.org/debian stretch-backports main contrib non-free +deb http://security.debian.org/ stretch/updates main contrib non-free diff --git a/ansible/files/_etc_hostname b/ansible/files/_etc_hostname new file mode 100644 index 0000000..8769fca --- /dev/null +++ b/ansible/files/_etc_hostname @@ -0,0 +1 @@ +w530 diff --git a/ansible/files/_etc_hosts b/ansible/files/_etc_hosts new file mode 100644 index 0000000..d920e4f --- /dev/null +++ b/ansible/files/_etc_hosts @@ -0,0 +1,7 @@ +127.0.0.1 localhost +127.0.1.1 w530 + +# The following lines are desirable for IPv6 capable hosts +::1 localhost ip6-localhost ip6-loopback +ff02::1 ip6-allnodes +ff02::2 ip6-allrouters diff --git a/ansible/files/_etc_systemd_system_getty.target.wants_getty@tty1.service b/ansible/files/_etc_systemd_system_getty.target.wants_getty@tty1.service new file mode 100644 index 0000000..317d866 --- /dev/null +++ b/ansible/files/_etc_systemd_system_getty.target.wants_getty@tty1.service @@ -0,0 +1,53 @@ +# This file is part of systemd. +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. + +[Unit] +Description=Getty on %I +Documentation=man:agetty(8) man:systemd-getty-generator(8) +Documentation=http://0pointer.de/blog/projects/serial-console.html +After=systemd-user-sessions.service plymouth-quit-wait.service +After=rc-local.service + +# If additional gettys are spawned during boot then we should make +# sure that this is synchronized before getty.target, even though +# getty.target didn't actually pull it in. +Before=getty.target +IgnoreOnIsolate=yes + +# IgnoreOnIsolate causes issues with sulogin, if someone isolates +# rescue.target or starts rescue.service from multi-user.target or +# graphical.target. +Conflicts=rescue.service +Before=rescue.service + +# On systems without virtual consoles, don't start any getty. Note +# that serial gettys are covered by serial-getty@.service, not this +# unit. +ConditionPathExists=/dev/tty0 + +[Service] +# the VT is cleared by TTYVTDisallocate +ExecStart=-/sbin/agetty --noclear %I $TERM +Type=idle +Restart=always +RestartSec=0 +UtmpIdentifier=%I +TTYPath=/dev/%I +TTYReset=yes +TTYVHangup=yes +TTYVDisallocate=no +KillMode=process +IgnoreSIGPIPE=no +SendSIGHUP=yes + +# Unset locale for the console getty since the console has problems +# displaying some internationalized messages. +Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION= + +[Install] +WantedBy=getty.target +DefaultInstance=tty1 diff --git a/ansible/files/_etc_timezone b/ansible/files/_etc_timezone new file mode 100644 index 0000000..94d5acc --- /dev/null +++ b/ansible/files/_etc_timezone @@ -0,0 +1 @@ +Europe/Berlin diff --git a/ansible/tasks/apt_init.yml b/ansible/tasks/apt_init.yml deleted file mode 100644 index f94a54f..0000000 --- a/ansible/tasks/apt_init.yml +++ /dev/null @@ -1,23 +0,0 @@ ---- -- 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 deleted file mode 100644 index 248ebcc..0000000 --- a/ansible/tasks/console_init.yml +++ /dev/null @@ -1,33 +0,0 @@ ---- -- 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 deleted file mode 100644 index f5e036b..0000000 --- a/ansible/tasks/hostname.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- - -- 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 index 1354170..63fddd9 100644 --- a/ansible/tasks/initial_purge.yml +++ b/ansible/tasks/initial_purge.yml @@ -19,11 +19,7 @@ shell: DEBIAN_FRONTEND=noninteractive apt-get -y --purge autoremove - name: ensure flags directory exists - file: - path: flags - state: directory + 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 + file: path=flags/initial_purge_happened state=touch diff --git a/ansible/tasks/set_repos.yml b/ansible/tasks/set_repos.yml deleted file mode 100644 index 7605883..0000000 --- a/ansible/tasks/set_repos.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- - -- 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 deleted file mode 100644 index d60232b..0000000 --- a/ansible/tasks/timezone.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- - -- name: set /etc/timezone - shell: echo '{{ timezone }}' > /etc/timezone - -- name: set /etc/localtime - file: - src: /usr/share/zoneinfo/{{ timezone }} - path: /etc/localtime - state: link