lorin / ansiblebook Goto Github PK
View Code? Open in Web Editor NEWCode samples from the book "Ansible: Up and Running"
Home Page: http://ansiblebook.com
Code samples from the book "Ansible: Up and Running"
Home Page: http://ansiblebook.com
Cloned ch06 playbook and ran the playbook and keep getting this output for the manage.py tasks.
failed: [web] => (item=syncdb) => {"cmd": "./manage.py syncdb --noinput",
"failed": true, "item": "syncdb", "msg": "[Errno 13] Permission denied", "rc": 13}
failed: [web] => (item=migrate) => {"cmd": "./manage.py migrate --noinput",
"failed": true, "item": "migrate", "msg": "[Errno 13] Permission denied", "rc": 13}
failed: [web] => (item=collectstatic) => {"cmd": "./manage.py collectstatic --noinput",
"failed": true, "item": "collectstatic", "msg": "[Errno 13] Permission denied", "rc": 13}
I've gotten manage.py to run by vagrant ssh
, making it executable with chmod +x manage.py
and changing the #!/usr/bin/env
on the top of the file to the virtual env. How to get around this with ansible?
TASK: [check out the repository on the host] **********************************
<127.0.0.1> ESTABLISH CONNECTION FOR USER: vagrant
<127.0.0.1> REMOTE_MODULE git repo= dest=/home/vagrant/mezzanine-example/project accept_hostkey=yes
<127.0.0.1> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ForwardAgent=yes -o ControlPath="/home/shamim/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o Port=2222 -o IdentityFile=".vagrant/machines/default/virtualbox/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 $HOME/.ansible/tmp/ansible-tmp-1451338151.66-149952547135034 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1451338151.66-149952547135034 && echo $HOME/.ansible/tmp/ansible-tmp-1451338151.66-149952547135034'
<127.0.0.1> PUT /tmp/tmp7x4cMC TO /home/vagrant/.ansible/tmp/ansible-tmp-1451338151.66-149952547135034/git
<127.0.0.1> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ForwardAgent=yes -o ControlPath="/home/shamim/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o Port=2222 -o IdentityFile=".vagrant/machines/default/virtualbox/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 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1451338151.66-149952547135034/git; rm -rf /home/vagrant/.ansible/tmp/ansible-tmp-1451338151.66-149952547135034/ >/dev/null 2>&1'
failed: [web] => {"cmd": "/usr/bin/git ls-remote '' -h refs/heads/HEAD", "failed": true, "rc": 128}
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
msg: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
FATAL: all hosts have already failed -- aborting
Working through chapter 6 running ansible-playbook mezzanine.yml
fails at this point
$ ansible-playbook mezzanine.yml
PLAY [Deploy mezzanine] *******************************************************
GATHERING FACTS ***************************************************************
ok: [web]
...
TASK: [create a user] *********************************************************
failed: [web] => {"failed": true}
msg: unable to connect to database: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
FATAL: all hosts have already failed -- aborting
debugging Vagrant host
vagrant@vagrant-ubuntu-trusty-64:~/mezzanine-example$ psql
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_PAPER = "de_DE.UTF-8",
LC_ADDRESS = "de_DE.UTF-8",
LC_MONETARY = "de_DE.UTF-8",
LC_NUMERIC = "de_DE.UTF-8",
LC_TELEPHONE = "de_DE.UTF-8",
LC_IDENTIFICATION = "de_DE.UTF-8",
LC_MEASUREMENT = "de_DE.UTF-8",
LC_TIME = "de_DE.UTF-8",
LC_NAME = "de_DE.UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
locales of my control machine
$ locale
LANG=en_GB.UTF-8
LANGUAGE=en_GB:en
LC_CTYPE="en_GB.UTF-8"
LC_NUMERIC=de_DE.UTF-8
LC_TIME=de_DE.UTF-8
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY=de_DE.UTF-8
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER=de_DE.UTF-8
LC_NAME=de_DE.UTF-8
LC_ADDRESS=de_DE.UTF-8
LC_TELEPHONE=de_DE.UTF-8
LC_MEASUREMENT=de_DE.UTF-8
LC_IDENTIFICATION=de_DE.UTF-8
LC_ALL=
Validating a running postgres service
vagrant@vagrant-ubuntu-trusty-64:~$ sudo service postgresql start
* No PostgreSQL clusters exist; see "man pg_createcluster"
Adding missing locales to remote machine
vagrant@vagrant-ubuntu-trusty-64:~$ sudo locale-gen de_DE.utf8
Generating locales...
de_DE.UTF-8... done
Generation complete.
vagrant@vagrant-ubuntu-trusty-64:~$ sudo locale-gen en_GB.UTF-8
Generating locales...
en_GB.UTF-8... done
Generation complete.
Following the advice from AskUbuntu
vagrant@vagrant-ubuntu-trusty-64:~$ sudo pg_createcluster 9.3 main --start
Creating new cluster 9.3/main ...
config /etc/postgresql/9.3/main
data /var/lib/postgresql/9.3/main
locale en_US.UTF-8
port 5432
vagrant@vagrant-ubuntu-trusty-64:~$ sudo -iu postgres
postgres@vagrant-ubuntu-trusty-64:~$ psql
psql (9.3.9)
Type "help" for help.
postgres=#
Now Ansible tasks for Postgres succeed
TASK: [create a user] *********************************************************
changed: [web]
TASK: [create the database] ***************************************************
changed: [web]
Just noticed I even added option module_lang
to ansible.cfg
hostfile = hosts
remote_user = vagrant
private_key_file = .vagrant/machines/default/virtualbox/private_key
host_key_checking = False
module_lang = en_US.utf8
[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o ForwardAgent=yes
The problem itself is well known to people used to work with Postgresql and/or Ansible/Vagrant. To me it is not clear how to fix the playbook and how my machine locales affect the problem. I hope the book author can resolve this. BTW - it is an awesome book.
Environment
Vagrant - Ubuntu/Trusty64
$ vagrant box update
==> default: Checking for updates to 'ubuntu/trusty64'
default: Latest installed version: 20150911.0.0
default: Version constraints:
default: Provider: virtualbox
==> default: Updating 'ubuntu/trusty64' with provider 'virtualbox' from version
==> default: '20150911.0.0' to '20150916.0.0'...
==> default: Loading metadata for box 'https://atlas.hashicorp.com/ubuntu/trusty64'
==> default: Adding box 'ubuntu/trusty64' (v20150916.0.0) for provider: virtualbox
default: Downloading: https://atlas.hashicorp.com/ubuntu/boxes/trusty64/versions/20150916.0.0/providers/virtualbox.box
==> default: Successfully added box 'ubuntu/trusty64' (v20150916.0.0) for 'virtualbox'!
Ansible
$ ansible --version
ansible 1.9.3
References
TASK: [sync the database, apply migrations, collect static content] ***********
failed: [web] => (item=syncdb) => {"cmd": "python manage.py syncdb --noinput", "failed": true, "item": "syncdb", "path": "/home/vagrant/mezzanine-example/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games", "state": "absent", "syspath": ["/home/vagrant/.ansible/tmp/ansible-tmp-1453320377.52-217648168657076", "/usr/lib/python2.7", "/usr/lib/python2.7/plat-x86_64-linux-gnu", "/usr/lib/python2.7/lib-tk", "/usr/lib/python2.7/lib-old", "/usr/lib/python2.7/lib-dynload", "/usr/local/lib/python2.7/dist-packages", "/usr/lib/python2.7/dist-packages"]}
msg:
:stderr: Traceback (most recent call last):
File "manage.py", line 28, in <module>
execute_from_command_line(sys.argv)
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/core/management/base.py", line 284, in execute
self.validate()
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/core/management/base.py", line 310, in validate
num_errors = get_validation_errors(s, app)
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/core/management/validation.py", line 34, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/db/models/loading.py", line 196, in get_app_errors
self._populate()
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in _populate
self.load_app(app_name)
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app
models = import_module('%s.models' % app_name)
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/compressor/models.py", line 1, in <module>
from compressor.conf import CompressorConf # noqa
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/compressor/conf.py", line 5, in <module>
from django.template.utils import InvalidTemplateEngineError
ImportError: No module named utils
failed: [web] => (item=migrate) => {"cmd": "python manage.py migrate --noinput", "failed": true, "item": "migrate", "path": "/home/vagrant/mezzanine-example/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games", "state": "absent", "syspath": ["/home/vagrant/.ansible/tmp/ansible-tmp-1453320378.13-242683810168516", "/usr/lib/python2.7", "/usr/lib/python2.7/plat-x86_64-linux-gnu", "/usr/lib/python2.7/lib-tk", "/usr/lib/python2.7/lib-old", "/usr/lib/python2.7/lib-dynload", "/usr/local/lib/python2.7/dist-packages", "/usr/lib/python2.7/dist-packages"]}
msg:
:stderr: Traceback (most recent call last):
File "manage.py", line 28, in <module>
execute_from_command_line(sys.argv)
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/core/management/base.py", line 284, in execute
self.validate()
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/core/management/base.py", line 310, in validate
num_errors = get_validation_errors(s, app)
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/core/management/validation.py", line 34, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/db/models/loading.py", line 196, in get_app_errors
self._populate()
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in _populate
self.load_app(app_name)
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app
models = import_module('%s.models' % app_name)
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/compressor/models.py", line 1, in <module>
from compressor.conf import CompressorConf # noqa
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/compressor/conf.py", line 5, in <module>
from django.template.utils import InvalidTemplateEngineError
ImportError: No module named utils
failed: [web] => (item=collectstatic) => {"cmd": "python manage.py collectstatic --noinput", "failed": true, "item": "collectstatic", "path": "/home/vagrant/mezzanine-example/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games", "state": "absent", "syspath": ["/home/vagrant/.ansible/tmp/ansible-tmp-1453320378.75-239046207808436", "/usr/lib/python2.7", "/usr/lib/python2.7/plat-x86_64-linux-gnu", "/usr/lib/python2.7/lib-tk", "/usr/lib/python2.7/lib-old", "/usr/lib/python2.7/lib-dynload", "/usr/local/lib/python2.7/dist-packages", "/usr/lib/python2.7/dist-packages"]}
I am using amazon ec2 instances for deploying, unlike the vagrant.
so, i have't included domain names. and i configured the server name as localhost.
but now when i point to my instance i am getting "400 bad gateway"
The mezzanine.yml palybook fails when executing the "install Python requirements globally via pip" task for virtualenvwrapper with the following error message:
failed: [web] (item=virtualenvwrapper) => {"changed": false, "cmd": "/usr/local/bin/pip2 install -U virtualenvwrapper", "item": "virtualenvwrapper", "msg": "stdout: Collecting virtualenvwrapper\n Downloading https://files.pythonhosted.org/packages/2b/8c/3192e10913ad945c0f0fcb17e9b2679434a28ad58ee31ce0104cba3b1154/virtualenvwrapper-4.8.2-py2.py3-none-any.whl\nCollecting virtualenv-clone (from virtualenvwrapper)\n Downloading https://files.pythonhosted.org/packages/6d/c2/dccb5ccf599e0c5d1eea6acbd058af7a71384f9740179db67a9182a24798/virtualenv_clone-0.3.0-py2.py3-none-any.whl\nCollecting stevedore (from virtualenvwrapper)\n Downloading https://files.pythonhosted.org/packages/17/6b/3b7d6d08b2ab3e5ef09e01c9f7b3b590ee135f289bb94553419e40922c25/stevedore-1.28.0-py2.py3-none-any.whl\nRequirement not upgraded as not directly required: virtualenv in /usr/local/lib/python2.7/dist-packages (from virtualenvwrapper) (15.2.0)\nCollecting six>=1.10.0 (from stevedore->virtualenvwrapper)\n Downloading https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl\nCollecting pbr!=2.1.0,>=2.0.0 (from stevedore->virtualenvwrapper)\n Downloading https://files.pythonhosted.org/packages/e1/ba/f95e3ec83f93919b1437028e989cf3fa5ff4f5cae4a1f62255f71deddb5b/pbr-4.0.2-py2.py3-none-any.whl (98kB)\nInstalling collected packages: virtualenv-clone, six, pbr, stevedore, virtualenvwrapper\n Found existing installation: six 1.5.2\n\n:stderr: /usr/local/lib/python2.7/dist-packages/pip/vendor/urllib3/util/ssl.py:339: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n SNIMissingWarning\n/usr/local/lib/python2.7/dist-packages/pip/vendor/urllib3/util/ssl.py:137: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n InsecurePlatformWarning\n/usr/local/lib/python2.7/dist-packages/pip/vendor/urllib3/util/ssl.py:137: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings\n InsecurePlatformWarning\ncheetah 2.4.4 requires Markdown>=2.0.1, which is not installed.\nlaunchpadlib 1.10.2 requires testresources, which is not installed.\nCannot uninstall 'six'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.\n"}
page 57 has two same lines -- "db_primary_port=5432",please modify~
Lorin,
Sorry to abuse the Github new issue function but I've submitted a whole bunch of issues to the O'Reilly errata page for this book. It doesn't appear you pay much attention to that page. Could you please take a look at it. (I don't use Twitter or other social networks so I can't contact you using them.)
I used Ansible version 1.9.3. It was running normally until it ran to the django_manage and these error appears:
Can you please show me how to fixed it.
failed: [web] => {"cmd": "python manage.py createdb --noinput --nodata", "failed": true, "path": "/home/vagrant/mezzanine-example/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games", "state": "absent", "syspath": ["/home/vagrant/.ansible/tmp/ansible-tmp-1454896456.86-205844376608852", "/usr/lib/python2.7", "/usr/lib/python2.7/plat-x86_64-linux-gnu", "/usr/lib/python2.7/lib-tk", "/usr/lib/python2.7/lib-old", "/usr/lib/python2.7/lib-dynload", "/usr/local/lib/python2.7/dist-packages", "/usr/lib/python2.7/dist-packages"]}
msg:
:stderr: Traceback (most recent call last):
File "manage.py", line 28, in
execute_from_command_line(sys.argv)
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/core/management/init.py", line 399, in execute_from_command_line
utility.execute()
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/core/management/init.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/core/management/init.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/core/management/init.py", line 75, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
import(name)
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/mezzanine/core/management/init.py", line 16, in
from mezzanine.utils.tests import copy_test_to_media
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/mezzanine/utils/tests.py", line 12, in
from mezzanine.conf import settings
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/mezzanine/conf/init.py", line 202, in
module = import_module(app)
File "/home/vagrant/mezzanine-example/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
import(name)
ImportError: No module named apps
FATAL: all hosts have already failed -- aborting
On my OSX 10.10 machine i had a problem with the git step in the mezzanine config. I would get public key denied and with debugging was able to show that agent forwarding was not working. (I had ensured that the ssh-agent was running and that my github key was ssh-add'd to the agent).
Solution for me was to add to the ansible.cfg file so that it looks as follows on the ssh_args line:
[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o ForwardAgent=yes -o UserKnownHostsFile=/dev/null
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.