2018年8月21日火曜日

Ansibleでnextcloud13.0.5とPostgreSQL10をインストールする(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-pg.yml

nextcloud-pg.yml
- hosts: nextcloud
  vars:
    - dbname: nextcloud
    - dbuser: nextcloud
    - dbpassword: nextcloud
    - dbhost: localhost
  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: 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-pgsql
        - 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:5432


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

0 件のコメント:

コメントを投稿