10 Commits

Author SHA1 Message Date
8ad513bac3 Added sda to expression 2021-10-01 10:33:46 +13:00
0c9984e00d Commented defaults, added boolean for set root pw 2021-10-01 10:32:01 +13:00
ac94545d69 prefixed admin_group 2021-10-01 10:11:51 +13:00
b0655ceae4 Reformat smaller terminal 2021-09-30 23:40:46 +13:00
67fe06e119 Another prefix bites the dust 2021-09-30 23:33:36 +13:00
d2158ba3fa Add prefix 2021-09-30 23:26:52 +13:00
1f3310fe96 Re-add timezone 2021-09-30 23:12:42 +13:00
dae99f3168 Add molecule scenario 2021-09-30 22:58:20 +13:00
b84bcaa7c7 Migrate to common_ prefixed vars 2021-09-30 22:57:47 +13:00
e42d3c8214 Updated defaults prefix with common_ 2021-09-30 22:55:46 +13:00
15 changed files with 180 additions and 184 deletions

2
.ansible-lint Normal file
View File

@@ -0,0 +1,2 @@
skip_list:
- role-name

33
.yamllint Normal file
View File

@@ -0,0 +1,33 @@
---
# Based on ansible-lint config
extends: default
rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
colons:
max-spaces-after: -1
level: error
commas:
max-spaces-after: -1
level: error
comments: disable
comments-indentation: disable
document-start: disable
empty-lines:
max: 3
level: error
hyphens:
level: error
indentation: disable
key-duplicates: enable
line-length: disable
new-line-at-end-of-file: disable
new-lines:
type: unix
trailing-spaces: disable
truthy: disable

View File

@@ -1,23 +1,43 @@
---
# defaults file for guisea.common
domain: exampledomain.com
ad_domain_joined: no
win_timezone: New Zealand Standard Time
vendors_hosts: []
# defaults file for cybercinch.common
dns_servers:
# What is the domain name for this machine?
common_domain: exampledomain.com
# Timezone string for Windows nodes
common_win_tz: New Zealand Standard Time
# Timezone string for Linux nodes
common_tz: Pacific/Auckland
# Additional host entries to add to /etc/hosts if required
# e.g
# common_vendors_hosts:
# - ip: 192.168.1.3
# name: an.alias.hostname
# - ip: 192.168.1.4
# name: another.alias.hostname
common_vendors_hosts: []
# What DNS Servers should we use by default
common_dns_servers:
- 1.0.0.1
- 1.1.1.1
ADMIN_GROUP: admins
# The name of the security group for administrators
common_admin_group: admins
# Configuration of Grub boot timeout
common_grub_timeout: 5
postfix_configure: false
# Should we configure postfix?
common_postfix_configure: false
# This relayhost will be set if common_postfix_configure is true
common_postfix_relayhost: some.smtp.server
# Common packages to install in the case of Linux
common_packages:
- libselinux-python
- MySQL-python
- nano
- git
- htop
@@ -26,13 +46,23 @@ common_packages:
- bind-utils
- yum-utils
- unzip
win_packages:
# Common packages to install in the case of Windows
common_win_packages:
- notepadplusplus.install
- firefoxesr
- baretail
- 7zip.install
apply_win_updates: false
common_apply_win_updates: false
common_show_ipv6: false|bool
# Does this node have ipv6? If so set to true to add ipv4 and ipv6 to Dynamic MOTD
common_show_ipv6: false
# Want to change the root password?
common_change_root_pwd: false
# The crypted password you wish to set for root password
# Only fires if common_change_root_pwd is true default = false
common_root_pwd: $6$5GG7U/EyDL$L/UkIlhoVABnvjtJl0zGwryjgRF9wNZ5wIAIAVfViROiMUK0tUsuZmO.x87tpDYUJA0QR5pCo4yd.2sLgSlHU0
# This email address is set as the forwarding address for root. Used for notifications.
common_root_email: anemail@someco.com

View File

