kitaro-tn
5/27/2015 - 5:29 AM

ansibleでpostgresqlインストール ref: http://qiita.com/tatsu_nishiki/items/04aa7279c17be8b9b0ed

ansibleでpostgresqlインストール ref: http://qiita.com/tatsu_nishiki/items/04aa7279c17be8b9b0ed

---
- hosts: all
  sudo: yes
  vars:
    dbuser: "sample-ansible"
    dbpass: "abcdefg"
    dbname: "ansible-db"

  tasks:
  - name: install postgresql
    yum: name={{ item }} state=latest
    with_items:
      - postgresql-server
      - postgresql-devel
      - postgresql-contrib
      - python-psycopg2

  - name: postgresql initdb
    shell: service postgresql initdb

  - name: start postgresql
    service: name=postgresql state=started  enabled=yes

  - name: postgres user sudores
    lineinfile: 
      dest: /etc/sudoers.d/postgres 
      owner: root
      group: root
      mode: 0440
      line: "%vagrant ALL=(postgres) NOPASSWD: ALL"
      state: present
      create: yes
      validate: "visudo -cf %s"

  - name : create database
    postgresql_db: 
      name: "{{ dbname }}"
      encoding: "UTF-8"
      login_user: postgres
    sudo_user: postgres
    sudo: yes

  - name: create user
    postgresql_user: 
      db: "{{ dbname }}"
      name: "{{ dbuser }}"
      password: "{{ dbpass }}"
      priv: ALL
      state: present
      login_user: postgres
    sudo_user: postgres
    sudo: yes

[vagrant@postgresql-server ~]$ sudo su - postgres
-bash-4.1$ psql -l
                                      List of databases
    Name    |  Owner   | Encoding |  Collation  |    Ctype    |       Access privileges
------------+----------+----------+-------------+-------------+-------------------------------
 ansible-db | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres
                                                              : postgres=CTc/postgres
                                                              : "sample-ansible"=CTc/postgres
 postgres   | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
                                                              : postgres=CTc/postgres
 template1  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
                                                              : postgres=CTc/postgres
(4 rows)