From b37afe21d4315cdc4b6e8c4eb25445f7f671f3e2 Mon Sep 17 00:00:00 2001 From: Gerben Geijteman Date: Wed, 27 Jul 2016 00:53:08 +0200 Subject: [PATCH] Initial commit, not fully tested, work in progress --- .travis.yml | 29 +++++++ LICENSE | 2 +- README.md | 58 +++++++++++++ defaults/main.yml | 152 +++++++++++++++++++++++++++++++++ meta/main.yml | 23 +++++ tasks/main.yml | 3 + tasks/prerequisites-Debian.yml | 30 +++++++ tasks/prerequisites-RedHat.yml | 26 ++++++ tasks/prerequisites.yml | 18 ++++ tasks/setup.yml | 59 +++++++++++++ templates/options.conf.j2 | 1 + tests/inventory | 1 + tests/test.yml | 5 ++ 13 files changed, 406 insertions(+), 1 deletion(-) create mode 100644 .travis.yml create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/main.yml create mode 100644 tasks/prerequisites-Debian.yml create mode 100644 tasks/prerequisites-RedHat.yml create mode 100644 tasks/prerequisites.yml create mode 100644 tasks/setup.yml create mode 100644 templates/options.conf.j2 create mode 100644 tests/inventory create mode 100644 tests/test.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file diff --git a/LICENSE b/LICENSE index 853b46d..c62e51b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 +Copyright (c) 2016 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md new file mode 100644 index 0000000..1f232e8 --- /dev/null +++ b/README.md @@ -0,0 +1,58 @@ +Role Name +========= + +Deploy [DirectAdmin](https://directadmin.com/) with Ansible + +Requirements +------------ + +- A DirectAdmin license is required. +- A clean machine is required. DirectAdmin will actively overwrite existing packages. +- A publicly reachable IP is required. +- Root access to the target machine is required. For details, read: [Step 3](https://www.directadmin.com/installguide.php) + +Ansible 2.1 is highly recommended. + +Role Variables +-------------- + +Its recommended that you use either the `group_vars` / `host_vars` to set the required variables per server: + + directadmin_client_id: + directadmin_license_id: + directadmin_hostname: # Optional, will be obtained from server + directadmin_ip_address: # Optional, will be obtained from server + +If you wish to use a custom custombuild configuration, please configure: + + directadmin_custombuild_options_conf: http://yourdomain.com/options.conf + +Dependencies +------------ + +As of present there are no dependent roles. (They may be added later) + +Recommended to have installed on your server are: + + - Firewall + - SSH protection (Fail2Ban) + - Kernel hardening + +FreeBSD support may be added later. + +Example Playbook +---------------- + + - hosts: servers + roles: + - { role: hyperized.directadmin } + +License +------- + +MIT + +Author Information +------------------ + +Gerben Geijteman \ No newline at end of file diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..26ca769 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,152 @@ +--- +# Directadmin automated setup - http://help.directadmin.com/item.php?id=578 +directadmin_install: True +directadmin_setup_url: http://www.directadmin.com/setup.sh +directadmin_setup_path: /root +# directadmin_client_id: +# directadmin_license_id: +# directadmin_hostname: # Optional, will be obtained from server +# directadmin_ip_address: # Optional, will be obtained from server +directadmin_ethernet_device: eth0 +directadmin_custombuild_options_conf: # like http://yourdomain.com/options.conf +directadmin_custombuild_version: 2.0 +directadmin_custombuild_path: /usr/local/directadmin/custombuild +directadmin_cache_timeout: 3600 + +# Packages - http://help.directadmin.com/item.php?id=354 +directadmin_debian6_packages: + - gcc + - g++ + - make + - flex + - bison + - openssl + - libssl-dev + - perl + - perl-base + - perl-modules + - libperl-dev + - libaio1 + - libaio-dev + - zlib1g + - zlib1g-dev + - libcap-dev + - bzip2 + - automake + - autoconf + - libtool + - cmake + - pkg-config + - python + - libreadline-dev + - libdb4.8-dev + - libsasl2-dev + - patch + +directadmin_debian7_packages: + - gcc + - g++ + - make + - flex + - bison + - openssl + - libssl-dev + - perl + - perl-base + - perl-modules + - libperl-dev + - libaio1 + - libaio-dev + - zlib1g + - zlib1g-dev + - libcap-dev + - bzip2 + - automake + - autoconf + - libtool + - cmake + - pkg-config + - python + - libdb-dev + - libsasl2-dev + - libncurses5-dev + - patch + +directadmin_debian8_packages: + - gcc + - g++ + - make + - flex + - bison + - openssl + - libssl-dev + - perl + - perl-base + - perl-modules + - libperl-dev + - libaio1 + - libaio-dev + - zlib1g + - zlib1g-dev + - libcap-dev + - bzip2 + - automake + - autoconf + - libtool + - cmake + - pkg-config + - python + - libdb-dev + - libsasl2-dev + - libncurses5-dev + - libsystemd-dev + - bind9 + - quota + - libsystemd-daemon0 + - patch + - libjemalloc-dev + +directadmin_rhel_generic_packages: + - gcc + - gcc-c++ + - flex + - bison + - make + - bind + - bind-libs + - bind-utils + - openssl + - openssl-devel + - perl + - quota + - libaio + - libcom_err-devel + - libcurl-devel + - gd + - zlib-devel + - zip + - unzip + - libcap-devel + - cronie + - bzip2 + - cyrus-sasl-devel + - perl-ExtUtils-Embed + - autoconf + - automake + - libtool + - which + - patch + - mailx + - bzip2-devel + - lsof + +directadmin_rhel_packages: + - db4-devel + +directadmin_centos7_packages: + - psmisc + - net-tools + - systemd-devel + - libdb-devel + - perl-DBI + - xfsprogs diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..ad5afea --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,23 @@ +galaxy_info: + author: Gerben Geijteman + description: Deploy DirectAdmin with Ansible + company: Hyperized Hosting + license: MIT + min_ansible_version: 2.1 + platforms: + - name: EL + versions: + - all + - name: Fedora + versions: + - all + - name: Debian + versions: + - jessie + - squeeze + - wheezy + galaxy_tags: + - system + - web + - directadmin +dependencies: [] \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..0eb94bc --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,3 @@ +--- +- include: prerequisites.yml +- include: setup.yml diff --git a/tasks/prerequisites-Debian.yml b/tasks/prerequisites-Debian.yml new file mode 100644 index 0000000..7061e72 --- /dev/null +++ b/tasks/prerequisites-Debian.yml @@ -0,0 +1,30 @@ +--- +- name: Install dependencies for Debian 6 Squeeze + apt: + name: "{{ item }}" + update_cache: yes + cache_valid_time: "{{ directadmin_cache_timeout }}" + state: present + with_items: + - "{{ directadmin_debian6_packages }}" + when: "ansible_distribution == 'Debian' and ansible_distribution_release == 'squeeze'" + +- name: Install dependencies for Debian 7 Wheezy + apt: + name: "{{ item }}" + update_cache: yes + cache_valid_time: "{{ directadmin_cache_timeout }}" + state: present + with_items: + - "{{ directadmin_debian7_packages }}" + when: "ansible_distribution == 'Debian' and ansible_distribution_release == 'wheezy'" + +- name: Install dependencies for Debian 8 Jessie + apt: + name: "{{ item }}" + update_cache: yes + cache_valid_time: "{{ directadmin_cache_timeout }}" + state: present + with_items: + - "{{ directadmin_debian8_packages }}" + when: "ansible_distribution == 'Debian' and ansible_distribution_release == 'jessie'" diff --git a/tasks/prerequisites-RedHat.yml b/tasks/prerequisites-RedHat.yml new file mode 100644 index 0000000..793e176 --- /dev/null +++ b/tasks/prerequisites-RedHat.yml @@ -0,0 +1,26 @@ +--- +- name: install dependencies for RHEL, Fedora & CentOS + yum: + name: "{{ item }}" + update_cache: yes + state: present + with_items: + - "{{ directadmin_rhel_packages_generic }}" + +- name: install everywhere but on CentOS7 + yum: + name: "{{ item }}" + update_cache: yes + state: present + with_items: + - "{{ directadmin_rhel_packages }}" + when: ansible_distribution not 'CentOS' and ansible_distribution_version|version_compare('ne', 7) + +- name: install CentOS 7 specific requirements + yum: + name: "{{ item }}" + update_cache: yes + state: present + with_items: + - "{{ directadmin_centos7_packages }}" + when: ansible_distribution == 'CentOS' and ansible_distribution_version|version_compare('=', 7) diff --git a/tasks/prerequisites.yml b/tasks/prerequisites.yml new file mode 100644 index 0000000..46182ce --- /dev/null +++ b/tasks/prerequisites.yml @@ -0,0 +1,18 @@ +--- +# Ensure all variables are present to start with: +- name: verify all required variables are set + fail: + msg: "Variable: '{{ item }}' is not defined!" + when: "{{ item }} is undefined or {{ item }} is none" + with_items: + - directadmin_client_id + - directadmin_license_id + - directadmin_hostname + +# Ensure prerequisites are installed for supported OS +- include: prerequisites-Debian.yml + when: ansible_os_family == 'Debian' + +- include: prerequisites-RedHat.yml + when: ansible_os_family == 'RedHat' + diff --git a/tasks/setup.yml b/tasks/setup.yml new file mode 100644 index 0000000..9c95692 --- /dev/null +++ b/tasks/setup.yml @@ -0,0 +1,59 @@ +--- +- name: obtain setup.sh script + get_url: + url: "{{ directadmin_setup_url }}" + dest: "{{ directadmin_setup_path }}/" + +- name: ensure proper permissions on setup.sh + file: + path: "{{ directadmin_setup_path }}/setup.sh" + mode: 0755 + +- name: ensure custombuild version is set + template: + src: .custombuild.j2 + dest: "{{ directadmin_setup_path }}/.custombuild" + +- name: check if DA is already running on host + uri: + url: http://localhost:2222 + return_content: no + register: da_present + +- name: toggle whether to install DA or not + set_fact: + directadmin_install: False + when: da_present.status == 200 + +- block: + - name: ensure directadmin path if remote options file is used + file: + path: "{{ directadmin_custombuild_path }}" + recurse: yes + state: directory + + - name: try remote custombuild options file + get_url: + url: "{{ directadmin_custombuild_options_conf }}" + dest: "{{ directadmin_custombuild_path }}/options.conf" + + when: directadmin_custombuild_options_conf is defined and directadmin_custombuild_options_conf is not none + +# https://youtu.be/b00j4WblrzA?t=238 + +- debug: + msg: "This is a good time for a coffee break - https://xkcd.com/303/" + when: directadmin_install + +- name: run setup + command: "{{ directadmin_setup_path }}/setup.sh {{ directadmin_client_id }} {{ directadmin_license_id }} {{ directadmin_hostname }} {{ directadmin_ethernet_device }} {{ directadmin_ip_address | default( hostvars[inventory_hostname]['ansible_' + directadmin_ethernet_device]['ipv4']['address'] ) }}" + register: setup_output + when: directadmin_install + +- debug: + var: setup_output.stdout_lines + when: directadmin_install + +- debug: + msg: "Directadmin is already installed and running, skipping.." + when: not directadmin_install diff --git a/templates/options.conf.j2 b/templates/options.conf.j2 new file mode 100644 index 0000000..27b6154 --- /dev/null +++ b/templates/options.conf.j2 @@ -0,0 +1 @@ +{{ directadmin_custombuild_version }} \ No newline at end of file diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..d18580b --- /dev/null +++ b/tests/inventory @@ -0,0 +1 @@ +localhost \ No newline at end of file diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..6f3c2eb --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - ansible-directadmin \ No newline at end of file