Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy DIM on a Virtual Machine Using Ansible Playbook #272

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
73cf61f
add inventory file
sudoix Apr 13, 2024
74983a6
add role
sudoix Apr 13, 2024
a9b69e8
add dim playbook
sudoix Apr 13, 2024
fd8e8a9
add install some package
sudoix Apr 13, 2024
0b3a54b
add network-scripts variable
sudoix Apr 13, 2024
364279f
add network configuration task
sudoix Apr 13, 2024
75376e4
add lo config file
sudoix Apr 13, 2024
97e8056
modify variables
sudoix Apr 13, 2024
7cdeb0f
modify install packages
sudoix Apr 13, 2024
b3a9adf
modify mariadb install and configure
sudoix Apr 13, 2024
f7f9e9b
add some static file
sudoix Apr 13, 2024
cf272b4
update main and basic playbook
sudoix Apr 13, 2024
e0eb0df
update variable
sudoix Apr 13, 2024
a6acb3a
update handlers
sudoix Apr 13, 2024
092793a
add pdns variable
sudoix Apr 13, 2024
77813e6
add pdns static file
sudoix Apr 13, 2024
660d147
add pdns playbook
sudoix Apr 13, 2024
6ce5115
add pdns template config
sudoix Apr 13, 2024
08211c5
update some tasks
sudoix Apr 14, 2024
4f954dc
add variables
sudoix Apr 14, 2024
8cf50a0
add dim playbook
sudoix Apr 14, 2024
c848c72
add incloud dim playbook
sudoix Apr 14, 2024
0ba939a
add dim file
sudoix Apr 14, 2024
8a5cc31
add some template
sudoix Apr 14, 2024
39cbe5f
update inventory file
sudoix Apr 15, 2024
7a97c6e
add forward zone template
sudoix Apr 15, 2024
5d3b077
add nta lua template
sudoix Apr 15, 2024
df16ff7
add recursor-int conf
sudoix Apr 15, 2024
1916801
add readme
sudoix Apr 15, 2024
89dfd06
update readme
sudoix Apr 15, 2024
e80d986
add update cache
sudoix Apr 15, 2024
6e9425a
update readme
sudoix Apr 15, 2024
5e50838
update readme
sudoix Apr 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions ansible-deployment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Role Name
=========

An ansible playbook for deploy dim

Requirements
------------

`python3` on the remote servers (dnf install python36 -y)

This ansible only works on `Rocky Linux 8.5`, for more linux distro please test it.

`Sudoer user`: The ansible user should be a member of the wheel group. and can use sudo without password.

**Befor you run the ansible dim, you need to install the following packages:**

```bash
ansible-galaxy collection install ansible.posix
ansible-galaxy collection install community.mysql
```

Role Variables
--------------

Check the `inventory` directory for a list of variables that can be passed into the role.


How to use
-----------

```bash
ansible-playbook -i inventory/dim-servers.ini dim.yml --become --become-method=sudo
```

License
-------

BSD

Author Information
------------------

Milad Norouzi ([email protected])
5 changes: 5 additions & 0 deletions ansible-deployment/dim.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- hosts: all
roles:
- role: dim
gather_facts: yes
any_errors_fatal: true
7 changes: 7 additions & 0 deletions ansible-deployment/inventory/dim-servers.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[all]
dim ansible_host=5.34.207.235

[all:vars]
ansible_user=rocky
ansible_port=22
ansible_python_interpreter = "/usr/bin/python3"
67 changes: 67 additions & 0 deletions ansible-deployment/inventory/group_vars/all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# General
install_ansible_modules: "true"
disable_transparent_huge_pages: "true"
setup_interface: "false"

# Domain
domain_name: "example.com"

#DIM-Network
network_path: "/etc/sysconfig/network-scripts"
network_scripts_url: "https://dl.rockylinux.org/pub/rocky/9/devel/x86_64/os/Packages/n/network-scripts-10.11.5-1.el9.x86_64.rpm" # For rocky linux 9
network_scripts_dest: "/tmp"
network_scripts_package: "network-scripts-10.11.5-1.el9.x86_64.rpm"

# DIM DB
dim_db_name: "dim"
pdns_int_db_name: "pdns_int"
pdns_pub_db_name: "pdns_pub"


# DIM DB info
dim_db_user_name: "dim_user"
dim_db_user_password: "dim_pass"
dim_db_priv: "dim.*:ALL"
dim_secret_key: "SuperSecretTtestkey"

# pdns_int DB info
dim_pdns_int_db_user_name: "dim_pdns_int_user"
dim_pdns_int_db_user_password: "SuperSecret1"
dim_pdns_int_db_priv: "pdns_int.*:INSERT,UPDATE,DELETE,SELECT"
pdns_int_db_user_name: "pdns_int_user"
pdns_int_db_user_password: "SuperSecret4"
pdns_int_db_priv: "pdns_int.*:SELECT"

# pdns_pub DB info
dim_pdns_pub_db_user_name: "dim_pdns_pub_user"
dim_pdns_pub_db_user_password: "SuperSecret2"
dim_pdns_pub_db_priv: "pdns_pub.*:INSERT,UPDATE,DELETE,SELECT"
pdns_pub_db_user_name: "pdns_pub_user"
pdns_pub_db_user_password: "SuperSecret3"
pdns_pub_db_priv: "pdns_pub.*:SELECT"

# SQL
sql_url: "https://raw.githubusercontent.com/1and1/dim/master/dim/pdns.sql"
sql_file_path: "/tmp/pdns.sql"

# PowerDNS
pdns_conf_dir: "/etc/pdns"
pdns_recursor_conf_path: "/etc/pdns-recursor"

# DIM
dim_config_path: "/etc/dim"
din_example_path: "/srv/http/dim.example.com"

dim_url: "https://github.com/1and1/dim/releases/download/dim-4.0.9/dim-4.0.9-1.el8.x86_64.rpm"
dimclient_url: "https://github.com/1and1/dim/releases/download/dimclient-0.4.5/python3-dimclient-0.4.5-1.el8.x86_64.rpm"
ndcli_url: "https://github.com/1and1/dim/releases/download/ndcli-4.0.3/python3-ndcli-4.0.3-1.el8.x86_64.rpm"
dim_web_url: "https://github.com/1and1/dim/releases/download/dim-web-0.1/python3-dim-web-0.1-1.el8.x86_64.rpm"

dim_repo: "https://github.com/1and1/dim"
dim_repo_dest: "/usr/local/src/dim"

# Httpd
httpd_conf_path: "/etc/httpd/conf.d"

# wsgi
wsgi_path: "/opt/dim"
29 changes: 29 additions & 0 deletions ansible-deployment/roles/dim/.travis.yml
Original file line number Diff line number Diff line change
@@ -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/
2 changes: 2 additions & 0 deletions ansible-deployment/roles/dim/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# defaults file for dim
2 changes: 2 additions & 0 deletions ansible-deployment/roles/dim/files/dim.wsgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from dim import create_app
application = create_app()
8 changes: 8 additions & 0 deletions ansible-deployment/roles/dim/files/ifcfg-lo-bind-int
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DEVICE=lo
IPADDR=127.4.0.1
NETMASK=255.0.0.0
NETWORK=127.0.0.0
BROADCAST=127.255.255.255
ONBOOT=yes
NAME=loopback4
NM_CONTROLLED=no
8 changes: 8 additions & 0 deletions ansible-deployment/roles/dim/files/ifcfg-lo-pdns-int
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DEVICE=lo
IPADDR=127.1.0.1
NETMASK=255.0.0.0
NETWORK=127.0.0.0
BROADCAST=127.255.255.255
ONBOOT=yes
NAME=loopback1
NM_CONTROLLED=no
8 changes: 8 additions & 0 deletions ansible-deployment/roles/dim/files/ifcfg-lo-pdns-pub
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DEVICE=lo
IPADDR=127.2.0.1
NETMASK=255.0.0.0
NETWORK=127.0.0.0
BROADCAST=127.255.255.255
ONBOOT=yes
NAME=loopback2
NM_CONTROLLED=no
8 changes: 8 additions & 0 deletions ansible-deployment/roles/dim/files/ifcfg-lo-pdns-rec-int
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DEVICE=lo
IPADDR=127.3.0.1
NETMASK=255.0.0.0
NETWORK=127.0.0.0
BROADCAST=127.255.255.255
ONBOOT=yes
NAME=loopback3
NM_CONTROLLED=no
5 changes: 5 additions & 0 deletions ansible-deployment/roles/dim/files/my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[client]
user=root
password=


11 changes: 11 additions & 0 deletions ansible-deployment/roles/dim/files/query.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# This script set empty password for user root to allow to connect to the database anonymously
# Tested on Rocky linux 9

sudo mysql -uroot -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('');"
sudo mysql -uroot -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '';"
sudo mysql -uroot -e "FLUSH PRIVILEGES;"
sudo mysql -uroot -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '';"
sudo mysql -uroot -e "FLUSH PRIVILEGES;"
sudo mysql -uroot -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('');"
10 changes: 10 additions & 0 deletions ansible-deployment/roles/dim/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# handlers file for dim
- name: Restart mariadb
systemd:
name: mariadb
state: restarted

- name: Reload systemctl daemon
systemd:
daemon_reload: yes
53 changes: 53 additions & 0 deletions ansible-deployment/roles/dim/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)

min_ansible_version: 2.9

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

58 changes: 58 additions & 0 deletions ansible-deployment/roles/dim/tasks/basic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
- name: Disable SELinux policy permanently
ansible.posix.selinux:
policy: targeted
state: disabled

- name: Disable SELinux policy
shell:
cmd: setenforce 0
ignore_errors: true

- name: Gather firewalld is installed
package_facts:
manager: auto

- name: Stop and disable firewalld
systemd:
name: firewalld
state: stopped
enabled: false
when: "'firewalld' in ansible_facts.packages"

- name: Enable epel-release
dnf:
name: epel-release
state: present

- name: Install necessary packages
dnf:
name:
- wget
- htop
- bind-utils
- vim
- nload
- bc
- chkconfig
- initscripts
- python3-pip
- network-scripts
state: present
update_cache: true

- name: Install python packages with pip
pip:
name: PyMySQL


#### Uncomment it for Rocky linux 9
# - name: Download network-scripts package
# get_url:
# url: "{{ network_scripts_url }}"
# dest: "{{ network_scripts_dest }}"

# - name: Install network-scripts package
# dnf:
# name: "{{ network_scripts_dest }}/{{ network_scripts_package }}"
# state: present

Loading