〇インストール方法
以下のコマンドを実行します。
sudo apt-get -y install ansible
※動作確認
ansible-playbook --version
sudo apt-get -y install ansible
ansible-playbook --version
---
- name: Install packages
apt: name={{ item }} state=latest update_cache=yes
vars:
item:
- libxml2-utils
- xsltproc
- xmlstarlet
become: true
---
- name: check whether postgres is installed
stat:
path: "/usr/bin/psql"
register: chk_pg11
- name: configure sources.list
blockinfile:
dest: /etc/apt/sources.list.d/pgdg.list
create: yes
block: |
deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main
when: chk_pg11.stat.exists == false
become: true
- name: add an apt key
apt_key:
url: https://www.postgresql.org/media/keys/ACCC4CF8.asc
state: present
when: chk_pg11.stat.exists == false
become: yes
- name: Install required software
apt: name={{ item }} state=latest update_cache=yes
vars:
item:
- ca-certificates
- postgresql-11
when: chk_pg11.stat.exists == false
become: true
- name: configure postgresql.conf
blockinfile:
dest: /etc/postgresql/11/main/postgresql.conf
create: yes
block: |
listen_addresses='*'
when: chk_pg11.stat.exists == false
become: true
- name: edit pg_hba.conf
replace: dest=/etc/postgresql/11/main/pg_hba.conf regexp="host.*all.*all.*127.0.0.1" replace="#host all all 127.0.0.1"
when: chk_pg11.stat.exists == false
become: true
- name: edit pg_hba.conf
replace: dest=/etc/postgresql/11/main/pg_hba.conf regexp="^host.*all.*all.*::1/128.*ident" replace="host all all ::1/128 password"
when: chk_pg11.stat.exists == false
become: true
- name: configure postgresql.conf
blockinfile:
dest: /etc/postgresql/11/main/pg_hba.conf
create: yes
block: |
host all all 127.0.0.1/32 password
host all all {{ ansible_eth0.ipv4.address }}/24 password
when: chk_pg11.stat.exists == false
become: true
- name: enable and start postgresq.service
systemd:
daemon_reload: yes
enabled: yes
state: started
name: postgresql.service
when: chk_pg11.stat.exists == false
become: true
---
- name: uninstall old packages
apt:
name: "{{ packages }}"
state: absent
vars:
packages:
- docker
- docker-engine
- docker.io
- containerd
- runc
become: true
- name: install required packages
apt:
name: "{{ packages }}"
state: latest
update_cache: yes
vars:
packages:
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- virtualenv
- python3-setuptools
become: true
- name: add a key for docker
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
become: true
- name: add a repository
apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable
state: present
become: true
- name: install docker
apt:
name: "{{ packages }}"
state: latest
update_cache: yes
vars:
packages:
- docker-ce
- docker-ce-cli
- containerd.io
become: true
- name: enable docker
systemd:
name: docker
state: started
enabled: yes
become: true
- name: check whther docker-compose exists
stat:
path: "/usr/local/bin/docker-compose"
register: chk_docker_compose
- name: download docker-compose
get_url:
url: https://github.com/docker/compose/releases/download/1.24.1/docker-compose-Linux-x86_64
dest: /usr/local/bin/docker-compose
when: chk_docker_compose.stat.exists == false
become: true
- name: adding "+x"
file: dest=/usr/local/bin/docker-compose mode=a+x
when: chk_docker_compose.stat.exists == false
become: true
---
- name: check if unattended-upgrades is installed.
stat:
path: "/etc/apt/apt.conf.d/50unattended-upgrades"
register: chk_unattended_upgrades
- name: install unattended-upgrades
apt: name=unattended-upgrades state=present update_cache=yes
when: chk_unattended_upgrades.stat.exists == false
become: true
- name: debconf to configure unattended-upgrades
debconf: name="unattended-upgrades"
question="unattended-upgrades/enable_auto_updates"
value="true"
vtype=boolean
when: chk_unattended_upgrades.stat.exists == false
become: true
- name: reconfigure unattended upgrades with dpkg
shell: '/usr/sbin/dpkg-reconfigure --frontend noninteractive unattended-upgrades'
when: chk_unattended_upgrades.stat.exists == false
become: true
---
- hosts: borgbackup
vars:
borgbackup_repository: /opt/repo
borgbackup_encryption_key: repokey
borgbackup_passphrase: mypassphrase
borgbackup_target: /home/vagrant/playbook
roles:
- borgbackup
---
- name: install borgbackup
apt: name=borgbackup state=present update_cache=yes
become: true
- name: create repository directroy
file: path={{ borgbackup_repository }} state=directory owner={{ ansible_user }}
become: true
- name: check data directory in the repo
stat:
path: "{{ borgbackup_repository }}/data"
register: chk_data
- name: initialize repository
shell: borg init -e {{ borgbackup_encryption_key }} {{ borgbackup_repository }}
environment:
BORG_PASSPHRASE: "{{ borgbackup_passphrase }}"
when: chk_data.stat.exists == false
- name: take initial backup
shell: borg create --stats "{{ borgbackup_repository }}::init" {{ borgbackup_target }}
environment:
BORG_PASSPHRASE: "{{ borgbackup_passphrase }}"
when: chk_data.stat.exists == false
- name: show result of initial backup...
shell: borg list "{{ borgbackup_repository }}::init"
register: cmd_output
environment:
BORG_PASSPHRASE: "{{ borgbackup_passphrase }}"
changed_when: false
- name: output the result
debug:
msg: "{{ cmd_output }}"
- hosts: pipenv
roles:
- pipenv
---
- name: install required packages
apt:
name: "{{ packages }}"
vars:
packages:
- python-pip
- python3-distutils
- python3-dev
become: true
- name: install pipenv
pip:
name: pipenv
executable: pip
become: true
---
- name: check whther nodejs exists
stat:
path: "/usr/bin/nodejs"
register: chk_nodejs
- name: install required packages
apt:
name: "{{ packages }}"
state: latest
update_cache: yes
vars:
packages:
- apt-transport-https
- ca-certificates
- curl
when: chk_nodejs.stat.exists == false
become: true
- name: setup10.x
shell: curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
when: chk_nodejs.stat.exists == false
become: true
- name: install nodejs
apt:
name: "{{ packages }}"
state: latest
update_cache: yes
vars:
packages:
- nodejs
- build-essential
when: chk_nodejs.stat.exists == false
become: true
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False
[arduino-ide]
192.168.1.159
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=ubuntu
ansible_ssh_pass=ubuntu
ansible_sudo_pass=ubuntu
ansible-playbook -i inventory arduino-ide.yml
arduino-ide.yml
- hosts: arduino-ide
vars:
- arduinoversion: arduino-1.8.7
- arch: linux64
- username: ubuntu
tasks:
- name: check /opt/arduino-1.8.7 directory
stat: path=/opt/{{ arduinoversion }}
register: dirarduino
- name: download Arduino IDE
get_url:
url: https://downloads.arduino.cc/{{ arduinoversion }}-{{ arch }}.tar.xz
dest: /tmp
become: true
when: not dirarduino.stat.exists
- name: extract Arduino IDE
unarchive:
remote_src: yes
src: /tmp/{{ arduinoversion }}-{{ arch }}.tar.xz
dest: /opt
become: true
when: not dirarduino.stat.exists
- name: execute install.sh
shell: ./install.sh
args:
chdir: /opt/{{ arduinoversion }}
become: yes
- name: add specified user to dialout.
shell: "usermod -a -G dialout {{ username }}"
become: yes
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False
[sysbench]
192.168.1.61
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant
ansible-playbook -i inventory sysbench-mariadb.yml
- hosts: sysbench
vars:
- dbname: sysbench
- dbuser: sysbench
- dbpassword: sysbench
- dbhost: localhost
- dbport: 3306
tasks:
- name: set password for root
shell: echo "mariadb-server-10.1 mysql-server/root_password password root" | sudo debconf-set-selections
become: yes
- name: set password for root
shell: echo "mariadb-server-10.1 mysql-server/root_password_again password root" | sudo debconf-set-selections
become: yes
- name: install mariadb
apt:
name: mariadb-server
state: present
become: yes
- name: enable and start mariadb
systemd:
name: mysql
enabled: yes
state: started
become: yes
- name: Install required software
apt: name={{ item }} state=present
with_items:
- libmysqlclient-dev
- python-pip
become: true
- name: install MySQL-python using pip
pip:
name: "{{ item }}"
state: forcereinstall
with_items:
- pip
- MySQL-python
become: true
- name: create db
mysql_db:
name={{ dbname }}
state=present
encoding=utf8
login_user=root
become: true
- name: create and grant a database user
mysql_user:
name={{ dbuser }}
password={{ dbpassword }}
priv="{{ dbuser }}.*:ALL"
state=present
become: true
- name: install sysbench
apt: name={{ item }} state=present
with_items:
- sysbench
become: true
- name: execute cpu benchmark
shell: sysbench cpu run --threads=2 > /tmp/result
become: true
- name: execute memory benchmark
shell: sysbench memory run --threads=2 >> /tmp/result
become: true
- name: execute fileio benchmark(seqwr)
shell: sysbench fileio run --file-test-mode=seqwr --threads=2 >> /tmp/result
become: true
- name: execute fileio benchmark(rndwr)
shell: sysbench fileio run --file-test-mode=rndwr --threads=2 >> /tmp/result
become: true
- name: prepare oltp_read_write benchmark
shell: sysbench /usr/share/sysbench/oltp_read_write.lua prepare --db-driver=mysql --mysql-host=localhost --mysql-port=3306 --mysql-user=sysbench --mysql-password=sysbench --mysql-db=sysbench >> /tmp/result
become: true
- name: execute oltp_read_write benchmark
shell: sysbench /usr/share/sysbench/oltp_read_write.lua run --db-driver=mysql --mysql-host=localhost --mysql-port=3306 --mysql-user=sysbench --mysql-password=sysbench --mysql-db=sysbench --threads=2 >> /tmp/result
become: true
- name: fetch result
fetch:
src: /tmp/result
dest: ./result
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False
[unixbench]
192.168.1.61
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant
ansible-playbook -i inventory unixbench.yml
- hosts: unixbench
tasks:
- name: install git
yum: name={{ item }} state=latest
with_items:
- git
become: true
- name: yum group-install
yum: name="{{ item }}" state=present
with_items:
- "@Development Tools"
become: true
- name: git clone
git:
repo: https://github.com/kdlucas/byte-unixbench
dest: /home/vagrant/byte-unixbench/
become: true
- name: make
shell: make
args:
chdir: /home/vagrant/byte-unixbench/UnixBench
become: true
- name: Run
shell: ./Run > /tmp/result
args:
chdir: /home/vagrant/byte-unixbench/UnixBench
become: true
- name: fetch result
fetch:
src: /tmp/result
dest: ./result
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False
[docker]
192.168.1.61
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant
ansible-playbook -i inventory docker.yml
- hosts: docker
vars:
- username: vagrant
tasks:
- name: download docker
get_url:
url: https://get.docker.com
dest: /tmp/get-docker.sh
mode: a+x
become: true
- name: install docker
shell: creates=/usr/bin/docker /tmp/get-docker.sh
become: true
- name: add username to docker group
user: name={{ username }} group=docker append=yes
become: true
- name: install python-pip
apt: name={{ item }} state=present
with_items:
- python-pip
become: true
- name: install docker-compose
pip:
name: docker-compose
become: true
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False
[docker]
192.168.1.16
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=pi
ansible_ssh_pass=raspberry
ansible_sudo_pass=raspberry
ansible-playbook -i inventory docker.yml
- hosts: docker
tasks:
- name: download docker
get_url:
url: https://get.docker.com
dest: /tmp/get-docker.sh
mode: a+x
become: true
- name: install docker
shell: creates=/usr/bin/docker /tmp/get-docker.sh
become: true
- name: add pi to docker group
user: name=pi group=docker append=yes
become: true
- name: install python-pip
apt: name={{ item }} state=present
with_items:
- python-pip
become: true
- name: install docker-compose
pip:
name: docker-compose
become: true
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False
[lime-survey]
192.168.1.107
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant
ansible-playbook -i inventory limesurvey.yml
- hosts: lime-survey
vars:
- dbname: limesurvey
- dbuser: limesurvey
- dbpassword: limesurvey
- dbhost: localhost
- dbport: 3306
tasks:
- name: set password for root
shell: echo "mariadb-server-10.1 mysql-server/root_password password root" | sudo debconf-set-selections
become: yes
- name: set password for root
shell: echo "mariadb-server-10.1 mysql-server/root_password_again password root" | sudo debconf-set-selections
become: yes
- name: install mariadb
apt:
name: mariadb-server
state: present
become: yes
- name: enable and start mariadb
systemd:
name: mysql
enabled: yes
state: started
become: yes
- name: Install required software
apt: name={{ item }} state=present
with_items:
- libmysqlclient-dev
- python-pip
become: true
- name: install MySQL-python using pip
pip:
name: "{{ item }}"
state: forcereinstall
with_items:
- pip
- MySQL-python
become: true
- name: create db
mysql_db:
name={{ dbname }}
state=present
encoding=utf8
login_user=root
become: true
- name: create and grant a database user
mysql_user:
name={{ dbuser }}
password={{ dbpassword }}
priv="limesurvey.*:ALL"
state=present
become: true
- name: Install apache and php modules
apt: name={{ item }} state=present
with_items:
- apache2
- libapache2-mod-php7.2
- php7.2-gd
- php7.2-json
- php7.2-mysql
- php7.2-pdo
- php7.2-curl
- php7.2-mbstring
- php7.2-xml
- php7.2-zip
become: true
- name: download limesurvey
get_url:
url: https://github.com/LimeSurvey/LimeSurvey/archive/3.14.0+180730.tar.gz
dest: /tmp/
become: true
- name: extract limesurvey
unarchive:
remote_src: yes
src: /tmp/LimeSurvey-3.14.0-180730.tar.gz
dest: /opt/
become: true
- name: change owner
file:
path: /opt/LimeSurvey-3.14.0-180730
owner: www-data
group: www-data
recurse: yes
become: true
- name: symlink
file:
path: /var/www/html/limesurvey
state: link
src: /opt/LimeSurvey-3.14.0-180730
become: true
- name: clean up
file:
state: absent
path: /tmp/LimeSurvey-3.14.0-180730.tar.gz
become: yes
- name: start apache2.service
systemd:
name: apache2
state: restarted
become: yes
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False
[nifi-pg]
192.168.55.61
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant
ansible-playbook -i inventory nifi-pg.yml
- hosts: nifi-pg
vars:
- dbname: test
- dbuser: test
- dbpassword: test
tasks:
- name: configure sources.list
blockinfile:
dest: /etc/apt/sources.list.d/pgdg.list
create: yes
block: |
deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main
become: true
- name: add an apt key
apt_key:
url: https://www.postgresql.org/media/keys/ACCC4CF8.asc
state: present
become: yes
- name: install packages
apt:
name: ca-certificates
state: latest
become: yes
- name: Install required software
apt: name={{ item }} state=latest
with_items:
- postgresql-10
- libpq-dev
- python-dev
- python-pip
become: true
- name: install psycopg2 using pip
pip:
name: "{{ item }}"
state: forcereinstall
with_items:
- psycopg2-binary
become: true
- name: configure postgresql.conf
blockinfile:
dest: /etc/postgresql/10/main/postgresql.conf
create: yes
block: |
listen_addresses='*'
become: true
- name: edit pg_hba.conf
replace: dest=/etc/postgresql/10/main/pg_hba.conf regexp="host.*all.*all.*127.0.0.1" replace="#host all all 127.0.0.1"
become: true
- name: edit pg_hba.conf
replace: dest=/etc/postgresql/10/main/pg_hba.conf regexp="^host.*all.*all.*::1/128.*ident" replace="host all all ::1/128 password"
become: true
- name: configure postgresql.conf
blockinfile:
dest: /etc/postgresql/10/main/pg_hba.conf
create: yes
block: |
host all all 127.0.0.1/32 password
host all all 192.168.1.0/24 password
host all all 192.168.55.0/24 password
become: true
- name: enable and start postgresq.service
systemd:
daemon_reload: yes
enabled: yes
state: started
name: postgresql.service
become: true
- name: create PostgreSQL user
postgresql_user:
name: "{{ dbuser }}"
password: "{{ dbpassword }}"
login_user: postgres
encrypted: yes
become: true
become_user: postgres
- name: create a database
postgresql_db:
name: "{{ dbname }}"
owner: "{{ dbuser }}"
encoding: 'UTF-8'
lc_collate: 'ja_JP.UTF-8'
lc_ctype: 'ja_JP.UTF-8'
template: 'template0'
login_user: postgres
become: true
become_user: postgres
- name: download jdbc driver
get_url:
url: https://jdbc.postgresql.org/download/postgresql-42.2.4.jar
dest: /usr/share/java
become: true
- name: configure limits.conf
blockinfile:
dest: /etc/security/limits.conf
create: yes
block: |
* hard nofile 50000
* soft nofile 50000
* hard nproc 10000
* soft nproc 10000
become: true
- name: Install openjdk
apt: name={{ item }} state=present
with_items:
- openjdk-8-jdk
become: true
- name: download nifi
get_url:
url: http://ftp.riken.jp/net/apache/nifi/1.7.1/nifi-1.7.1-bin.tar.gz
dest: /opt
become: true
- name: extract nifi
unarchive:
remote_src: yes
src: /opt/nifi-1.7.1-bin.tar.gz
dest: /opt/
become: true
- name: setup systemd
blockinfile:
dest: /etc/systemd/system/nifi.service
create: yes
block: |
[Unit]
Description=Apache Nifi
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/opt/nifi-1.7.1/bin/nifi.sh start
ExecStop=/opt/nifi-1.7.1/bin/nifi.sh stop
KillMode=none
[Install]
WantedBy=multi-user.target
become: true
- name: clean up
file:
state: absent
path: /opt/nifi-1.7.1-bin.tar.gz
become: yes
- name: enable and start nifi.service
systemd:
daemon_reload: yes
enabled: yes
state: started
name: nifi.service
become: true
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False
[node-exporter]
192.168.1.16
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=pi
ansible_ssh_pass=raspberry
ansible_sudo_pass=raspberry
ansible-playbook -i inventory node-exporter.yml
- hosts: node-exporter
vars:
- password: prometheus
- arch: armv7
tasks:
- name: create prometheus group
group:
name: prometheus
become: true
- name: create prometheus user
user:
name: prometheus
group: prometheus
password: "{{ password | password_hash('sha512') }}"
become: true
- name: create prometheus directory
file:
path: /opt/prometheus
state: directory
owner: prometheus
become: true
- name: download prometheus node exporter
get_url:
url: https://github.com/prometheus/node_exporter/releases/download/v0.16.0/node_exporter-0.16.0.linux-{{ arch }}.tar.gz
dest: /opt/prometheus/
become: true
become_user: prometheus
- name: extract prometheus node exporter
unarchive:
remote_src: yes
src: /opt/prometheus/node_exporter-0.16.0.linux-{{ arch }}.tar.gz
dest: /opt/prometheus/
become: true
become_user: prometheus
- name: symlink
file:
path: /bin/node_exporter
state: link
src: /opt/prometheus/node_exporter-0.16.0.linux-{{ arch }}/node_exporter
become: true
- name: clean up
file:
state: absent
path: /opt/prometheus/node_exporter-0.16.0.linux-{{ arch }}.tar.gz
become: yes
become_user: prometheus
- name: setup systemd
blockinfile:
dest: /etc/systemd/system/node-exporter.service
create: yes
block: |
[Unit]
Description=Prometheus Node Exporter
Requires=network.target
[Service]
Restart=always
WorkingDirectory=/opt/prometheus/node_exporter-0.16.0.linux-{{ arch }}
ExecStart=/bin/node_exporter
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
become: true
- name: enable and start node-exporter
systemd:
daemon_reload: yes
enabled: yes
state: started
name: node-exporter.service
become: true
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False
[lime-survey]
192.168.1.107
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant
ansible-playbook -i inventory limesurvey.yml
- hosts: lime-survey
vars:
- dbname: limesurvey
- dbuser: limesurvey
- dbpassword: limesurvey
- dbhost: localhost
- dbport: 3306
tasks:
- name: set password for root
shell: echo "mariadb-server-10.1 mysql-server/root_password password root" | sudo debconf-set-selections
become: yes
- name: set password for root
shell: echo "mariadb-server-10.1 mysql-server/root_password_again password root" | sudo debconf-set-selections
become: yes
- name: install mariadb
apt:
name: mariadb-server
state: present
become: yes
- name: enable and start mariadb
systemd:
name: mysql
enabled: yes
state: started
become: yes
- name: Install required software
apt: name={{ item }} state=present
with_items:
- libmysqlclient-dev
- python-pip
become: true
- name: install MySQL-python using pip
pip:
name: "{{ item }}"
state: forcereinstall
with_items:
- pip
- MySQL-python
become: true
- name: create db
mysql_db:
name={{ dbname }}
state=present
encoding=utf8
login_user=root
become: true
- name: create and grant a database user
mysql_user:
name={{ dbuser }}
password={{ dbpassword }}
priv="limesurvey.*:ALL"
state=present
become: true
- name: Install apache and php modules
apt: name={{ item }} state=present
with_items:
- apache2
- libapache2-mod-php7.0
- php7.0-gd
- php7.0-json
- php7.0-mysql
- php7.0-pdo
- php7.0-curl
- php7.0-mbstring
- php7.0-mcrypt
- php7.0-xml
- php7.0-zip
become: true
- name: download limesurvey
get_url:
url: https://github.com/LimeSurvey/LimeSurvey/archive/3.14.0+180730.tar.gz
dest: /tmp/
become: true
- name: extract limesurvey
unarchive:
remote_src: yes
src: /tmp/LimeSurvey-3.14.0-180730.tar.gz
dest: /opt/
become: true
- name: change owner
file:
path: /opt/LimeSurvey-3.14.0-180730
owner: www-data
group: www-data
recurse: yes
become: true
- name: symlink
file:
path: /var/www/html/limesurvey
state: link
src: /opt/LimeSurvey-3.14.0-180730
become: true
- name: clean up
file:
state: absent
path: /tmp/LimeSurvey-3.14.0-180730.tar.gz
become: yes
- name: start apache2.service
systemd:
name: apache2
state: restarted
become: yes
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False
[nextcloud]
192.168.1.61
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant
ansible-playbook -i inventory nextcloud-mariadb.yml
- hosts: nextcloud
vars:
- dbname: nextcloud
- dbuser: nextcloud
- dbpassword: nextcloud
- dbhost: localhost
- dbport: 3306
tasks:
- name: set password for root
shell: echo "mariadb-server-10.1 mysql-server/root_password password root" | sudo debconf-set-selections
become: yes
- name: set password for root
shell: echo "mariadb-server-10.1 mysql-server/root_password_again password root" | sudo debconf-set-selections
become: yes
- name: install mariadb
apt:
name: mariadb-server
state: present
become: yes
- name: enable and start mariadb
systemd:
name: mysql
enabled: yes
state: started
become: yes
- name: Install required software
apt: name={{ item }} state=present
with_items:
- libmysqlclient-dev
- python-pip
become: true
- name: install MySQL-python using pip
pip:
name: "{{ item }}"
state: forcereinstall
with_items:
- pip
- MySQL-python
become: true
- name: create db
mysql_db:
name={{ dbname }}
state=present
encoding=utf8
login_user=root
become: true
- name: create and grant a database user
mysql_user:
name={{ dbuser }}
password={{ dbpassword }}
priv="{{ dbuser }}.*:ALL"
state=present
become: true
- name: Install apache and php modules
apt: name={{ item }} state=present
with_items:
- apache2
- libapache2-mod-php7.2
- php7.2-gd
- php7.2-json
- php7.2-mysql
- php7.2-pdo
- php7.2-curl
- php7.2-mbstring
- php7.2-xml
- php7.2-zip
- php7.2-imagick
- php7.2-intl
- unzip
become: true
- name: download nextcloud
get_url:
url: https://download.nextcloud.com/server/releases/nextcloud-13.0.5.zip
dest: /tmp/
become: true
- name: extract nextcloud
unarchive:
remote_src: yes
src: /tmp/nextcloud-13.0.5.zip
dest: /opt/
become: true
- name: change owner
file:
path: /opt/nextcloud
owner: www-data
group: www-data
recurse: yes
become: true
- name: symlink
file:
path: /var/www/html/nextcloud
state: link
src: /opt/nextcloud
become: true
- name: clean up
file:
state: absent
path: /tmp/nextcloud-13.0.5.zip
become: yes
- name: start apache2.service
systemd:
name: apache2
state: restarted
become: yes
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False
[nifi-postgresql]
192.168.1.107
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant
ansible-playbook -i inventory nifi-postgresql.yml
- hosts: nifi-postgresql
vars:
- dbname: test
- dbuser: test
- dbpassword: test
tasks:
- name: install epel-release
yum:
name: epel-release
state: present
become: yes
- name: download postgresql repos
get_url:
url: https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
dest: /tmp
become: true
- name: install repos
yum: state=present name=/tmp/pgdg-centos10-10-2.noarch.rpm
become: true
- name: install PostgreSQL
yum: name={{ item }} state=latest enablerepo=epel
with_items:
- postgresql10-server
- postgresql10-devel
- postgresql10-contrib
- python-devel
- python36-devel
- python-pip
become: true
- name: install psycopg2 using pip
pip:
name: "{{ item }}"
state: forcereinstall
with_items:
- psycopg2-binary
become: true
- name: initdb
shell: /usr/pgsql-10/bin/postgresql-10-setup initdb
become: yes
- name: configure postgresql.conf
blockinfile:
dest: /var/lib/pgsql/10/data/postgresql.conf
create: yes
block: |
listen_addresses='*'
become: true
- name: edit pg_hba.conf
replace: dest=/var/lib/pgsql/10/data/pg_hba.conf regexp="host.*all.*all.*127.0.0.1" replace="#host all all 127.0.0.1"
become: true
- name: edit pg_hba.conf
replace: dest=/var/lib/pgsql/10/data/pg_hba.conf regexp="^host.*all.*all.*::1/128.*ident" replace="host all all ::1/128 password"
become: true
- name: configure postgresql.conf
blockinfile:
dest: /var/lib/pgsql/10/data/pg_hba.conf
create: yes
block: |
host all all 127.0.0.1/32 password
host all all 192.168.1.0/24 password
host all all 192.168.55.0/24 password
become: true
- name: enable and start postgresql-10.service
systemd:
daemon_reload: yes
enabled: yes
state: started
name: postgresql-10.service
become: true
- name: create PostgreSQL user
postgresql_user:
name: "{{ dbuser }}"
password: "{{ dbpassword }}"
login_user: postgres
encrypted: yes
become: true
become_user: postgres
- name: create a database
postgresql_db:
name: "{{ dbname }}"
owner: "{{ dbuser }}"
encoding: 'UTF-8'
lc_collate: 'ja_JP.UTF-8'
lc_ctype: 'ja_JP.UTF-8'
template: 'template0'
login_user: postgres
become: true
become_user: postgres
- name: configure limits.conf
blockinfile:
dest: /etc/security/limits.conf
create: yes
block: |
* hard nofile 50000
* soft nofile 50000
* hard nproc 10000
* soft nproc 10000
become: true
- name: Install openjdk
yum: name={{ item }} state=present
with_items:
- java-1.8.0-openjdk
become: true
- name: download connectorJ
get_url:
url: https://jdbc.postgresql.org/download/postgresql-42.2.4.jar
dest: /usr/share/java
become: true
- name: download nifi
get_url:
url: http://ftp.riken.jp/net/apache/nifi/1.7.1/nifi-1.7.1-bin.tar.gz
dest: /opt
become: true
- name: extract nifi
unarchive:
remote_src: yes
src: /opt/nifi-1.7.1-bin.tar.gz
dest: /opt/
become: true
- name: setup systemd
blockinfile:
dest: /etc/systemd/system/nifi.service
create: yes
block: |
[Unit]
Description=Apache Nifi
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/opt/nifi-1.7.1/bin/nifi.sh start
ExecStop=/opt/nifi-1.7.1/bin/nifi.sh stop
KillMode=none
[Install]
WantedBy=multi-user.target
become: true
- name: setup systemd
blockinfile:
dest: /opt/nifi-1.7.1/bin/nifi-env.sh
create: yes
block: |
JAVA_HOME=/usr/lib/jvm/jre-1.8.0
become: true
- name: clean up
file:
state: absent
path: /opt/nifi-1.7.1-bin.tar.gz
become: yes
- name: enable and start nifi.service
systemd:
daemon_reload: yes
enabled: yes
state: started
name: nifi.service
become: true
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False
[rundeck-postgresql]
192.168.55.61
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant
ansible-playbook -i inventory rundeck-postgresql.yml
- hosts: rundeck-postgresql
vars:
- dbname: rundeck
- dbuser: rundeck
- dbpassword: rundeck
- dbhost: localhost
- dbport: 3306
- serverurl: http://192.168.55.61:4440
tasks:
- name: generate ssh key
shell: ssh-keygen -t rsa -f /root/.ssh/id_rsa -N ""
become: yes
- name: configure sources.list
blockinfile:
dest: /etc/apt/sources.list.d/pgdg.list
create: yes
block: |
deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main
become: true
- name: add an apt key
apt_key:
url: https://www.postgresql.org/media/keys/ACCC4CF8.asc
state: present
become: yes
- name: install packages
apt:
name: ca-certificates
state: latest
become: yes
- name: Install required software
apt: name={{ item }} state=latest
with_items:
- postgresql-10
- libpq-dev
- python-dev
- python-pip
become: true
- name: install psycopg2 using pip
pip:
name: "{{ item }}"
state: forcereinstall
with_items:
- psycopg2-binary
become: true
- name: configure postgresql.conf
blockinfile:
dest: /etc/postgresql/10/main/postgresql.conf
create: yes
block: |
listen_addresses='*'
become: true
- name: edit pg_hba.conf
replace: dest=/etc/postgresql/10/main/pg_hba.conf regexp="host.*all.*all.*127.0.0.1" replace="#host all all 127.0.0.1"
become: true
- name: edit pg_hba.conf
replace: dest=/etc/postgresql/10/main/pg_hba.conf regexp="^host.*all.*all.*::1/128.*ident" replace="host all all ::1/128 password"
become: true
- name: configure postgresql.conf
blockinfile:
dest: /etc/postgresql/10/main/pg_hba.conf
create: yes
block: |
host all all 127.0.0.1/32 password
host all all 192.168.1.0/24 password
host all all 192.168.55.0/24 password
become: true
- name: enable and start postgresq.service
systemd:
daemon_reload: yes
enabled: yes
state: started
name: postgresql.service
become: true
- name: create PostgreSQL user
postgresql_user:
name: "{{ dbuser }}"
password: "{{ dbpassword }}"
login_user: postgres
encrypted: yes
become: true
become_user: postgres
- name: create a database
postgresql_db:
name: "{{ dbname }}"
owner: "{{ dbuser }}"
encoding: 'UTF-8'
lc_collate: 'ja_JP.UTF-8'
lc_ctype: 'ja_JP.UTF-8'
template: 'template0'
login_user: postgres
become: true
become_user: postgres
- name: download jdbc driver
get_url:
url: https://jdbc.postgresql.org/download/postgresql-42.2.4.jar
dest: /usr/share/java
become: true
- name: Install openjdk
apt: name={{ item }} state=present
with_items:
- openjdk-8-jdk
become: true
- name: create a directory
file: path=/opt/rundeck state=directory owner=root group=root
become: yes
- name: download rundeck
get_url:
url: http://dl.bintray.com/rundeck/rundeck-maven/rundeck-launcher-2.11.4.jar
dest: /opt/rundeck
become: true
- name: install rundeck
shell: /usr/bin/java -Xmx1024m -jar rundeck-launcher-2.11.4.jar --installonly
args:
chdir: /opt/rundeck/
become: yes
- name: edit rundeck-config.properties
replace: dest=/opt/rundeck/server/config/rundeck-config.properties regexp="grails.serverURL=http://.*:4440" replace="grails.serverURL={{ serverurl }}"
become: true
- name: edit rundeck-config.properties
replace: dest=/opt/rundeck/server/config/rundeck-config.properties regexp="dataSource.url = jdbc:h2:file:/opt/rundeck/server/data/grailsdb;MVCC=true" replace="dataSource.url = jdbc:postgresql://localhost:5432/rundeck"
become: true
- name: edit rundeck-config.properties
blockinfile:
dest: /opt/rundeck/server/config/rundeck-config.properties
create: yes
block: |
dataSource.username = rundeck
dataSource.password = rundeck
become: true
- name: setup systemd
blockinfile:
dest: /etc/systemd/system/rundeck.service
create: yes
block: |
[Unit]
Description=rundeck
[Service]
Type=simple
ExecStart=/usr/bin/java -Xmx2048m -jar rundeck-launcher-2.11.4.jar -b /opt/rundeck
WorkingDirectory=/opt/rundeck
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
become: true
- name: enable and start rundeck.service
systemd:
daemon_reload: yes
enabled: yes
state: started
name: rundeck.service
become: true