Skip to content

Common

Hello From Common Space!

Auto Documentation

Documentation Generated with Python on 2021-04-03

Default Variables

---
# defaults file for adriagalin.motd

ag_motd_add_footer: false

ag_motd_sysadmins_signature: hay-kot
ag_motd_sysadmins_email: hay-kot@pm.me

ag_motd_info:
  - " FQDN:    ": "{{ ansible_fqdn }}"
  - " Distro:  ": "{{ ansible_distribution }} {{ ansible_distribution_version }} {{ ansible_distribution_release }}"
  - " Virtual: ": "{{ 'YES' if ansible_virtualization_role == 'guest' else 'NO' }}\n"
  - " CPUs:    ": "{{ ansible_processor_vcpus }}"
  - " RAM:     ": "{{ (ansible_memtotal_mb / 1000) | round(1) }}GB"

ag_motd_content: |
  --------------------------------------------------------------------------
                      This system is managed by Ansible
  --------------------------------------------------------------------------
  This is {{ ansible_fqdn }} running {{ ansible_distribution }}.
  NOTE: System and application configuration for this host is managed by
  automated systems. To ensure that any changes you make here are not lost,
  please contact with your system administrators.

  {% for item in ag_motd_info %}
  {% for key, value in item.items() | list %}
  {{ key }}{{ value }}
  {% endfor %}
  {% endfor %}

  Yours,

    {{ ag_motd_sysadmins_signature }}
    email: {{ ag_motd_sysadmins_email }}
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Last ansible run: {{ ansible_date_time.iso8601 }}

Tasks

main.yml

- include: user.yml
- include: installs.yml
- include: oh_my_zsh.yml
- include: ssh-notify.yml
- include: motd.yml

installs.yml

- name: Install Prerequisites
  become: yes
  apt:
    pkg:
      - curl
      - git
      - ufw
      - zsh
      - bat
      - python3-dev
      - python3-pip
      - python3-setuptools
      - python-apt
    update_cache: yes
    state: latest

- name: "Check if lf is installed"
  package_facts:
    manager: "auto"

- name: install LF File Manager
  become: yes
  ansible.builtin.shell: |
    echo 'deb http://download.opensuse.org/repositories/home:/Provessor/xUbuntu_20.04/ /' | sudo tee /etc/apt/sources.list.d/home:Provessor.list
    curl -fsSL https://download.opensuse.org/repositories/home:Provessor/xUbuntu_20.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_Provessor.gpg > /dev/null
    sudo apt update
    sudo apt install lf
  when: "'lf' not in ansible_facts.packages"

motd.yml

- name: remove ubuntu motd spam
  become: true
  file:
    path: "/etc/update-motd.d/{{ item }}"
    state: absent
  loop:
    - 80-livepatch
    - 95-hwe-eol
    - 10-help-text

# tasks file for adriagalin.motd
- name: Add 99-footer file
  become: yes
  copy:
    src: 99-footer
    dest: /etc/update-motd.d/99-footer
    owner: root
    group: root
    mode: 0755
  when: ag_motd_add_footer | bool

- name: Delete 99-footer file
  become: yes
  file:
    path: /etc/update-motd.d/99-footer
    state: absent
  when: not ag_motd_add_footer | bool

- name: Delete /etc/motd file
  become: yes
  file:
    path: /etc/motd
    state: absent
  when: ag_motd_add_footer | bool

- name: Check motd tail supported
  become: yes
  stat:
    path: /etc/update-motd.d/99-footer
  register: motd_tail_supported

- name: Add motd tail
  become: yes
  template:
    src: etc/motd.j2
    dest: /etc/motd.tail
  when: motd_tail_supported.stat.exists | bool

- name: Add motd
  become: yes
  template:
    src: motd.j2
    dest: /etc/motd
  when: not motd_tail_supported.stat.exists | bool

oh_my_zsh.yml

- name: Check if .zshrc exists
  stat:
    path: ~/.zshrc
  register: stat_rc_result

- name: Check if .oh-my-zsh exists
  stat:
    path: ~/.oh-my-zsh
  register: stat_oh_my_zsh_result

- name: Cloning oh-my-zsh
  git:
    repo: https://github.com/robbyrussell/oh-my-zsh
    dest: ~/.oh-my-zsh
  when: not stat_oh_my_zsh_result.stat.exists

- name: Set Permissions on Cloned ZSH Directories
  file:
    owner: "{{ main_username }}"
    path: "~/.oh-my-zsh"
    mode: "755"
    recurse: yes

- name: Clone Dot FIles
  git:
    repo: https://github.com/hay-kot/linux-dev
    force: yes
    dest: "/home/{{ main_username }}/linux-dev"
    clone: yes

- name: ZSH Plugins
  git:
    repo: https://github.com/supercrabtree/k
    force: yes
    dest: "/home/{{ main_username }}/.oh-my-zsh/custom/plugins/k"
    clone: yes

- name: ZSH Plugins - Auto Suggestions
  git:
    repo: https://github.com/zsh-users/zsh-autosuggestions
    force: yes
    dest: "/home/{{ main_username }}/.oh-my-zsh/custom/plugins/zsh-autosuggestions"
    clone: yes

- name: ZSH Plugins - Auto Completions
  git:
    repo: https://github.com/zsh-users/zsh-completions
    force: yes
    dest: "/home/{{ main_username }}/.oh-my-zsh/custom/plugins/zsh-completions"
    clone: yes

- name: Copy ZSH dotfile
  copy:
    remote_src: yes
    src: "/home/{{ main_username }}/linux-dev/templates/.zshrc"
    dest: "/home/{{ main_username }}/.zshrc"

user.yml

# Create New User and Add Key
- name: Create Non-Root User
  become: yes
  user:
    name: '{{ main_username }}'
    shell: "/bin/zsh"
    state: present

- name: Add Authorized Ley to Non Root User
  authorized_key:
    user: '{{ main_username }}'
    state: present
    key: "{{ item }}"
  loop:
    - "{{ lookup('file', './pub_keys/desktop_wsl.pub') }}"
    - "{{ lookup('file', './pub_keys/macbook_air.pub') }}"

ssh-notify.yml

- name: Copy SSH Notification file to Server
  become: yes
  template:
    src: roles/common/templates/sshrc.j2
    dest: /etc/ssh/sshrc