diff --git a/playbooks/golang/golang.yml b/playbooks/golang/golang.yml deleted file mode 100644 index b4609b6..0000000 --- a/playbooks/golang/golang.yml +++ /dev/null @@ -1,43 +0,0 @@ ---- -- hosts: golang - vars: - # Personal Go configuration - - golang_user: "root" - - golang_home_dir: "/root" - - golang_personal_gopath: "github.com/mdlayher" - # Go installation configuration - - golang_url: "https://storage.googleapis.com/golang/go1.6.1.linux-amd64.tar.gz" - - golang_tgz: "/tmp/golang.tar.gz" - - golang_sha256: "6d894da8b4ad3f7f6c295db0d73ccc3646bce630e1c43e662a0120681d47e988" - - golang_root: "/usr/local/go" - tasks: - - name: install git - apt: pkg=git state=installed - - - name: install mercurial - apt: pkg=mercurial state=installed - - - name: download and checksum go tarball - get_url: url={{ golang_url }} dest={{ golang_tgz }} checksum=sha256:{{ golang_sha256 }} - - - name: unpack tarball - unarchive: src={{ golang_tgz }} dest=/usr/local/ copy=no - - - name: insert go configuration into shell configuration - blockinfile: - dest: /{{ golang_user }}/.bashrc - marker: "# {mark} ansible-managed Go configuration" - block: | - export GOROOT={{ golang_root }} - export GOROOT_BOOTSTRAP=$GOROOT - export GOPATH=$HOME - export PATH=$PATH:$GOROOT/bin:$GOPATH/bin - - - name: create personal GOPATH location - file: path={{ golang_home_dir }}/src/{{ golang_personal_gopath }} state=directory - - - name: symlink personal GOPATH location to ~/go - file: dest={{ golang_home_dir }}/go src={{ golang_home_dir }}/src/{{ golang_personal_gopath }} owner={{ golang_user }} group={{ golang_user }} state=link - - - name: remove temporary go tarball - file: path={{ golang_tgz }} state=absent diff --git a/playbooks/plex/plex.yml b/playbooks/plex/plex.yml deleted file mode 100644 index c7f88c5..0000000 --- a/playbooks/plex/plex.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -- hosts: plex - vars: - - plex_url: "https://downloads.plex.tv/plex-media-server/0.9.16.4.1911-ee6e505/plexmediaserver_0.9.16.4.1911-ee6e505_amd64.deb" - - plex_deb: "/tmp/plex.deb" - - plex_sha1: "c056838454953857fec2622ddd7350635723c09e" - tasks: - - name: download and checksum plex debian package - get_url: url={{ plex_url }} dest={{ plex_deb }} checksum=sha1:{{ plex_sha1 }} - - - name: install plex - apt: deb={{ plex_deb }} state=installed - - - name: remove temporary plex debian package - file: path={{ plex_deb }} state=absent - - - name: start plex service - service: name=plexmediaserver state=started enabled=yes diff --git a/playbooks/prometheus/prometheus.yml b/playbooks/prometheus/prometheus.yml deleted file mode 100644 index 5e91964..0000000 --- a/playbooks/prometheus/prometheus.yml +++ /dev/null @@ -1,75 +0,0 @@ ---- -- hosts: prometheus - vars: - # Prometheus version and checksum configuration - - prometheus_version: "0.18.0rc1" - - prometheus_sha1: "915b0396b9ed973842c3c3e5394caec24269fa37" - # Prometheus configuration and data storage locations - - prometheus_config: "/etc/prometheus/prometheus.yml" - - prometheus_data: "/var/lib/prometheus/" - # Prometheus jobs configuration - - prometheus_jobs: - - job: "edgemax" - targets: - - "192.168.1.3:9132" - - job: "node" - targets: - - "192.168.1.3:9100" - - "192.168.1.5:9100" - - "192.168.1.20:9100" - - job: "prometheus" - scrape_interval: "5s" - targets: - - "192.168.1.3:9090" - - job: "rtorrent" - scrape_interval: "5s" - targets: - - "192.168.1.3:9135" - - job: "unifi" - targets: - - "unifi.servnerr.com:9130" - - job: "zfs" - targets: - - "192.168.1.3:9134" - # Static configuration. - - prometheus_dir: "prometheus-{{ prometheus_version }}.linux-amd64" - - prometheus_tmp: "/tmp/{{ prometheus_dir }}" - - prometheus_url: "https://github.com/prometheus/prometheus/releases/download/{{ prometheus_version }}/{{ prometheus_dir }}.tar.gz" - - prometheus_tgz: "/tmp/prometheus.tar.gz" - tasks: - - name: stop prometheus service - service: name=prometheus state=stopped - - - name: download and checksum prometheus tarball - get_url: url={{ prometheus_url }} dest={{ prometheus_tgz }} checksum=sha1:{{ prometheus_sha1 }} - - - name: unpack tarball - unarchive: src={{ prometheus_tgz }} dest=/tmp/ copy=no - - - name: create prometheus user - user: name=prometheus shell=/bin/false comment="prometheus service user" - - - name: copy prometheus binary to /usr/local/bin - copy: src={{ prometheus_tmp }}/prometheus dest=/usr/local/bin/ owner=prometheus group=prometheus mode=0755 - - - name: copy promtool binary to /usr/local/bin - copy: src={{ prometheus_tmp }}/promtool dest=/usr/local/bin/ owner=prometheus group=prometheus mode=0755 - - - name: create prometheus configuration - template: src=templates/prometheus.yml.j2 dest={{ prometheus_config }} - with_items: "{{ prometheus_jobs }}" - - - name: create prometheus data directory - file: path={{ prometheus_data }} state=directory owner=prometheus group=prometheus mode=0755 - - - name: create prometheus upstart job - template: src=templates/prometheus.conf.j2 dest=/etc/init/prometheus.conf - - - name: start prometheus service - service: name=prometheus state=started enabled=yes - - - name: remove temporary prometheus directory - file: path={{ prometheus_tmp }} state=absent - - - name: remove temporary prometheus tarball - file: path={{ prometheus_tgz }} state=absent diff --git a/playbooks/rtorrent/rtorrent.yml b/playbooks/rtorrent/rtorrent.yml deleted file mode 100644 index 4c0b364..0000000 --- a/playbooks/rtorrent/rtorrent.yml +++ /dev/null @@ -1,36 +0,0 @@ ---- -- hosts: rtorrent - vars: - # Client configurations - - rtorrent_port: 58575 - - rtorrent_download_rate: 10000 - - rtorrent_upload_rate: 400 - - rtorrent_low_diskspace: "1G" - # Path configurations - - rtorrent_path_root: "/mnt/rtorrent" - - rtorrent_path_files: "{{ rtorrent_path_root }}/files" - - rtorrent_path_session: "{{ rtorrent_path_root }}/.session" - - rtorrent_path_watch: "{{ rtorrent_path_root }}/watch" - tasks: - - name: install rtorrent - apt: pkg=rtorrent state=installed - register: rtorrentinstalled - - - name: fail the play if rtorrent could not be installed - when: rtorrentinstalled|failed - fail: msg="failed to install rtorrent" - - - name: create rtorrent user - user: name=rtorrent shell=/bin/false comment="rtorrent service user" - - - name: create rtorrent configuration - template: src=rtorrent.rc.j2 dest=/home/rtorrent/.rtorrent.rc owner=rtorrent group=rtorrent mode=0755 - - - name: create files directory - file: path={{ rtorrent_path_files }} state=directory owner=rtorrent group=rtorrent mode=0755 - - - name: create watch directory - file: path={{ rtorrent_path_watch }} state=directory owner=rtorrent group=rtorrent mode=0755 - - - name: create session directory - file: path={{ rtorrent_path_session }} state=directory owner=rtorrent group=rtorrent mode=0755 diff --git a/roles/golang/tasks/main.yml b/roles/golang/tasks/main.yml new file mode 100644 index 0000000..8e9d513 --- /dev/null +++ b/roles/golang/tasks/main.yml @@ -0,0 +1,31 @@ +--- +- name: install git + apt: pkg=git state=installed + +- name: install mercurial + apt: pkg=mercurial state=installed + +- name: download and checksum go tarball + get_url: url={{ golang_url }} dest={{ golang_tgz }} checksum=sha256:{{ golang_sha256 }} + +- name: unpack tarball + unarchive: src={{ golang_tgz }} dest=/usr/local/ copy=no + +- name: insert go configuration into shell configuration + blockinfile: + dest: /{{ golang_user }}/.bashrc + marker: "# {mark} ansible-managed Go configuration" + block: | + export GOROOT={{ golang_root }} + export GOROOT_BOOTSTRAP=$GOROOT + export GOPATH=$HOME + export PATH=$PATH:$GOROOT/bin:$GOPATH/bin + +- name: create personal GOPATH location + file: path={{ golang_home_dir }}/src/{{ golang_personal_gopath }} state=directory + +- name: symlink personal GOPATH location to ~/go + file: dest={{ golang_home_dir }}/go src={{ golang_home_dir }}/src/{{ golang_personal_gopath }} owner={{ golang_user }} group={{ golang_user }} state=link + +- name: remove temporary go tarball + file: path={{ golang_tgz }} state=absent diff --git a/roles/golang/vars/main.yml b/roles/golang/vars/main.yml new file mode 100644 index 0000000..6eb46ed --- /dev/null +++ b/roles/golang/vars/main.yml @@ -0,0 +1,10 @@ +--- +# Personal Go configuration +golang_user: "root" +golang_home_dir: "/root" +golang_personal_gopath: "github.com/mdlayher" +# Go installation configuration +golang_url: "https://storage.googleapis.com/golang/go1.6.1.linux-amd64.tar.gz" +golang_tgz: "/tmp/golang.tar.gz" +golang_sha256: "6d894da8b4ad3f7f6c295db0d73ccc3646bce630e1c43e662a0120681d47e988" +golang_root: "/usr/local/go" diff --git a/roles/plex/tasks/main.yml b/roles/plex/tasks/main.yml new file mode 100644 index 0000000..2b94c35 --- /dev/null +++ b/roles/plex/tasks/main.yml @@ -0,0 +1,12 @@ +--- +- name: download and checksum plex debian package + get_url: url={{ plex_url }} dest={{ plex_deb }} checksum=sha1:{{ plex_sha1 }} + +- name: install plex + apt: deb={{ plex_deb }} state=installed + +- name: remove temporary plex debian package + file: path={{ plex_deb }} state=absent + +- name: start plex service + service: name=plexmediaserver state=started enabled=yes diff --git a/roles/plex/vars/main.yml b/roles/plex/vars/main.yml new file mode 100644 index 0000000..7ed7577 --- /dev/null +++ b/roles/plex/vars/main.yml @@ -0,0 +1,4 @@ +--- +plex_url: "https://downloads.plex.tv/plex-media-server/0.9.16.4.1911-ee6e505/plexmediaserver_0.9.16.4.1911-ee6e505_amd64.deb" +plex_deb: "/tmp/plex.deb" +plex_sha1: "c056838454953857fec2622ddd7350635723c09e" diff --git a/roles/prometheus/tasks/main.yml b/roles/prometheus/tasks/main.yml new file mode 100644 index 0000000..f1c5ea8 --- /dev/null +++ b/roles/prometheus/tasks/main.yml @@ -0,0 +1,45 @@ +--- +- name: check if prometheus service exists + stat: path=/etc/init/prometheus.conf + register: prometheusexists + +- name: stop prometheus service + service: name=prometheus state=stopped + when: prometheusexists.stat.exists + +- name: download and checksum prometheus tarball + get_url: url={{ prometheus_url }} dest={{ prometheus_tgz }} checksum=sha1:{{ prometheus_sha1 }} + +- name: unpack tarball + unarchive: src={{ prometheus_tgz }} dest=/tmp/ copy=no + +- name: create prometheus user + user: name=prometheus shell=/bin/false comment="prometheus service user" + +- name: copy prometheus binary to /usr/local/bin + copy: src={{ prometheus_tmp }}/prometheus dest=/usr/local/bin/ owner=prometheus group=prometheus mode=0755 + +- name: copy promtool binary to /usr/local/bin + copy: src={{ prometheus_tmp }}/promtool dest=/usr/local/bin/ owner=prometheus group=prometheus mode=0755 + +- name: create prometheus config directory + file: path={{ prometheus_config }} state=directory owner=prometheus group=prometheus mode=0755 + +- name: create prometheus configuration + template: src=prometheus.yml.j2 dest={{ prometheus_config }}/prometheus.yml + with_items: "{{ prometheus_jobs }}" + +- name: create prometheus data directory + file: path={{ prometheus_data }} state=directory owner=prometheus group=prometheus mode=0755 + +- name: create prometheus upstart job + template: src=prometheus.conf.j2 dest=/etc/init/prometheus.conf + +- name: start prometheus service + service: name=prometheus state=started enabled=yes + +- name: remove temporary prometheus directory + file: path={{ prometheus_tmp }} state=absent + +- name: remove temporary prometheus tarball + file: path={{ prometheus_tgz }} state=absent diff --git a/playbooks/prometheus/templates/prometheus.conf.j2 b/roles/prometheus/templates/prometheus.conf.j2 similarity index 78% rename from playbooks/prometheus/templates/prometheus.conf.j2 rename to roles/prometheus/templates/prometheus.conf.j2 index 4fec8b6..58c2b5d 100644 --- a/playbooks/prometheus/templates/prometheus.conf.j2 +++ b/roles/prometheus/templates/prometheus.conf.j2 @@ -1,3 +1,4 @@ +# {{ ansible_managed }} # prometheus - service job file description "Prometheus metrics and monitoring system" @@ -17,4 +18,4 @@ setuid prometheus setgid prometheus # What to execute -exec /usr/local/bin/prometheus -config.file {{ prometheus_config }} -storage.local.path {{ prometheus_data }} -storage.local.chunk-encoding-version 2 +exec /usr/local/bin/prometheus -config.file {{ prometheus_config }}/prometheus.yml -storage.local.path {{ prometheus_data }} -storage.local.chunk-encoding-version 2 diff --git a/playbooks/prometheus/templates/prometheus.yml.j2 b/roles/prometheus/templates/prometheus.yml.j2 similarity index 100% rename from playbooks/prometheus/templates/prometheus.yml.j2 rename to roles/prometheus/templates/prometheus.yml.j2 diff --git a/roles/prometheus/vars/main.yml b/roles/prometheus/vars/main.yml new file mode 100644 index 0000000..e389546 --- /dev/null +++ b/roles/prometheus/vars/main.yml @@ -0,0 +1,36 @@ +--- +# Prometheus version and checksum configuration +prometheus_version: "0.18.0rc1" +prometheus_sha1: "915b0396b9ed973842c3c3e5394caec24269fa37" +# Prometheus configuration and data storage locations +prometheus_config: "/etc/prometheus/" +prometheus_data: "/var/lib/prometheus/" +# Prometheus jobs configuration +prometheus_jobs: + - job: "edgemax" + targets: + - "192.168.1.3:9132" + - job: "node" + targets: + - "192.168.1.3:9100" + - "192.168.1.5:9100" + - "192.168.1.20:9100" + - job: "prometheus" + scrape_interval: "5s" + targets: + - "192.168.1.3:9090" + - job: "rtorrent" + scrape_interval: "5s" + targets: + - "192.168.1.3:9135" + - job: "unifi" + targets: + - "unifi.servnerr.com:9130" + - job: "zfs" + targets: + - "192.168.1.3:9134" +# Static configuration. +prometheus_dir: "prometheus-{{ prometheus_version }}.linux-amd64" +prometheus_tmp: "/tmp/{{ prometheus_dir }}" +prometheus_url: "https://github.com/prometheus/prometheus/releases/download/{{ prometheus_version }}/{{ prometheus_dir }}.tar.gz" +prometheus_tgz: "/tmp/prometheus.tar.gz" diff --git a/roles/rtorrent/tasks/main.yml b/roles/rtorrent/tasks/main.yml new file mode 100644 index 0000000..ce3c373 --- /dev/null +++ b/roles/rtorrent/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: install rtorrent + apt: pkg=rtorrent state=installed + register: rtorrentinstalled + +- name: fail the play if rtorrent could not be installed + when: rtorrentinstalled|failed + fail: msg="failed to install rtorrent" + +- name: create rtorrent user + user: name=rtorrent shell=/bin/false comment="rtorrent service user" + +- name: create rtorrent configuration + template: src=rtorrent.rc.j2 dest=/home/rtorrent/.rtorrent.rc owner=rtorrent group=rtorrent mode=0755 + +- name: create files directory + file: path={{ rtorrent_path_files }} state=directory owner=rtorrent group=rtorrent mode=0755 + +- name: create watch directory + file: path={{ rtorrent_path_watch }} state=directory owner=rtorrent group=rtorrent mode=0755 + +- name: create session directory + file: path={{ rtorrent_path_session }} state=directory owner=rtorrent group=rtorrent mode=0755 diff --git a/playbooks/rtorrent/rtorrent.rc.j2 b/roles/rtorrent/templates/rtorrent.rc.j2 similarity index 100% rename from playbooks/rtorrent/rtorrent.rc.j2 rename to roles/rtorrent/templates/rtorrent.rc.j2 diff --git a/roles/rtorrent/vars/main.yml b/roles/rtorrent/vars/main.yml new file mode 100644 index 0000000..8bb9324 --- /dev/null +++ b/roles/rtorrent/vars/main.yml @@ -0,0 +1,11 @@ +--- +# Client configurations +rtorrent_port: 58575 +rtorrent_download_rate: 10000 +rtorrent_upload_rate: 400 +rtorrent_low_diskspace: "1G" +# Path configurations +rtorrent_path_root: "/mnt/rtorrent" +rtorrent_path_files: "{{ rtorrent_path_root }}/files" +rtorrent_path_session: "{{ rtorrent_path_root }}/.session" +rtorrent_path_watch: "{{ rtorrent_path_root }}/watch" diff --git a/servnerr.yml b/servnerr.yml new file mode 100644 index 0000000..161b9cd --- /dev/null +++ b/servnerr.yml @@ -0,0 +1,7 @@ +--- +- hosts: servnerr + roles: + - golang + - plex + - prometheus + - rtorrent diff --git a/test b/test new file mode 100644 index 0000000..26b476b --- /dev/null +++ b/test @@ -0,0 +1,2 @@ +[servnerr] +test-ansible