ラベル Ansible の投稿を表示しています。 すべての投稿を表示
ラベル Ansible の投稿を表示しています。 すべての投稿を表示

2020年4月13日月曜日

Raspberry Pi(Raspbian Buster)/Debian 10(Buster)にAnsibleをインストールする

Ansibleを使用する事でインストールやメンテナンスを自動化する事ができます。

〇インストール方法
以下のコマンドを実行します。
sudo apt-get -y install ansible

※動作確認
ansible-playbook --version

2019年12月4日水曜日

AnsibleでXML関連コマンドラインツールをインストールする

以下のAnsibleのRoleを使用して、xmllint/xsltproc/xmlstarletといったXML関連のコマンドラインツールをまとめてインストールする事ができます。

roles/xmltools/tasks/main.yml
---
- name: Install packages
  apt: name={{ item }} state=latest update_cache=yes
  vars:
    item:
    - libxml2-utils
    - xsltproc
    - xmlstarlet
  become: true

2019年12月3日火曜日

AnsibleでPostgreSQL11をインストールする

以下のAnsibleのRoleを使用して、PostgreSQL11をインストールする事ができます。

roles/pg11/tasks/main.yml
---
- 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

2019年11月29日金曜日

AnsibleでDocker/docker-composeをインストールする

以下のAnsibleのRoleを使用して、Dockerとdocker-composeをインストールする事ができます。

roles/docker_compose/tasks/main.yml
---
- 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

2019年11月27日水曜日

AnsibleでUbuntu18.04/Debian Buster/Raspbian Busterの自動アップデートを設定する

AnsibleでUbuntu18.04/Debian Buster/Raspbian Busterの自動アップデートを設定するには、以下のroleを使用します。

roles/automaticupdates/tasks/main.yml
---
- 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

2019年11月25日月曜日

AnsibleでBorgbackupをインストールする

Borgbackupで差分バックアップを行うことができます。以下のファイルを使用して、AnsibleでBorgbackupをインストールする事ができます。

borgbackup.yml ※各パラメータは適宜変更してください。
---
- hosts: borgbackup
  vars:
    borgbackup_repository: /opt/repo
    borgbackup_encryption_key: repokey
    borgbackup_passphrase: mypassphrase
    borgbackup_target: /home/vagrant/playbook
  roles:
    - borgbackup

role/borgbackup/tasks/main.yml
---
- 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 }}"

〇動作環境
・Ubuntu 18.04

2019年11月24日日曜日

Ansibleでpipenvをインストールする

以下のファイルを使用して、Ansibleでpipenvをインストールする事ができます。

pipenv.yml
- hosts: pipenv
  roles:
    - pipenv

roles/pipenv/tasks/main.yml
---
- 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

〇動作環境
・Ubuntu 18.04

2019年10月25日金曜日

Ansibleでnodejsをインストールする

以下のAnsibleのRoleを使用して、nodejsをインストールする事ができます。

roles/nodejs10/tasks/main.yml
---
- 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

2018年10月26日金曜日

AnsibleでArduino IDEをUbuntu18.04にインストールする

Arduino IDEでスケッチと呼ばれるプログラムを作成し、Arduinoに実行イメージを書き込んで実行する事ができます。

〇Arduino IDEの画面


〇インストール方法
1.下準備
~/.ansible.cfgに以下の内容を設定します
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False

2. Arduinoのバージャンやインストール対象のユーザを環境に合わせてinventoryファイルに記入します

inventory例
[arduino-ide]
192.168.1.159

[all:vars]
ansible_ssh_port=22
ansible_ssh_user=ubuntu
ansible_ssh_pass=ubuntu
ansible_sudo_pass=ubuntu

3.inventory、arduino-ide.ymlを準備し、以下のコマンドを実行します。
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


○関連情報
・Ansibleに関する他の記事はこちらを参照してください。

2018年10月24日水曜日

AnsibleでsysbenchとMariaDBをインストールする(Ubuntu18.04用)

sysbenchでホストマシンやデータベースのベンチマークを行うことができます。

〇インストール方法
1.下準備
~/.ansible.cfgに以下の内容を設定します
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False

2. インストール対象ホストのユーザやパスワードを環境に合わせてinventoryファイルに記入します

inventory例
[sysbench]
192.168.1.61