@@ -1,131 +1,28 @@
---
galaxy_info:
author: your name
author: Aaron Guise
namespace: cybercinch
role_name: ansible_role_common
description:
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Some suggested licenses:
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: license (GPLv2, CC-BY, etc)
min_ansible_version: 1.2
#
# Below are all platforms currently available. Just uncomment
# the ones that apply to your role. If you don't see your
# platform on this list, let us know and we'll get it added!
#
#platforms:
#- name: EL
# versions:
# - all
# - 5
# - 6
# - 7
#- name: GenericUNIX
# versions:
# - all
# - any
#- name: Solaris
# versions:
# - all
# - 10
# - 11.0
# - 11.1
# - 11.2
# - 11.3
#- name: Fedora
# versions:
# - all
# - 16
# - 17
# - 18
# - 19
# - 20
# - 21
# - 22
# - 23
#- name: Windows
# versions:
# - all
# - 2012R2
#- name: SmartOS
# versions:
# - all
# - any
#- name: opensuse
# versions:
# - all
# - 12.1
# - 12.2
# - 12.3
# - 13.1
# - 13.2
#- name: Amazon
# versions:
# - all
# - 2013.03
# - 2013.09
#- name: GenericBSD
# versions:
# - all
# - any
#- name: FreeBSD
# versions:
# - all
# - 10.0
# - 10.1
# - 10.2
# - 8.0
# - 8.1
# - 8.2
# - 8.3
# - 8.4
# - 9.0
# - 9.1
# - 9.1
# - 9.2
# - 9.3
#- name: Ubuntu
# versions:
# - all
# - lucid
# - maverick
# - natty
# - oneiric
# - precise
# - quantal
# - raring
# - saucy
# - trusty
# - utopic
# - vivid
#- name: SLES
# versions:
# - all
# - 10SP3
# - 10SP4
# - 11
# - 11SP1
# - 11SP2
# - 11SP3
#- name: GenericLinux
# versions:
# - all
# - any
#- name: Debian
# versions:
# - all
# - etch
# - jessie
# - lenny
# - squeeze
# - wheezy
license: MIT
min_ansible_version: 2.9
platforms:
- name: EL
versions:
- all
- name: Windows
versions:
- all
- name: Amazon
versions:
- all
- name: Ubuntu
versions:
- all
- name: Debian
versions:
- all
#
# Below are all categories currently available. Just as with
# the platforms above, uncomment those that apply to your role.
@@ -145,8 +42,4 @@ galaxy_info:
#- packaging
#- system
#- web
dependencies: []
# List your role dependencies here, one per line.
# Be sure to remove the '[]' above if you add dependencies
# to this list.
dependencies: []

View File

@@ -0,0 +1,7 @@
---
- name: Converge
hosts: all
tasks:
- name: "Include ansi-ansible-role-common"
include_role:
name: "ansi-ansible-role-common"

View File

@@ -0,0 +1,14 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: instance
image: docker.io/pycontribs/centos:8
pre_build_image: true
privileged: true
provisioner:
name: ansible
verifier:
name: ansible

View File

@@ -0,0 +1,18 @@
---
# This is an example playbook to execute Ansible tests.
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Capture output of dynamic motd
command: /usr/local/bin/dynmotd
register: motd
changed_when: false
- debug:
msg: "{{ motd.stdout.split('\n') }}"
- name: Example assertion
assert:
that: true

View File

@@ -4,19 +4,17 @@
- name: Ensure common packages
yum:
name: "{{item}}"
name: "{{ common_packages }}"
state: present
enablerepo: epel
with_items: "{{ common_packages }}"
when: ansible_distribution != 'OracleLinux'
tags: packages
- name: Ensure common packages
yum:
name: "{{item}}"
name: "{{ common_packages }}"
state: present
enablerepo: ol7_developer_EPEL
with_items: "{{ common_packages }}"
when: ansible_distribution == 'OracleLinux'
tags: packages
@@ -26,21 +24,8 @@
register: se
tags: security
# - name: SELinux Management
# block:
# - name: selinux | Ensure SELinux status
# selinux:
# state: disabled
# register: sestate
# - name: selinux | Message Output
# debug:
# msg: "SELinux {{ sestate.msg }}"
# when: sestate.changed
# when: se.stat.exists
# tags: security
- name: Create admin group
group: name={{ADMIN_GROUP}} state=present
group: name={{ common_admin_group }} state=present
- name: Configure yum limit
lineinfile:
@@ -62,15 +47,22 @@
- name: Ensure Hostname is set
hostname:
name: "{{ inventory_hostname }}.{{ domain }}"
name: "{{ inventory_hostname }}.{{ common_domain }}"
when:
- ansible_virtualization_type != "docker"
- name: Change root password
user:
name: root
password: "{{ root_pwd }}"
password: "{{ common_root_pwd }}"
changed_when: false
when: common_change_root_pwd
tags: rootpw
- name: Set timezone
timezone:
name: "{{ common_tz }}"
- include: grub.yml
- include: communication.yml
- include: motd.yml

