Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap playbook splitted in roles #1

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f907f7b
Added template in order to allow a user to sudo without a password.
joraman Apr 13, 2016
c1a9ca6
Modification to make use of the template created in the previous commit.
joraman Apr 13, 2016
2a879cb
Merge branch 'master' of https://github.com/guillaumevincent/Ansible-…
joraman Apr 13, 2016
dcf8070
First commit of the rolify branch.
joraman Apr 27, 2016
e3393f3
Moved templates into the user role directory
joraman Apr 27, 2016
a76daed
Created playbook that includes the roles
joraman Apr 27, 2016
d6a5a9a
Added reference to the "vault" file in the roles that need it.
joraman Apr 27, 2016
e861587
Updated README.md
joraman Apr 27, 2016
01dbd42
The timezone is now setup in secrets.yml
joraman Apr 27, 2016
3098b7d
When the a playbook fails, it creates a file with the .retry extensio…
joraman Apr 27, 2016
a21764e
New role to setup fail2ban.
joraman Apr 27, 2016
fceb9b2
Added TIMEZONE var
joraman Apr 27, 2016
dd61189
Returned become_user line to its original state.
joraman Apr 27, 2016
d8ae6d9
Fixed typo
joraman Apr 27, 2016
696b01b
Syntax updated
joraman Apr 27, 2016
b6baaf7
Updated syntax in roles/user/tasks/main.yml
joraman Apr 27, 2016
04d9a3e
Merge branch 'master' of gogs.amorosandreu.cat:jordi/Ansible-My-First…
joraman Apr 27, 2016
d479c99
First commit of the branch automatic_security_updates.
joraman Apr 28, 2016
95cdbfa
Updated template so the Family OS is correct depending on the machine.
joraman Apr 28, 2016
54fe6eb
Added example of inventory file
joraman Apr 28, 2016
28ef7fc
First role that will distinguish between distribution families.
joraman Apr 28, 2016
2882435
Roles adapted to take into account the OS Family.
joraman Apr 28, 2016
d784633
Clean up.
joraman Apr 28, 2016
5f1ddc0
Added Vagrantfile and test_inventory to test the playbook.
joraman Apr 28, 2016
66e91c1
Added README to the test directory so testing the playbook is easier.
joraman Apr 28, 2016
c54f11d
All roles adapted to CentOS.
joraman Apr 28, 2016
e5fa0d1
Updated copyright holder
joraman Apr 28, 2016
6e58d50
Now the VMs are created with the public key already set up for the us…
joraman Apr 29, 2016
ed8d301
Updated the README with the lines I add to .ssh/config.
joraman Apr 29, 2016
5b533f9
Afegits paquets per a Debian/Ubuntu
joraman Aug 8, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
.idea/

### Project specific stuff:
/secrets.yml
/secrets.yml
*retry
inventori
test/.vagrant/*
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Guillaume Vincent
Copyright (c) 2016 Jordi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Use this playbook if you want to improve the security of your server and want to
- setup firewall
- disallow password authentication
- disallow root SSH access
- setup the time


## tldr
Expand Down Expand Up @@ -92,6 +93,7 @@ the encrypted information that you need to change :
ADMIN_USERNAME: admin
PUBLIC_KEYS:
- ~/.ssh/id_rsa.pub
TIMEZONE: 'xxxxxx'
#EXTRA_PACKAGES:
# - vim
# - htop
Expand Down Expand Up @@ -129,4 +131,20 @@ Imagine you run SSH on port 2222 and your ssh daemon crashes. Now any local user

See why it's probably better to stay on port 22 [Should I change the default SSH port on linux servers?](http://security.stackexchange.com/a/32311/26203)

Thanks Cryonine
Thanks Cryonine

### How to use the inventory file

Having the write

--inventory-file='192.168.1.100,'

is not optimal and makes the command innecessarily long quite fast when you add more and more servers. The solution is quite
simple, edit the file called inventoire and add your own list of IPs. Or create your own (remember to also add it to the
.gitignore file).

ansible-playbook --private-key=~/.ssh/id_rsa --ask-become-pass --ask-vault-pass -i inventoire bootstrap.yml

If we want to limit the run of the playbook to just one machine:

ansible-playbook --private-key=~/.ssh/id_rsa --ask-become-pass --ask-vault-pass -i inventoire bootstrap.yml -l server1
95 changes: 0 additions & 95 deletions bootstrap.yml

This file was deleted.

28 changes: 28 additions & 0 deletions bootstrap_roles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
- hosts: all
become: yes
become_user: root

vars:
SSH_PORT: 22
DEFAULT_PACKAGES:
- ufw
- fail2ban
- lsof
- vim
- tmux
- htop
DEFAULT_PACKAGES_RED:
- fail2ban
- vim
- htop
- tmux
- firewalld

roles:
- user
- packages
- ssh
- time
- config_fail2ban
- auto_sec_updates
4 changes: 4 additions & 0 deletions inventoire
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
server1 ansible_ssh_host=192.168.0.21 ansible_ssh_user=pi
server2 ansible_ssh_host=192.168.0.22 ansible_ssh_user=pi
...
servern ansible_ssh_host=192.168.0.n ansible_ssh_user=pi
4 changes: 4 additions & 0 deletions roles/auto_sec_updates/files/10periodic
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Unattended-Upgrade "1";
21 changes: 21 additions & 0 deletions roles/auto_sec_updates/tasks/deb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Install unattended-upgrades
apt: state=installed pkg={{ item }}
with_items:
- unattended-upgrades

- name: Setup 10periodic
copy:
src: files/10periodic
dest: /etc/fail2ban/jail.local
owner: root
group: root
mode: 0644

- name: Setup allowed origins
template:
src: templates/50unattended-upgrades.j2
dest: /etc/apt/apt.conf.d/50unattended-upgrades
owner: root
group: root
mode: 0644
6 changes: 6 additions & 0 deletions roles/auto_sec_updates/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- include: deb.yml
when: ansible_os_family == 'Debian' or ansible_distribution == 'Ubuntu'

- include: red.yml
when: ansible_os_family == 'RedHat'
3 changes: 3 additions & 0 deletions roles/auto_sec_updates/tasks/red.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: Message
debug: msg="Automatic security updates only available on RedHat"
3 changes: 3 additions & 0 deletions roles/auto_sec_updates/templates/50unattended-upgrades.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Unattended-Upgrade::Allowed-Origins {
"{{ ansible_distribution }} {{ ansible_distribution_release }}-security";
};