Skip to content

Commit

Permalink
Update tasks to a more modern syntax.
Browse files Browse the repository at this point in the history
Plain YAML is favoured over the KV style.
Fix long lines and clean up various things.

This also closes nsg#19
  • Loading branch information
nsg committed Aug 4, 2017
1 parent a29ad6f commit 8a7f101
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 44 deletions.
53 changes: 39 additions & 14 deletions tasks/Debian.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
---

- name: Install packages with apt
apt: name={{ item }} state=present update_cache=true
apt:
name: "{{ item }}"
update_cache: yes
with_items:
- python-pip
- python-dev
Expand All @@ -14,33 +16,56 @@
- libffi-dev

- name: Install init.d script for carbon-cache
template: src=debian_carbon_service.j2 dest=/etc/init.d/carbon-cache
template:
src: debian_carbon_service.j2
dest: /etc/init.d/carbon-cache
notify: restart carbon-cache
when: ansible_distribution_release == "wheezy" or ansible_distribution_release == "trusty"
when: >
ansible_distribution_release == "wheezy"
or ansible_distribution_release == "trusty"
- name: Install systemd unit carbon-cache.service
template: src=debian_carbon_service_systemd.j2 dest=/etc/systemd/system/carbon-cache.service
when: ansible_distribution_release == "jessie" or ansible_distribution_release == "xenial"
- name: Install systemd unit carbon-cache.service
template:
src: debian_carbon_service_systemd.j2
dest: /etc/systemd/system/carbon-cache.service
when: >
not (ansible_distribution_release == "wheezy"
or ansible_distribution_release == "trusty")
register: ccunit

- name: Check the install scripts perms
file: path=/etc/init.d/{{ item }} mode=0755 owner=root group=root
file:
path: "/etc/init.d/{{ item }}"
mode: 0755
owner: root
group: root
with_items:
- carbon-cache
when: ansible_distribution_release == "wheezy" or ansible_distribution_release == "trusty"
when: >
ansible_distribution_release == "wheezy"
or ansible_distribution_release == "trusty"
- name: Reload systemd if unit file has changed
shell: 'systemctl daemon-reload'
when: ccunit.changed and ansible_distribution_release == "jessie" or ansible_distribution_release == "xenial"
shell: systemctl daemon-reload
when: ccunit|changed
notify: restart carbon-cache

- name: Install uwsgi graphite config
template: src=uwsgi_graphite.ini.j2 dest=/etc/uwsgi/apps-available/graphite.ini
template:
src: uwsgi_graphite.ini.j2
dest: /etc/uwsgi/apps-available/graphite.ini
notify: restart uwsgi

- name: Enable uwsgi graphite config
file: src=/etc/uwsgi/apps-available/graphite.ini dest=/etc/uwsgi/apps-enabled/graphite.ini state=link
file:
src: /etc/uwsgi/apps-available/graphite.ini
dest: /etc/uwsgi/apps-enabled/graphite.ini
state: link
notify: restart uwsgi

- name: Make sure we have /run/uwsgi/graphite
file: path=/run/uwsgi/graphite state=directory owner={{ graphite_user }} group={{ graphite_user }}
file:
path: /run/uwsgi/graphite
state: directory
owner: "{{ graphite_user }}"
group: "{{ graphite_user }}"
43 changes: 30 additions & 13 deletions tasks/RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
---

- name: Install EPEL repository from fedoraproject.org
yum: name=http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
when: ansible_distribution_version.split(".")[0]|int < 7
yum:
name: http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
when: ansible_distribution_major_version < 7

- name: Install EPEL repository from repo
yum: name=epel-release
when: ansible_distribution_version.split(".")[0]|int >= 7
yum:
name: epel-release
when: ansible_distribution_major_version >= 7

- name: Install packages with yum
yum: name={{ item }} state=present
yum:
name: "{{ item }}"
with_items:
- python-pip
- python-devel
Expand All @@ -23,30 +26,44 @@
- libffi-devel

- name: "Install Twisted 15.3.0 on 6.x (never versions req python 2.7)"
pip: name=Twisted==15.3.0
when: ansible_distribution_version.split(".")[0]|int < 7
pip:
name: "Twisted==15.3.0"
when: ansible_distribution_major_version < 7

- name: Install uwsgi with pip
pip: name=uwsgi state=present
pip:
name: uwsgi

- name: Install carbon-cache init.d script
template: src=redhat_carbon_service.j2 dest=/etc/init.d/carbon-cache
template:
src: redhat_carbon_service.j2
dest: /etc/init.d/carbon-cache
notify: restart carbon-cache

- name: Install uwsgi default settings
template: src=redhat_uwsgi_default.ini.j2 dest=/etc/uwsgi_default.ini
template:
src: redhat_uwsgi_default.ini.j2
dest: /etc/uwsgi_default.ini
notify: restart uwsgi

- name: Install uwsgi graphite config
template: src=uwsgi_graphite.ini.j2 dest=/etc/uwsgi_graphite.ini
template:
src: uwsgi_graphite.ini.j2
dest: /etc/uwsgi_graphite.ini
notify: restart uwsgi