View File

@@ -20,7 +20,7 @@
}
- { dest: /etc/postfix/main.cf,
regexp: "^.?relayhost =",
line: "relayhost = {{ relayhost }}"
line: "relayhost = {{ common_postfix_relayhost }}"
}
- {
dest: /etc/postfix/main.cf,
@@ -33,11 +33,11 @@
name: postfix
state: started
enabled: yes
when: postfix_configure
when: common_postfix_configure
- name: Ensure root forwarding address is set
lineinfile:
dest: ~/.forward
regexp: "{{ root_email }}"
line: "{{ root_email }}"
regexp: "{{ common_root_email }}"
line: "{{ common_root_email }}"
create: yes

View File

@@ -1,2 +1,2 @@
---
- include: "{{ ansible_os_family }}.yml"
- include: "{{ ansible_os_family }}.yml"

View File

@@ -1,4 +1,13 @@
---
- name: Ensure resolvers set
template:
src: etc.resolv.conf.j2
dest: /etc/resolv.conf
mode: u+rw,a+r
tags: dns
when:
- ansible_virtualization_type != "docker"
- name: Ensure DNS and SSH common config
template:
src: "{{ item.src }}"
@@ -10,10 +19,6 @@
dest: /etc/sysconfig/network,
mode: u+rw,a+r
}
- { src: etc.resolv.conf.j2,
dest: /etc/resolv.conf,
mode: u+rw,a+r
}
tags: dns
- name: Ensure hosts file correct
@@ -31,7 +36,7 @@
line: "::1 localhost {{ inventory_hostname }}"
}
- {regexp: "^{{ ansible_default_ipv4.address }}.*{{ ansible_default_ipv4.address.split('.')[-1] }}$",
line: "{{ ansible_default_ipv4.address }} {{ inventory_hostname }}.{{ domain }} {{ inventory_hostname }}"
line: "{{ ansible_default_ipv4.address }} {{ inventory_hostname }}.{{ common_domain }} {{ inventory_hostname }}"
}
- {regexp: "^127.0.0.1.+{{ ansible_nodename.split('.')[0] }}$",
line: "127.0.0.1 localhost {{ inventory_hostname }}"
@@ -40,8 +45,10 @@
line: "::1 localhost {{ inventory_hostname }}"
}
- {regexp: "^{{ ansible_default_ipv4.address }}.*{{ ansible_nodename.split('.')[0] }}$",
line: "{{ ansible_default_ipv4.address }} {{ inventory_hostname }}.{{ domain }} {{ inventory_hostname }}"
line: "{{ ansible_default_ipv4.address }} {{ inventory_hostname }}.{{ common_domain }} {{ inventory_hostname }}"
}
when:
- ansible_virtualization_type != "docker"
- name: Ensure NetworkManager does not fiddle DNS
ini_file:

View File

