Commit ed2e0bea authored by Chris's avatar Chris
Browse files

Initial commit

parents
Base Linux
==========
This role does bootstrapping and common configuration for a base Linux server.
Requirements
------------
Ansible 2.4 or later.
Role Variables
--------------
| Variable | Default | Purpose |
|----------|---------|---------|
| hostname | | The hostname to set on the server. If blank or undefined, the hostname will not be changed. |
| common_utils | `[curl, git, htop, screen, unzip, vim]` | Common packages and utilities to install. |
OS specific variable overrides will be read from the `vars/` directory. The
first OS specific var file found will be loaded, and they are queried in
descending order by specificity. For example, Ubuntu would check files in this
order:
1. ubuntu-18.04.yml # Distribution name + full version number
1. ubuntu-bionic.yml # Distribution name + release name
1. ubuntu-18.yml # Distribution name + major version number
1. ubuntu.yml # Distribution name
1. debian.yml # OS family name
---
# The hostname to set on the server
# If blank or undefined, the hostname will not be changed
hostname:
# Common packages and utils
common_utils:
- curl
- git
- gzip
- htop
- screen
- unzip
- vim
...
# vi: set ts=2 sts=2 sw=2 et ft=yaml:
---
- name: Check if Python is installed
raw: test -x /usr/bin/python
changed_when: false
failed_when: false
register: result
- block:
- name: Install Python
raw: >
(test -e /etc/redhat-release && yum install -y python)
|| (test -e /etc/debian_version && apt-get -y update && apt-get install -y python)
when: result.rc == 1
...
# vi: set ts=2 sts=2 sw=2 et ft=yaml:
---
- name: Install common packages and utils
apt:
name: '{{ common_utils }}'
state: present
cache_valid_time: 3600
when: common_utils is defined and common_utils | length
...
# vi: set ts=2 sts=2 sw=2 et ft=yaml:
---
- name: Update 'vim-minimal' to not conflict with 'vim' or 'vim-enhanced'
dnf:
name: vim-minimal
state: latest
when: "'vim' in common_utils or 'vim-enhanced' in common_utils"
- name: Install common packages and utils
dnf:
name: '{{ common_utils }}'
state: present
when: common_utils is defined and common_utils | length
...
# vi: set ts=2 sts=2 sw=2 et ft=yaml:
---
- name: Install the 'epel-release' repo
yum:
name: epel-release
state: present
update_cache: yes
- name: Install common packages and utils
yum:
name: '{{ common_utils }}'
state: present
update_cache: yes
when: common_utils is defined and common_utils | length
...
# vi: set ts=2 sts=2 sw=2 et ft=yaml:
---
- name: Gather OS specific vars
include_vars: '{{ item }}'
with_first_found:
- vars/{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml
- vars/{{ ansible_distribution | lower }}-{{ ansible_distribution_release | lower }}.yml
- vars/{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml
- vars/{{ ansible_distribution | lower }}.yml
- vars/{{ ansible_os_family | lower }}.yml
- defaults/main.yml
# Set hostname
- block:
- name: Set hostname
hostname:
name: '{{ hostname }}'
- name: Update /etc/hosts to use new hostname
lineinfile:
dest: /etc/hosts
regexp: '^127.0.1.1'
line: '127.0.1.1 {{ hostname }}'
state: present
when: hostname is defined and hostname != None and hostname != ''
# Install common packages and utils
- include_tasks: '{{ item }}'
with_first_found:
- tasks/install-common-utils_{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml
- tasks/install-common-utils_{{ ansible_distribution | lower }}-{{ ansible_distribution_release | lower }}.yml
- tasks/install-common-utils_{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml
- tasks/install-common-utils_{{ ansible_distribution | lower }}.yml
- tasks/install-common-utils_{{ ansible_os_family | lower }}.yml
...
# vi: set ts=2 sts=2 sw=2 et ft=yaml:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment