2018年9月9日日曜日

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

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

〇Rundeckの画面


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

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

inventory例
[rundeck-mariadb]
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-mariadb.ymlを準備し、以下のコマンドを実行します。
ansible-playbook -i inventory rundeck-mariadb.yml

rundeck-mariadb.yml
- hosts: rundeck-mariadb
  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: 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="{{ dbname }}.*:ALL"
        state=present
      become: true
    - name: download connectorJ
      get_url:
        url: https://downloads.mariadb.com/Connectors/java/connector-java-2.2.6/mariadb-java-client-2.2.6.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:mysql://localhost/rundeck?autoReconnect=true"
      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

0 件のコメント:

コメントを投稿