@@ -20,7 +20,7 @@ HOSTNAME=`/usr/bin/uname -n | /usr/bin/cut -d. -f1`
IP=`/usr/sbin/ip route get 1 | grep -Po '(?<=src.)[\w\d.]+'`
IP6=`/sbin/ip -6 addr | awk -F '[ \t]+|/' '$3 == "::1" { next;} $3 ~ /^fe80::/ { next ; } /inet6/ {print $3} '`
NUM_CPU=`/usr/bin/lscpu | /usr/bin/grep "CPU(s):" | /usr/bin/head -n 1 | /usr/bin/awk '{print $2}'`
ROOT=`/usr/bin/df / -x fuse.gvfs-fuse-daemon -Ph | /usr/bin/egrep -i 'root|logvol|vda' | awk '{print $4}' | tr -d '\n'`
ROOT=`/usr/bin/df / -x fuse.gvfs-fuse-daemon -Ph | /usr/bin/egrep -i 'root|logvol|vda|sda' | awk '{print $4}' | tr -d '\n'`
HOME=`/usr/bin/df /home -x fuse.gvfs-fuse-daemon -Ph | grep home | awk '{print $4}' | tr -d '\n'`
BACKUP=`/usr/bin/df -x fuse.gvfs-fuse-daemon -Ph | grep backup | awk '{print $4}' | tr -d '\n'`
@@ -61,7 +61,7 @@ COLOR_COLUMN="\e[1m-"
COLOR_VALUE="\e[31m"
RESET_COLORS="\e[0m"
echo -e "
===========================================================================
==========================================================================
$COLOR_COLUMN- Hostname$RESET_COLORS............: $COLOR_VALUE $HOSTNAME $RESET_COLORS
{% if common_show_ipv6 == true %}
$COLOR_COLUMN- IP Address (Main v4)$RESET_COLORS: $COLOR_VALUE $IP $RESET_COLORS
@@ -70,7 +70,7 @@ echo -e "
{% endif %}
$COLOR_COLUMN- Release$RESET_COLORS.............: $COLOR_VALUE `cat {{ ansible_distribution_file_path }}` $RESET_COLORS
$COLOR_COLUMN- Users$RESET_COLORS...............: $COLOR_VALUE Currently `users | wc -w` user(s) logged on $RESET_COLORS
=========================================================================== $RESET_COLORS
========================================================================== $RESET_COLORS
$COLOR_COLUMN- Current user$RESET_COLORS........: $COLOR_VALUE $USER $RESET_COLORS
$COLOR_COLUMN- Number of CPU$RESET_COLORS.......: $COLOR_VALUE $NUM_CPU $RESET_COLORS
$COLOR_COLUMN- CPU usage$RESET_COLORS...........: $COLOR_VALUE $LOAD1 - $LOAD5 - $LOAD15 (1-5-15 min) $RESET_COLORS
@@ -79,6 +79,6 @@ echo -e "
$COLOR_COLUMN- Processes$RESET_COLORS...........: $COLOR_VALUE $PSA running $RESET_COLORS
$COLOR_COLUMN- System uptime$RESET_COLORS.......: $COLOR_VALUE $upDays days $upHours hours $upMins minutes $upSecs seconds $RESET_COLORS
$COLOR_COLUMN- Disk space$RESET_COLORS..........: $COLOR_VALUE $ROOT remaining $RESET_COLORS
===========================================================================
==========================================================================
`/usr/bin/cat /etc/motd`
"

View File

@@ -4,7 +4,7 @@
127.0.0.1 localhost {{ ansible_hostname }}
::1 localhost {{ ansible_hostname }}
{{ ansible_default_ipv4.address }} {{ ansible_hostname }}.{{ domain }} {{ ansible_hostname }}
{{ ansible_default_ipv4.address }} {{ ansible_hostname }}.{{ common_domain }} {{ ansible_hostname }}
{# note: below block takes a list of ip -> name mappings
applying them to the hosts file should the variable be

View File

@@ -2,9 +2,9 @@
## DO NOT edit manually as changes will be overwritten ##
# Search Domain
search {{ domain }}
search {{ common_domain }}
# Use servers configured via Ansible
{% for server in dns_servers %}
{% for server in common_dns_servers %}
nameserver {{ server }}
{% endfor %}

View File

@@ -2,4 +2,4 @@
## DO NOT edit manually as changes will be overwritten ##
NETWORKING=yes
HOSTNAME={{ inventory_hostname }}.{{ domain }}
HOSTNAME={{ inventory_hostname }}.{{ common_domain }}