Skip to content

Commit

Permalink
add rancher and docker Ansible roles
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkight committed Nov 7, 2019
1 parent a072b9e commit dd70062
Show file tree
Hide file tree
Showing 20 changed files with 462 additions and 1 deletion.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,31 @@ TASK [k3s-master : update master ip in k3s.yaml] *******************************
changed: [node-19 -> localhost]
```

### rancher-site.yml

Utilizes Ansible roles for docker and rancher to install rancher

#### Usage
```
$ ansible-playbook rancher-site.yml
PLAY [rancher] ***********************************************************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************************************************
ok: [node-3]
```
output filtered
```
TASK [rancher : start rancher in docker] *********************************************************************************************************************************
changed: [node-3]
PLAY RECAP ***************************************************************************************************************************************************************
node-3 : ok=24 changed=20 unreachable=0 failed=0 skipped=12 rescued=0 ignored=0
```

#### Access Rancher
To access the Rancher server UI, open a browser and go to the hostname or address where the container was installed. You will be guided through setting up your first cluster.

## Troubleshooting

### .vaultpass
Expand Down
8 changes: 7 additions & 1 deletion hosts-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ all:
node-28:
node-29:
node-30:
node-3:


children:
Expand All @@ -16,6 +17,7 @@ all:
children:
k3s_masters:
k3s_workers:
rancher:
vars:
ansible_user: ubuntu
proxy: "http://proxy.kightlabs.net:8080"
Expand All @@ -36,4 +38,8 @@ all:
node-29:
node-30:
vars:


rancher:
hosts:
node-3:
vars:
9 changes: 9 additions & 0 deletions rancher-site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

- hosts: rancher
gather_facts: yes

roles:
- common
- docker
- rancher
38 changes: 38 additions & 0 deletions roles/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Role Name
=========

A brief description of the role goes here.

Requirements
------------

Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.

Role Variables
--------------

A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.

Dependencies
------------

A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.

Example Playbook
----------------

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

- hosts: servers
roles:
- { role: username.rolename, x: 42 }

License
-------

BSD

Author Information
------------------

An optional section for the role authors to include contact information, or a website (HTML is not allowed).
2 changes: 2 additions & 0 deletions roles/docker/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# defaults file for docker
2 changes: 2 additions & 0 deletions roles/docker/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for docker
53 changes: 53 additions & 0 deletions roles/docker/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
galaxy_info:
author: your name
description: your 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

# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)

min_ansible_version: 2.4

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

155 changes: 155 additions & 0 deletions roles/docker/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
---
# tasks file for docker

- name: install apt packages
apt:
name: "{{ docker_apt_packages }}"
become: yes
when: ansible_facts['os_family'] == "Debian"

- name: install yum packages
yum:
name: "{{ docker_yum_packages }}"
become: yes
when: ansible_facts['os_family'] == "RedHat"

- name: install docker python library
pip:
name: docker
become: yes

- name: create systemd directory for docker proxy
file:
path: /etc/systemd/system/docker.service.d
state: directory
mode: '0755'
become: yes

- name: create systemd proxy file from template
template:
src: roles/docker/templates/http-proxy.conf.j2
dest: /etc/systemd/system/docker.service.d/http-proxy.conf
mode: '0644'
become: yes

- name: create docker group
group:
name: docker
state: present
become: yes
when: ansible_facts['os_family'] == "Debian"

- name: create dockerroot group
group:
name: dockerroot
state: present
become: yes
when: ansible_facts['os_family'] == "RedHat"

- name: add ansible user to docker group
user:
name: "{{ ansible_user }}"
groups: docker
append: yes
become: yes
when: ansible_facts['os_family'] == "Debian"

- name: add ansible user to dockerroot group
user:
name: "{{ ansible_user }}"
groups: dockerroot
append: yes
become: yes
when: ansible_facts['os_family'] == "RedHat"

- name: load kernel modules
modprobe:
name: "{{ item }}"
state: present
loop: "{{ docker_kernel_modules }}"
become: yes

- name: set sysctl
sysctl:
name: 'net.bridge.bridge-nf-call-iptables'
value: '1'
sysctl_set: yes
state: present
reload: yes
become: yes

- name: disable swap
command: swapoff -a
become: yes

- name: comment out swap in /etc/fstab
replace:
path: /etc/fstab
regexp: '^([^#].*?\sswap\s+sw\s+.*)$'
replace: '# \1'
become: yes

- name: load json from /etc/docker/daemon.json
slurp:
src: /etc/docker/daemon.json
register: original_json
become: yes
when: ansible_facts['os_family'] == "RedHat"

- name: append key/values
set_fact:
merged_json: "{{ original_json.content|b64decode|from_json | default([]) | combine({ 'group': 'dockerroot' }) }}"
when: ansible_facts['os_family'] == "RedHat"

- name: write json to /etc/docker/daemon.json
copy:
content: "{{ merged_json | to_nice_json }}"
dest: /etc/docker/daemon.json
backup: yes
become: yes
when: ansible_facts['os_family'] == "RedHat"

- name: reload and restart docker service
systemd:
state: restarted
enabled: yes
daemon_reload: yes
name: docker
become: yes

- name: stop and disable ufw
systemd:
state: stopped
enabled: no
name: ufw
become: yes
ignore_errors: yes
when: ansible_facts['os_family'] == "Debian"

- name: stop and disable firewalld
systemd:
state: stopped
enabled: no
name: firewalld
become: yes
ignore_errors: yes
when: ansible_facts['os_family'] == "RedHat"

- name: SSH allow tcp forwardwing
lineinfile:
path: /etc/ssh/sshd_config
regexp: '^AllowTcpForwarding '
insertafter: '^#AllowTcpForwarding '
line: AllowTcpForwarding yes
become: yes
register: sshd_config_result

- name: reload and restart sshd service
systemd:
state: restarted
enabled: yes
daemon_reload: yes
name: sshd
become: yes
when: sshd_config_result is changed

2 changes: 2 additions & 0 deletions roles/docker/templates/http-proxy.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Service]
Environment="HTTP_PROXY={{ proxy }}/"
2 changes: 2 additions & 0 deletions roles/docker/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

5 changes: 5 additions & 0 deletions roles/docker/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- docker
43 changes: 43 additions & 0 deletions roles/docker/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
# vars file for docker

docker_apt_packages:
- docker.io
- python3-pip

docker_yum_packages:
- docker
- python-pip

docker_kernel_modules:
- br_netfilter
- ip6_udp_tunnel
- ip_set
- ip_set_hash_ip
- ip_set_hash_net
- iptable_filter
- iptable_nat
- iptable_mangle
- iptable_raw
- nf_conntrack_netlink
- nf_conntrack
- nf_conntrack_ipv4
- nf_defrag_ipv4
- nf_nat
- nf_nat_ipv4
- nf_nat_masquerade_ipv4
- nfnetlink
- udp_tunnel
- veth
- vxlan
- x_tables
- xt_addrtype
- xt_conntrack
- xt_comment
- xt_mark
- xt_multiport
- xt_nat
- xt_recent
- xt_set
- xt_statistic
- xt_tcpudp
Loading

0 comments on commit dd70062

Please sign in to comment.