[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant

3.inventory、sysbench-mariadb.ymlを準備し、以下のコマンドを実行します。
ansible-playbook -i inventory sysbench-mariadb.yml

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


○関連情報
・Ansibleに関する他の記事はこちらを参照してください。

・sysbenchに関する他の記事はこちらを参照してください。

2018年9月29日土曜日

AnsibleでCentOS7.5にunixBenchをインストールする

unixBenchは歴史あるベンチマークツールです

〇インストール方法
1.下準備
~/.ansible.cfgに以下の内容を設定します
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False

2. Dockerインストール対象のホスト・ユーザ・パスワードを環境に合わせてinventoryファイルに記入します

inventory例
[unixbench]
192.168.1.61

[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant

3.inventoryとunixbench.ymlを準備し、以下のコマンドを実行します。unixbenchのビルド、インストールとベンチマーク実行も行います。
ansible-playbook -i inventory unixbench.yml

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


○関連情報
・unixBenchに関する他の記事はこちらを参照してください。

その他のAnsibleの記事

2018年9月27日木曜日

AnsibleでUbuntu18.04にDockerとdocker-composeをインストールする

Dockerとdocker-composeでコンテナの作成や実行を行うことができます。

〇インストール方法
1.下準備
~/.ansible.cfgに以下の内容を設定します
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False

2. Dockerインストール対象のホスト・ユーザ・パスワードを環境に合わせてinventoryファイルに記入します

inventory例
[docker]
192.168.1.61

[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant

3.inventoryとdocker.ymlを準備し、以下のコマンドを実行します。dockerグループに所属させたいユーザをusername変数に指定します。
ansible-playbook -i inventory docker.yml

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


○関連情報
・Ansibleに関する他の記事はこちらを参照してください。

2018年9月20日木曜日

AnsibleでRaspberry PiにDockerとdocker-composeをインストールする

Dockerとdocker-composeでコンテナの作成や実行を行うことができます。

〇インストール方法
1.下準備
~/.ansible.cfgに以下の内容を設定します
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False

2. Dockerインストール対象のホスト・ユーザ・パスワードを環境に合わせてinventoryファイルに記入します

inventory例
[docker]
192.168.1.16

[all:vars]
ansible_ssh_port=22
ansible_ssh_user=pi
ansible_ssh_pass=raspberry
ansible_sudo_pass=raspberry

3.inventoryとdocker.ymlを準備し、以下のコマンドを実行します。
ansible-playbook -i inventory docker.yml

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


○関連情報
・Ansibleに関する他の記事はこちらを参照してください。

・Raspberry Pi上のDockerに関する他の記事はこちらを参照してください。

AnsibleでMariaDBとLimeSurveyをインストールする(Ubuntu18.04用)

LimeSurveyで、オンラインアンケートを設置することができます。

〇LimeSurveyの管理者画面


〇インストール方法
1.下準備
~/.ansible.cfgに以下の内容を設定します
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False

2. インストール対象ホストのユーザやパスワードを環境に合わせてinventoryファイルに記入します

inventory例
[lime-survey]
192.168.1.107

[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant

3.inventory、limesurvey.ymlを準備し、以下のコマンドを実行します。
ansible-playbook -i inventory limesurvey.yml

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

4.ブラウザからhttp://192.168.55.107/limesurveyにアクセスして、「日本語 - Japan」を選択して「Start installation」をクリックします


5.ライセンスを確認して、同意できるのであれば「同意する」をクリックします


4.「インストール前のチェック」画面で「次へ」をクリックします


6.「データベース設定」画面で、以下の項目を入力して「次へ」をクリックします
データベース形式: MySQL
データの場所: localhost
データベースユーザー: limesurvey
データベースパスワード: limesurvey
データベース名: limesurvey


7.「データベースを作成する」をクリックします


8.「管理者設定」画面で管理者情報等を入力して、「次へ」をクリックします


9.インストーラ完了画面



○関連情報
・Ansibleに関する他の記事はこちらを参照してください。

・LimeSurveyに関する他の記事はこちらを参照してください。

2018年9月19日水曜日

AnsibleでApache NiFiとPostgreSQL10をインストールする(Ubuntu18.04用)

Apache Nifiは様々なデータを処理・分配するためのソフトウェアです。

〇Apache NiFiの画面


〇インストール方法
1.下準備
~/.ansible.cfgに以下の内容を設定します
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False

2. インストール対象ホストのユーザやパスワードを環境に合わせてinventoryファイルに記入します

inventory例
[nifi-pg]
192.168.55.61

[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant

3.inventory、kanboard.ymlを準備し、以下のコマンドを実行します。
ansible-playbook -i inventory nifi-pg.yml

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

4.DBCPConnectionPoolで、以下のようにパラメータを設定してローカルのPostgreSQLにアクセスします。
Database Connection -> URL jdbc:postgresql://localhost:5432/test
Database Driver Class Name -> org.postgresql.Driver
Database Driver Location(s) -> /usr/share/java/postgresql-42.2.4.jar
Database User -> test
Password -> test


○関連情報
・Apache NiFiに関する他の記事はこちらを参照してください。

・psycopg2に関する他の記事はこちらを参照してください。

その他のAnsibleの記事

2018年9月17日月曜日

AnsibleでRaspberry PiにPrometheus Node Exporterをインストールする

Prometheus Node Exporterでハードウェア、OS情報の収集を行います。

〇インストール方法
1.下準備
~/.ansible.cfgに以下の内容を設定します
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False

2. Prometheus Node Exporterをインストール対象のユーザやパスワードを環境に合わせてinventoryファイルに記入します

inventory例
[node-exporter]
192.168.1.16

[all:vars]
ansible_ssh_port=22
ansible_ssh_user=pi
ansible_ssh_pass=raspberry
ansible_sudo_pass=raspberry

3.inventory node-exporter-deb.ymlを準備し、以下のコマンドを実行します。
archパラメータをRaspberry Pi 3系ならarmv7、Raspberry Pi 1系ならarmv6を指定します
ansible-playbook -i inventory node-exporter.yml

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


○関連情報
・Ansibleに関する他の記事はこちらを参照してください。

2018年9月16日日曜日

AnsibleでMariaDBとLimeSurveyをインストールする(Ubuntu16.04用)

LimeSurveyで、オンラインアンケートを設置することができます。

〇LimeSurveyの管理者画面


〇インストール方法
1.下準備
~/.ansible.cfgに以下の内容を設定します
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False

2. インストール対象ホストのユーザやパスワードを環境に合わせてinventoryファイルに記入します

inventory例
[lime-survey]
192.168.1.107

[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant

3.inventory、limesurvey.ymlを準備し、以下のコマンドを実行します。
ansible-playbook -i inventory limesurvey.yml

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

4.ブラウザからhttp://192.168.55.107/limesurveyにアクセスして、「日本語 - Japan」を選択して「Start installation」をクリックします


5.ライセンスを確認して、同意できるのであれば「同意する」をクリックします


4.「インストール前のチェック」画面で「次へ」をクリックします


6.「データベース設定」画面で、以下の項目を入力して「次へ」をクリックします
データベース形式: MySQL
データの場所: localhost
データベースユーザー: limesurvey
データベースパスワード: limesurvey
データベース名: limesurvey


7.「データベースを作成する」をクリックします


8.「管理者設定」画面で管理者情報等を入力して、「次へ」をクリックします


9.インストーラ完了画面



○関連情報
・Ansibleに関する他の記事はこちらを参照してください。

・LimeSurveyに関する他の記事はこちらを参照してください。

2018年9月15日土曜日

AnsibleでnextcloudとMariaDBをインストールする(Ubuntu18.04用)

nextcloudで、Dropboxのようにファイルを管理・共有する事ができます。

〇nextcloudの画面


〇インストール方法
1.下準備
~/.ansible.cfgに以下の内容を設定します
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False

2. インストール対象ホストのユーザやパスワードを環境に合わせてinventoryファイルに記入します

inventory例
[nextcloud]
192.168.1.61

[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant

3.inventory、nextcloud.ymlを準備し、以下のコマンドを実行します。
ansible-playbook -i inventory nextcloud-mariadb.yml

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

2.ブラウザからhttp://<対象ホスト>/nextcloud/にアクセスして、初期設定を行います。管理者の情報の他、以下の情報を指定します。
DB user: nextcloud, DB password: nextcloud, DB: nextcloud, DB host: localhost:3306


○関連情報
・Nextcloudに関する他の記事はこちらを参照してください。

その他のAnsibleの記事

2018年9月14日金曜日

AnsibleでApache NiFiとPostgreSQL10をインストールする(CentOS7.5用)

Apache Nifiは様々なデータを処理・分配するためのソフトウェアです。

〇Apache NiFiの画面


〇インストール方法
1.下準備
~/.ansible.cfgに以下の内容を設定します
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False

v 2. インストール対象ホストのユーザやパスワードを環境に合わせてinventoryファイルに記入します

inventory例
[nifi-postgresql]
192.168.1.107

[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant

3.inventory、kanboard.ymlを準備し、以下のコマンドを実行します。
ansible-playbook -i inventory nifi-postgresql.yml

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

4.DBCPConnectionPoolで、以下のようにパラメータを設定してローカルのPostgreSQLにアクセスします。
Database Connection -> URL jdbc:postgresql://localhost:5432/test
Database Driver Class Name -> org.postgresql.Driver
Database Driver Location(s) -> /usr/share/java/postgresql-42.2.4.jar
Database User -> test
Password -> test


○関連情報
・Apache NiFiに関する他の記事はこちらを参照してください。

・psycopg2に関する他の記事はこちらを参照してください。

その他のAnsibleの記事

2018年9月13日木曜日

AnsibleでRundeckとPostgreSQL10をインストールする(Ubuntu18.04用)

Rundeckはオープンソースのジョブスケジューラです。

〇Rundeckの画面

ブラウザからhttp://<ホスト名またはIP>:4440にアクセスします。デフォルトのユーザ名/パスワードはadmin/adminです。

〇インストール方法
1.下準備
~/.ansible.cfgに以下の内容を設定します
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False

2. インストール対象ホストのユーザやパスワードを環境に合わせてinventoryファイルに記入します

inventory例
[rundeck-postgresql]
192.168.55.61

[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant

3.inventory、rundeck-postgresql.ymlを準備し、以下のコマンドを実行します。
ansible-playbook -i inventory rundeck-postgresql.yml

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


○関連情報
・Ansibleに関する他の記事はこちらを参照してください。