Files
convert-images-for-web/roles/common/tasks/main.yml

190 lines
4.4 KiB
YAML

---
# This playbook contains plays that will run on all nodes
- name: Add docker key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
- name: Add docker repo
apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable
state: present
- name: Update apt
apt: update_cache=yes
#- name: Upgrade APT to the lastest packages
# apt: upgrade=dist
- name: Install standard programs
apt: name={{ item }} state=present force=yes
with_items:
- htop
- curl
- openssh-server
- git
- rsync
- zip
- unzip
- fail2ban
- ntp
- mysql-client
- wget
- nfs-common
- docker-ce={{docker_ce_version_to_install}}
- sshpass
- ack-grep
- dnsutils
- nmon
- build-essential
- tmux
- name: Create standard user
user:
name: "{{ standard_user }}"
groups:
- sudo
- docker
state: present
shell: /bin/bash
- name: Add standard_user to docker group
user:
name: "{{ standard_user }}"
groups: docker
append: yes
- name: Set authorized key took from url
become: yes
become_user: "{{ standard_user }}"
authorized_key:
user: "{{ standard_user }}"
state: present
key: "{{ home_pub_key }}"
- name: Docker compose version
get_url:
url: "https://github.com/docker/compose/releases/download/{{docker_compose_version_to_install}}/docker-compose-{{ ansible_system }}-{{ ansible_userspace_architecture }}"
dest: /usr/local/bin/docker-compose
validate_certs: false
mode: 755
group: docker
- name: Set timezone to NewYork
timezone:
name: America/New_York
ignore_errors: true
- name: Replace sudoers file
template: src=../roles/common/templates/sudoers.j2 dest=/etc/sudoers
- name: Create /etc/docker
file:
path: /etc/docker
group: root
owner: root
mode: 700
state: directory
- name: Replace docker daemon file
template: src=../roles/common/templates/docker-daemon.json.j2 dest=/etc/docker/daemon.json
register: dockerdaemon
- name: Restart docker if daemon changes
service:
name: docker
state: restarted
when: dockerdaemon.changed
- name: Creates directory
file: path=/data state=directory
- name: Data is mounted
stat: path=/data/swarm
register: data_mounted
- name: USB lab data in fstab
when: not data_mounted.stat.exists
lineinfile: dest=/etc/fstab
regexp=\/data
state=present
line="{{ nfs_location }}:{{ nfs_share }}/raw-files/fileserver/shares/lab-data /data nfs defaults,nolock 0 0"
- name: Mount USB lab data directory
mount:
path: /data
src: 10.0.0.150:{{ nfs_share }}/raw-files/fileserver/shares/lab-data
state: mounted
fstype: nfs
ignore_errors: true
- name: test for swap partition
shell: swapon -s | grep -E "^/"
register: swapfile
ignore_errors: yes
- name: create swapfile
when: swapfile|failed
shell: fallocate -l 4G /swapfile
ignore_errors: yes
- name: set swapfile permissions
when: swapfile|failed
file: path=/swapfile
owner=root
group=root
mode=0600
- name: prepare swapfile
when: swapfile|failed
shell: mkswap /swapfile
ignore_errors: yes
- name: enable swap
when: swapfile|failed
shell: swapon /swapfile
ignore_errors: yes
- name: add swapfile
when: swapfile|failed
lineinfile: dest=/etc/fstab
regexp="^/swapfile"
state=present
line="/swapfile none swap sw 0 0"
- name: set swappiness (temporarily)
when: swapfile|failed
shell: echo 10 > /proc/sys/vm/swappiness
ignore_errors: yes
- name: set swappiness (permanent)
when: swapfile|failed
lineinfile: dest=/etc/sysctl.conf
regexp="^vm.swappiness"
state=present
line="vm.swappiness = 10"
- name: set cache pressure (temporarily)
when: swapfile|failed
shell: echo 50 > /proc/sys/vm/vfs_cache_pressure
ignore_errors: yes
- name: set cache pressure (permanent)
when: swapfile|failed
lineinfile: dest=/etc/sysctl.conf
regexp="^vm.vfs_cache_pressure"
state=present
line="vm.vfs_cache_pressure = 50"
- name: Set hostname
hostname:
name: '{{ inventory_hostname }}'
- name: Fix hosts file
replace:
path: /etc/hosts
regexp: '(\s+)ubuntu(\s+.*)?$'
replace: '\1{{ inventory_hostname }}\2'
backup: yes