通过ec2(请求密码)运行systemd作为默认用户的服务

我正在尝试使用以下Ansible脚本(playbook的一部分)来通过systemd为EC2(微)实例上的rails应用程序运行独angular兽:

 --- - name: restart unicorn command: psql -h {{ db_host }} -U {{ db_user }} -d {{ db }} -c "SELECT true FROM pg_tables WHERE tablename = 'order_cycles';" register: table_exists ignore_errors: yes sudo: yes sudo_user: "{{ unicorn_user }}" notify: restart unicorn step 2 #TODO make sure both of these things run as one handler. - name: restart unicorn step 2 service: name: unicorn_{{ app }} state: restarted when: table_exists.stderr.find('does not exist') == -1 # If unicorn isn't actually started yet we probably need this: notify: start unicorn - name: start unicorn service: name: unicorn_{{ app }} state: started 

在剧本中configuration的用户是ubuntu的默认(EC2)用户,我在那里打Interactive authentication required错误,所以我只是试图直接在部署到服务器的命令行进行故障排除,并已经到来这个路障。

我可以运行它作为sudo:

 $ sudo systemctl start unicorn_myapp.service 

直接通过服务器的命令行,或通过使用Ansible的原始方法,成功。

但是接下来由用户ubuntu运行的rails服务器无法访问它(至less这是我正在探索.sock failed (111: Connection refused原因的一个途径.sock failed (111: Connection refused error)。

如果我没有使用sudo运行它,则需要input密码,但据我所知,EC2 ubuntu用户在没有密码的情况下运行。

我知道一个解决方法可能是创build一个新的用户密码和运行轨道和systemctl /独angular兽作为该用户,但我不认为这是这个问题的实际答案,更是如此,因为剧本的开发人员最近删除了user_password从安全的angular度出发,

如果我能弄清楚如何以非root用户的身份运行systemd ,也许我可以想出如何使Ansible成功。

当然,我从一开始就错误地接近它也不是不可能的,因为我对这个场景所涉及的几乎所有东西都是相当新的。