7

Ansible を使用して、Vagrant で開始された仮想マシンをプロビジョニングしています。(推奨) VMware プロバイダーと VirtualBox の両方を使用してテストしましたが、それぞれで同じ結果が得られました。

so次の一連のタスクを使用して、と呼ばれるデータベースとアクセス権を持つユーザーを作成しようとしていdjangoます。ただし、データベースのパスワードは設定されていないようです。これを手動で設定すると接続できます。事前に試してみると、常にFATAL: password authentication failed for user "django".

Ansible 構成の関連セクションを以下に投稿し、その下にデバッグの関連セクションを投稿しました ( ansible.verbose = "vvv"vagrant 構成)。

# Create Prostgres DB
- hosts: all
  sudo: True
  sudo_user: postgres

  vars:
    dbname: so
    dbuser: django
    dbpassword: 4967bKzCegrPxVH4tGgQe6kFn232t7KiFDXfedVi

  tasks: 
  - name: Ensure database exists
    postgresql_db: name={{ dbname }}

  - name: Ensure DB user has access to the DB
    postgresql_user: db={{ dbname }} name={{ dbuser }} password={{ dbpassword }} priv=ALL state=present

  # Leave user with ability to create databases. This prividge should be 
  # removed for production, but is required for running tests. 
    postgresql_user: name={{ dbuser }} role_attr_flags=NOSUPERUSER,CREATEDB

詳細出力:

TASK: [Ensure DB user has access to the DB] *********************************** 
<127.0.0.1> ESTABLISH CONNECTION FOR USER: vagrant
<127.0.0.1> EXEC ['ssh', '-tt', '-q', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/Users/danielsgroves/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'Port=2222', '-o', 'IdentityFile=/Users/danielsgroves/.vagrant.d/insecure_private_key', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=vagrant', '-o', 'ConnectTimeout=10', '127.0.0.1', "/bin/sh -c 'mkdir -p /tmp/ansible-1387481596.93-132175356393082 && chmod a+rx /tmp/ansible-1387481596.93-132175356393082 && echo /tmp/ansible-1387481596.93-132175356393082'"]
<127.0.0.1> REMOTE_MODULE postgresql_user name=django role_attr_flags=NOSUPERUSER,CREATEDB
<127.0.0.1> PUT /var/folders/2j/n8ng8fdd5gj125w5zswg9kj00000gn/T/tmpvnrb37 TO /tmp/ansible-1387481596.93-132175356393082/postgresql_user
<127.0.0.1> EXEC ['ssh', '-tt', '-q', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/Users/danielsgroves/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'Port=2222', '-o', 'IdentityFile=/Users/danielsgroves/.vagrant.d/insecure_private_key', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=vagrant', '-o', 'ConnectTimeout=10', '127.0.0.1', "/bin/sh -c 'chmod a+r /tmp/ansible-1387481596.93-132175356393082/postgresql_user'"]
<127.0.0.1> EXEC ['ssh', '-tt', '-q', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/Users/danielsgroves/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'Port=2222', '-o', 'IdentityFile=/Users/danielsgroves/.vagrant.d/insecure_private_key', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=vagrant', '-o', 'ConnectTimeout=10', '127.0.0.1', '/bin/sh -c \'sudo -k && sudo -H -S -p "[sudo via ansible, key=isnxrvycjudgazbgyciehbcpiiswfczx] password: " -u postgres /bin/sh -c \'"\'"\'echo SUDO-SUCCESS-isnxrvycjudgazbgyciehbcpiiswfczx; /usr/bin/python /tmp/ansible-1387481596.93-132175356393082/postgresql_user\'"\'"\'\'']
<127.0.0.1> EXEC ['ssh', '-tt', '-q', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/Users/danielsgroves/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'Port=2222', '-o', 'IdentityFile=/Users/danielsgroves/.vagrant.d/insecure_private_key', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=vagrant', '-o', 'ConnectTimeout=10', '127.0.0.1', "/bin/sh -c 'rm -rf /tmp/ansible-1387481596.93-132175356393082/ >/dev/null 2>&1'"]
ok: [server] => {"changed": false, "user": "django"}
4

1 に答える 1

-1

その Playbook の最後のタスクは ansible によって実行されません。モジュール名の前にハイフンがありません。次のいずれかに変更します。

- postgresql_user:
    name: "{{ dbuser }}"
    role_attr_flags: "NOSUPERUSER,CREATEDB"

または(すべてのタスクに名前を付ける方が好きです)

- name: Set roles for DB user
  postgresql_user:
    name: "{{ dbuser }}"
    role_attr_flags: "NOSUPERUSER,CREATEDB"

そして、djangoユーザーとしてログインできるはずです

$ psql -U django -h localhost so

役割が設定されていないと、ユーザーはログインできません。「LOGIN」ロールは、そこで指定されているロールで暗黙的でなければならないと思いますが、PostgreSQL ドキュメントでは確認していません。

于 2014-02-10T05:39:49.560 に答える