import files
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
---
|
||||
# file: tasks/boot.yml
|
||||
|
||||
- name: boot - define config
|
||||
set_fact:
|
||||
boot_config:
|
||||
# set clocksource at boot
|
||||
- dest: /etc/update-extlinux.conf
|
||||
line: 'default_kernel_opts="\1 clocksource=tsc tsc=reliable"'
|
||||
regex: '^default_kernel_opts="((?!.*clocksource=tsc tsc=reliable).*)"$'
|
||||
|
||||
- name: boot - stat config file
|
||||
changed_when: false
|
||||
register: boot_config_stat
|
||||
stat:
|
||||
path: '{{item.dest}}'
|
||||
with_items: '{{boot_config|default([])}}'
|
||||
|
||||
- name: boot - update config
|
||||
become: yes
|
||||
lineinfile:
|
||||
backrefs: true
|
||||
dest: '{{item.0.dest}}'
|
||||
line: '{{item.0.line}}'
|
||||
regex: '{{item.0.regex}}'
|
||||
with_together:
|
||||
- '{{boot_config|default([])}}'
|
||||
- '{{boot_config_stat.results}}'
|
||||
when: item.1.stat.exists
|
||||
register: boot_config_handler_notify
|
||||
notify:
|
||||
- update boot config
|
||||
@@ -0,0 +1,48 @@
|
||||
---
|
||||
# file: tasks/cloudinit.yml
|
||||
|
||||
- name: cloudinit - install cloud-init packages
|
||||
package: name="cloud-init" state="present"
|
||||
become: yes
|
||||
when: hosts_enable_cloudinit|default(false) and ansible_os_family|lower != "alpine"
|
||||
|
||||
- name: cloudinit - install cloud-init packages
|
||||
apk: name="{{item.name}}" state="{{item.state}}"
|
||||
apk:
|
||||
name: cloud-init
|
||||
state: present
|
||||
repository:
|
||||
- http://dl-cdn.alpinelinux.org/alpine/edge/main
|
||||
- http://dl-cdn.alpinelinux.org/alpine/edge/testing
|
||||
- http://dl-cdn.alpinelinux.org/alpine/edge/community
|
||||
- http://dl-cdn.alpinelinux.org/alpine/latest-stable/main
|
||||
- http://dl-cdn.alpinelinux.org/alpine/latest-stable/community
|
||||
with_items:
|
||||
- { "name": "cloud-init", "state": "present" }
|
||||
- { "name": "cloud-init-openrc", "state": "present" }
|
||||
become: yes
|
||||
when: hosts_enable_cloudinit|default(false) and ansible_os_family|lower == "alpine"
|
||||
|
||||
- name: cloudinit - update /etc/cloud/cloud.cfg
|
||||
template:
|
||||
src: etc/cloud/cloud.cfg.j2
|
||||
dest: /etc/cloud/cloud.cfg
|
||||
force: yes
|
||||
when: hosts_enable_cloudinit|default(false)
|
||||
|
||||
- name: cloudinit - activate service
|
||||
service:
|
||||
name: cloud-init
|
||||
state: started
|
||||
enabled: yes
|
||||
when: hosts_enable_cloudinit|default(false) and ansible_service_mgr|lower != "openrc"
|
||||
become: yes
|
||||
|
||||
- name: cloudinit - activate service (openrc)
|
||||
service:
|
||||
name: cloud-init
|
||||
state: started
|
||||
enabled: yes
|
||||
runlevel: boot
|
||||
when: hosts_enable_cloudinit|default(false) and ansible_service_mgr|lower == "openrc"
|
||||
become: yes
|
||||
@@ -0,0 +1,37 @@
|
||||
---
|
||||
# file: tasks/files.yml
|
||||
|
||||
- name: files - copy files
|
||||
with_items:
|
||||
- /etc/issue.net
|
||||
- /etc/profile.d/rc.sh
|
||||
- /etc/profile.d/rc_functions.sh
|
||||
copy: src=../files/{{item}} dest={{item}} owner=root group=root mode=0644
|
||||
become: yes
|
||||
|
||||
- name: files - copy binary files
|
||||
with_items:
|
||||
- /etc/init.d/zram
|
||||
copy: src=../files/{{item}} dest={{item}} owner=root group=root mode=0755
|
||||
become: yes
|
||||
|
||||
- name: files - copy systemd files
|
||||
with_items:
|
||||
- /etc/systemd/system/zram.service
|
||||
copy: src=../files/{{item}} dest={{item}} owner=root group=root mode=0644
|
||||
when: ansible_service_mgr|lower == "systemd"
|
||||
become: yes
|
||||
|
||||
- name: files - copy openrc files
|
||||
with_items:
|
||||
- /etc/init.d/zram-openrc
|
||||
- /etc/local.d/ansible.start
|
||||
copy: src=../files/{{item}} dest={{item}} owner=root group=root mode=0755
|
||||
when: ansible_service_mgr|lower == "openrc"
|
||||
become: yes
|
||||
|
||||
- name: files - get remote binary files
|
||||
with_items:
|
||||
- https://raw.githubusercontent.com/dylanaraps/pfetch/master/pfetch
|
||||
get_url: url={{item}} dest=/usr/local/bin owner=root group=root mode=0755
|
||||
become: yes
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
# file: tasks/git.yml
|
||||
|
||||
- name: git - clone repositories
|
||||
with_items: "{{ hosts_git_repositories|default([]) }}"
|
||||
git:
|
||||
repo: "{{ item.repo }}"
|
||||
dest: "{{ item.dest|default('/src') }}"
|
||||
key_file: "{{ item.key_file|default('~/.ssh/id_rsa') }}"
|
||||
version: "{{ item.version|default('HEAD') }}"
|
||||
@@ -0,0 +1,30 @@
|
||||
---
|
||||
# file: tasks/main.yml
|
||||
|
||||
- import_tasks: vars.yml
|
||||
tags:
|
||||
- vars
|
||||
- import_tasks: boot.yml
|
||||
tags:
|
||||
- boot
|
||||
- import_tasks: cloudinit.yml
|
||||
tags:
|
||||
- cloudinit
|
||||
- import_tasks: packages.yml
|
||||
tags:
|
||||
- packages
|
||||
- import_tasks: ssh.yml
|
||||
tags:
|
||||
- ssh
|
||||
- import_tasks: files.yml
|
||||
tags:
|
||||
- files
|
||||
- import_tasks: git.yml
|
||||
tags:
|
||||
- git
|
||||
- import_tasks: service.yml
|
||||
tags:
|
||||
- service
|
||||
- import_tasks: user.yml
|
||||
tags:
|
||||
- user
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
# file: tasks/packages.yml
|
||||
|
||||
- name: packages - install/remove packages
|
||||
package: name="{{item.name}}" state="{{item.state}}"
|
||||
with_items: "{{hosts_packages_common|default([]) + hosts_packages_distro|default([]) + hosts_packages|default([])}}"
|
||||
become: yes
|
||||
@@ -0,0 +1,26 @@
|
||||
---
|
||||
# file: tasks/service.yml
|
||||
|
||||
- name: service - activate local (openrc)
|
||||
service:
|
||||
name: local
|
||||
enabled: yes
|
||||
when: hosts_enable_local|default(false) and ansible_service_mgr|lower == "openrc"
|
||||
become: yes
|
||||
|
||||
- name: service - activate zram
|
||||
service:
|
||||
name: zram
|
||||
state: started
|
||||
enabled: yes
|
||||
when: hosts_enable_zram|default(false) and ansible_service_mgr|lower != "openrc"
|
||||
become: yes
|
||||
|
||||
- name: service - activate zram (openrc)
|
||||
service:
|
||||
name: zram-openrc
|
||||
state: started
|
||||
enabled: yes
|
||||
runlevel: boot
|
||||
when: hosts_enable_zram|default(false) and ansible_service_mgr|lower == "openrc"
|
||||
become: yes
|
||||
@@ -0,0 +1,48 @@
|
||||
---
|
||||
# file: tasks/ssh.yml
|
||||
|
||||
- name: ssh - add keys to file ~/.ssh/authorized_keys
|
||||
authorized_key: user="root" key=https://github.com/{{item}}.keys
|
||||
with_items: "{{hosts_ssh_users|default([])}}"
|
||||
become: yes
|
||||
|
||||
- name: ssh - copy ssh private keys
|
||||
with_items: "{{hosts_ssh_private_keys|default([])}}"
|
||||
copy: src={{item}} dest=~/.ssh/ mode=0400
|
||||
become: yes
|
||||
|
||||
- name: ssh - add public hosts keys to known_hosts
|
||||
with_items: "{{hosts_ssh_public_hosts_keys|default([])}}"
|
||||
known_hosts:
|
||||
name: "{{item.name}}"
|
||||
key: "{{ lookup('file', '{{item.key}}') }}"
|
||||
become: yes
|
||||
|
||||
- name: ssh - define configuration
|
||||
set_fact:
|
||||
sshd_config:
|
||||
- dest: /etc/conf.d/dropbear
|
||||
line: 'DROPBEAR_OPTS="\1 -b /etc/issue.net"'
|
||||
regex: '^DROPBEAR_OPTS="((?!.*-b /etc/issue.net).*)"$'
|
||||
- dest: /etc/ssh/sshd_config
|
||||
line: Banner /etc/issue.net
|
||||
regex: ^#?Banner
|
||||
|
||||
- name: ssh - stat configuration file
|
||||
changed_when: false
|
||||
register: sshd_config_stat
|
||||
stat:
|
||||
path: '{{item.dest}}'
|
||||
with_items: '{{sshd_config|default([])}}'
|
||||
|
||||
- name: ssh - configure sshd
|
||||
become: yes
|
||||
lineinfile:
|
||||
backrefs: true
|
||||
dest: '{{item.0.dest}}'
|
||||
line: '{{item.0.line}}'
|
||||
regex: '{{item.0.regex}}'
|
||||
with_together:
|
||||
- '{{sshd_config|default([])}}'
|
||||
- '{{sshd_config_stat.results}}'
|
||||
when: item.1.stat.exists
|
||||
@@ -0,0 +1,66 @@
|
||||
---
|
||||
# file: tasks/user.yml
|
||||
|
||||
- name: user - create ~/.env
|
||||
template:
|
||||
src: .env.j2
|
||||
dest: ~/.env
|
||||
force: no
|
||||
mode: 0400
|
||||
|
||||
- name: user - create ~/.rc.d
|
||||
file: path=~/.rc.d/ state={{hosts_enable_rc|default(false)|ternary('directory', 'absent')}} mode="0700"
|
||||
|
||||
- name: user - activate rc functions
|
||||
with_items: "{{hosts_rc_functions|default([])}}"
|
||||
file: path="~/.rc.d/{{item}}" state="touch" mode="0600"
|
||||
when: hosts_enable_rc|default(false)
|
||||
|
||||
- name: user - disable rc functions
|
||||
with_items: "{{hosts_rc_cleanup|default([])}}"
|
||||
file: path="~/.rc.d/{{item}}" state="absent" mode="0600"
|
||||
when: hosts_enable_rc|default(false)
|
||||
|
||||
- name: user - create directories
|
||||
with_items:
|
||||
- ~/.config
|
||||
- ~/.config/git
|
||||
file:
|
||||
path: "{{item}}"
|
||||
state: directory
|
||||
|
||||
- name: user - update ~/.config/git/ignore
|
||||
with_items:
|
||||
- '.nfs*'
|
||||
- '*~'
|
||||
- '*.log'
|
||||
- '*.swp'
|
||||
lineinfile: dest=~/.config/git/ignore create=yes line='{{item}}'
|
||||
|
||||
- name: user - update ~/.profile
|
||||
with_items:
|
||||
- alias ctop='docker run --rm -ti --volume /var/run/docker.sock:/var/run/docker.sock:ro quay.io/vektorlab/ctop:latest'
|
||||
- alias vi='vim'
|
||||
- export EDITOR='vim'
|
||||
- export PAGER='less'
|
||||
lineinfile: dest=~/.profile create=yes line='{{item}}'
|
||||
|
||||
- name: user - update ~/.screenrc
|
||||
with_items:
|
||||
- defscrollback 1024
|
||||
- hardstatus alwayslastline "%{= kw}[%{G}$USER@%H%{-}] \# %?%-Lw%?[%{G}%n%f %t%{-}]%?%+Lw%?%?%=%-17< [%{B}%l%{-}]"
|
||||
- shell -$SHELL
|
||||
lineinfile: dest=~/.screenrc create=yes line='{{item}}'
|
||||
|
||||
- name: user - update ~/.vimrc
|
||||
with_items:
|
||||
- :set et ai bg=dark sw=4 ts=4 encoding=utf-8 mouse=""
|
||||
- :syn on
|
||||
- :filetype plugin indent on
|
||||
lineinfile: dest=~/.vimrc create=yes line='{{item}}'
|
||||
|
||||
- name: user - update ~/Makefile
|
||||
template:
|
||||
src: Makefile.j2
|
||||
dest: ~/Makefile
|
||||
force: yes
|
||||
@@ -0,0 +1,34 @@
|
||||
---
|
||||
# file: tasks/vars.yml
|
||||
|
||||
- name: vars - load per operating system variables
|
||||
include_vars: "{{item}}"
|
||||
with_first_found:
|
||||
- paths:
|
||||
- "vars/"
|
||||
- files:
|
||||
- "{{ansible_distribution|lower}}-{{ansible_distribution_version|lower}}-{{ansible_machine}}.yml" # centos-6.4-i386.yml ubuntu-16.04-x86_64.yml
|
||||
- "{{ansible_distribution|lower}}-{{ansible_distribution_version|lower}}.yml" # centos-6.4.yml ubuntu-16.04.yml
|
||||
- "{{ansible_distribution|lower}}-{{ansible_distribution_major_version|lower}}-{{ansible_machine}}.yml" # centos-6-i386.yml ubuntu-16-x86_64.yml
|
||||
- "{{ansible_distribution|lower}}-{{ansible_distribution_major_version|lower}}.yml" # centos-6.yml ubuntu-16.yml
|
||||
- "{{ansible_os_family|lower}}-{{ansible_distribution_version|lower}}-{{ansible_machine}}.yml" # redhat-6.4-i386.yml debian-8.5-x86_64.yml
|
||||
- "{{ansible_os_family|lower}}-{{ansible_distribution_version|lower}}.yml" # redhat-6.4.yml debian-8.5.yml
|
||||
- "{{ansible_os_family|lower}}-{{ansible_distribution_major_version|lower}}-{{ansible_machine}}.yml" # redhat-6-i386.yml debian-8-x86_64.yml
|
||||
- "{{ansible_os_family|lower}}-{{ansible_distribution_major_version|lower}}.yml" # redhat-6.yml debian-8.yml
|
||||
- "{{ansible_distribution|lower}}-{{ansible_machine}}.yml" # centos-i386.yml ubuntu-x86_64.yml
|
||||
- "{{ansible_distribution|lower}}.yml" # centos.yml ubuntu.yml
|
||||
- "{{ansible_os_family|lower}}-{{ansible_machine}}.yml" # redhat-i386.yml debian-x86_64.yml
|
||||
- "{{ansible_os_family|lower}}.yml" # redhat.yml debian.yml
|
||||
- "{{ansible_system|lower}}-{{ansible_machine}}.yml" # linux-i386.yml linux-x86_64.yml
|
||||
- "{{ansible_system|lower}}.yml" # linux.yml
|
||||
- "default.yml" # default.yml
|
||||
skip: true
|
||||
|
||||
- name: vars - override with local variables
|
||||
include_vars: "{{item}}"
|
||||
with_first_found:
|
||||
- paths:
|
||||
- "vars/"
|
||||
- files:
|
||||
- "local.yml"
|
||||
skip: true
|
||||
Reference in New Issue
Block a user