I've been pounding my head on this for a few hours now.
Nothing I do can get python to import psycopg2.
Consider:
- name: Setup mysql databases
hosts: localhost
connection: local
become: no
tags: [database, postgres]
gather_facts: no
pre_tasks:
- debug: var=ansible_python_interpreter
- name: Install psycopg2 for ansible to be able to create postgresql
users
become: yes
pip:
name: psycopg2
register: _psycopg2
- debug: var=_psycopg2
- command: "{{ ansible_python_interpreter }} -c 'import {{ module }};
print({{ module }}.__version__)'"
vars:
module: psycopg2
register: test
- debug: var=test
But the results are:
ansible⯠ap -i inventory/aws/ops playbooks/deploy/ops-alerta.yml --tags
database
ops/git/master !+
PLAY [Setup mysql databases]
******************************************************************************************************************************************************************************************
TASK [debug]
**********************************************************************************************************************************************************************************************************
ok: [127.0.0.1] => {
"ansible_python_interpreter": "/usr/local/bin/python"
}
TASK [Install psycopg2 for ansible to be able to create postgresql users]
*********************************************************************************************************************************************
ok: [127.0.0.1]
TASK [debug]
**********************************************************************************************************************************************************************************************************
ok: [127.0.0.1] => {
"_psycopg2": {
"changed": false,
"cmd": "/usr/local/bin/pip2 install psycopg2",
"failed": false,
"name": [
"psycopg2"
],
"requirements": null,
"state": "present",
"stderr": "",
"stderr_lines": [],
"stdout": "Requirement already satisfied: psycopg2 in
/Library/Python/2.7/site-packages (2.7.6.1)\n",
"stdout_lines": [
"Requirement already satisfied: psycopg2 in
/Library/Python/2.7/site-packages (2.7.6.1)"
],
"version": null,
"virtualenv": null
}
}
TASK [command]
********************************************************************************************************************************************************************************************************
fatal: [127.0.0.1]: FAILED! => {"changed": true, "cmd": [
"/usr/local/bin/python", "-c", "import psycopg2;
print(psycopg2.__version__)"], "delta": "0:00:00.051150", "end": "2018-12-09
23:33:22.335590", "failed": true, "msg": "non-zero return code", "rc": 1,
"start": "2018-12-09 23:33:22.284440", "stderr": "Traceback (most recent
call last):\n File \"<string>\", line 1, in <module>\nImportError: No
module named psycopg2", "stderr_lines": ["Traceback (most recent call
last):", " File \"<string>\", line 1, in <module>", "ImportError: No
module named psycopg2"], "stdout": "", "stdout_lines": []}
to retry, use: --limit @/Users/bkaplan/.ansible/retry-files/ops-alerta.
retry
PLAY RECAP
************************************************************************************************************************************************************************************************************
127.0.0.1 : ok=3 changed=0 unreachable=0 failed=1
Playbook run took 0 days, 0 hours, 0 minutes, 2 seconds
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/b1ecaad7-e46f-423f-8dd1-db47060985c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.