- name: Install uwsgi init.d script
template: src=redhat_uwsgi_service.j2 dest=/etc/init.d/uwsgi
template:
src: redhat_uwsgi_service.j2
dest: /etc/init.d/uwsgi
notify: restart uwsgi

- name: Check the install scripts perms
file: path=/etc/init.d/{{ item }} mode=0755 owner=root group=root
file:
path: /etc/init.d/{{ item }}
mode: 0755
owner: root
group: root
with_items:
- carbon-cache
- uwsgi
69 changes: 52 additions & 17 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,66 @@
# Install graphite

- name: Create user
user: name={{ graphite_user }} comment="Graphite user" state=present
user:
name: "{{ graphite_user }}"
comment: "Graphite user"

- include: RedHat.yml
- name: "Run tasks on a RedHat based system"
include: RedHat.yml
when: ansible_os_family == "RedHat"

- include: Debian.yml
- name: "Run tasks on a Debian based system"
include: Debian.yml
when: ansible_os_family == "Debian"

- name: Setup graphite with pip
pip: name={{ item }} state=present extra_args="--no-binary=:all:"
pip:
name: "{{ item }}"
extra_args: "--no-binary=:all:"
with_items: "{{ graphite_install_requirements[graphite_install_version] }}"
environment:
PYTHONPATH: "{{ graphite_install_path }}/lib:{{ graphite_install_path }}/webapp"
notify: restart carbon-cache
when: ansible_distribution_release == "xenial"

- name: Setup graphite with pip
pip: name={{ item }} state=present
pip:
name: "{{ item }}"
with_items: "{{ graphite_install_requirements[graphite_install_version] }}"
environment:
PYTHONPATH: "{{ graphite_install_path }}/lib:{{ graphite_install_path }}/webapp"
notify: restart carbon-cache
when: ansible_distribution_release != "xenial"

- name: Set perms for graphite storage
file: path={{ graphite_install_path }}/storage owner={{ graphite_user }} recurse=yes state=directory
file:
path: "{{ graphite_install_path }}/storage"
owner: "{{ graphite_user }}"
recurse: yes
state: directory

- name: Install webapp settings
template: src=local_settings.py.j2 dest={{ graphite_install_path }}/webapp/graphite/local_settings.py
template:
src: local_settings.py.j2
dest: "{{ graphite_install_path }}/webapp/graphite/local_settings.py"
notify: restart carbon-cache

- name: Install carbon settings
template: src=carbon.conf.j2 dest={{ graphite_install_path }}/conf/carbon.conf
template:
src: carbon.conf.j2
dest: "{{ graphite_install_path }}/conf/carbon.conf"
notify: restart carbon-cache

- name: Install storage schemas
template: src=storage-schemas.conf.j2 dest={{ graphite_install_path }}/conf/storage-schemas.conf
template:
src: storage-schemas.conf.j2
dest: "{{ graphite_install_path }}/conf/storage-schemas.conf"
notify: restart carbon-cache

- name: Install uwsgi configuration
template: src=wsgi.py.j2 dest={{ graphite_install_path }}/conf/wsgi.py
template:
src: wsgi.py.j2
dest: "{{ graphite_install_path }}/conf/wsgi.py"
notify: restart carbon-cache

- name: Inspect graphite db
Expand All @@ -63,31 +82,47 @@
when: result.stdout.find("AccountMygraph") == -1

- name: Create superuser account
command: python {{ graphite_install_path }}/webapp/graphite/manage.py createsuperuser --username={{ graphite_admin_username }} --email={{ graphite_admin_email }} --noinput
command: >
python {{ graphite_install_path }}/webapp/graphite/manage.py createsuperuser
--username={{ graphite_admin_username }}
--email={{ graphite_admin_email }}
--noinput
sudo_user: "{{ graphite_user }}"
register: superuser_created
args:
creates: "{{ graphite_install_path }}/webapp/graphite/.superuser_created"

- name: Prepare to set up superuser password
template: src=createsuperuser.py.j2 dest=/tmp/createsuperuser.py
template:
src: createsuperuser.py.j2
dest: /tmp/createsuperuser.py
when: superuser_created|changed
register: debug2

- name: Set superuser password
shell: "python {{ graphite_install_path }}/webapp/graphite/manage.py shell < /tmp/createsuperuser.py"
shell: >
python {{ graphite_install_path }}/webapp/graphite/manage.py
shell < /tmp/createsuperuser.py
sudo_user: "{{ graphite_user }}"
when: superuser_created|changed

- name: Create lock file
file: path="{{ graphite_install_path }}/webapp/graphite/.superuser_created" state=touch
file:
path: "{{ graphite_install_path }}/webapp/graphite/.superuser_created"
state: touch
when: superuser_created|changed

- name: Remove temp file
file: path=/tmp/createsuperuser.py state=absent
file:
path: /tmp/createsuperuser.py
state: absent

- name: Enable uwsgi service
service: name=uwsgi enabled=yes
service:
name: uwsgi
enabled: yes

- name: Enable carbon-cache service
service: name=carbon-cache enabled=yes
service:
name: carbon-cache
enabled: yes

0 comments on commit 8a7f101

Please sign in to comment.