2

Scope of problem

  • Rails 4.2.11
  • Ansible 2.1.1.0
  • Ubuntu 14
  • Ubuntu user: deploy

I have Rails app which I deploy to Ubuntu server by Ansible script.

I have problem of understanding why Rails app create log files with root permissions when Ansible script execute rake tasks.

enter image description here

In my example it's running rake db:migrate but also same behaviour with rake assets:precompile

You can see by photo below that application is deployed via user 'deploy' but after run of rake task it create 2 log files with root permission. After restart of web server it crash with permission denied error, so I need manually change ownership to deploy:deploy

enter image description here

Structure of Rails logger is also looks suspicious. You can check @dev=IO:<STDERR> value. I've checked in another project and there I can see something like @dev=#<File:/var/www/.../log/production.log>

enter image description here

I tried to explore source code of ror4 but so far no luck to understand from there what is happening. Only idea is could be that Rails raise exception when create log file and STDERR become output

Please help if you have similar problem or can point out where I can look to.

Vadim Eremeev
  • 470
  • 5
  • 16

1 Answers1

0

The rake script runs as root User.

To answer the question you must add the complete ansible script or the bundle script if you manually add a "sudo" commands or something unusual.

There are different possible positions to define the user in ansible.

Read the become section of the ansible documentation https://docs.ansible.com/ansible/latest/user_guide/become.html

Or give a try with

- name: Run db:migrate
  shell: ... rake cmd ...
  become: yes
  become_user: deploy
  become_method: su

Change the become_method to your needs e.g become_flags: '-s /bin/sh' or sudo

Octeny
  • 499
  • 5
  • 7