2013-12-19 15 views
6

私はVagrantで始まる仮想マシンをプロビジョニングするためにAnsibleを使用しています。私は(好ましい)VMwareプロバイダとVirtualBoxの両方をテストに使用し、それぞれで同じ結果を得ています。Postgresのユーザーパスワードを設定しないでください

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

以下のAnsible設定の関連セクションとその下のデバッグの関連セクション(迷惑メール設定のansible.verbose = "vvv")を掲載しました。

# 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"} 
+0

興味深いことに、これは物理的なボックスで動作するように見えますが、Vagrant VMではなく私が1分後にさらに調査します。 –

+0

あなたはこれを理解したことがありますか? – jrg

+0

残念ながら。ただし、同じコマンドはDigital Oceanでホストされているプロダクションボックスに対して使用されている別のプロビジョナでも動作します。 –

答えて

-1

ですか?例えば

$ psql -U django -h localhost so 

これが解決策です。

EDIT:

その脚本の最後のタスクは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 

、あなたはその後、どのなしで

$ psql -U django -h localhost so 

でDjangoのユーザとしてログインすることができるはずですロールが設定されていると、ユーザーはログインできません。私は、PostgreSQLのドキュメントでは確認していませんが、 'LOGIN'ロールは指定されたロールに暗黙的に指定されている必要があります。

+0

この質問は、コマンドラインではなく、実行する方法について質問しています。あなたは、ホストを追加するための確実なタスクを提供できますか? – adeady

関連する問題