doujin4031 2016-08-02 15:58
浏览 156
已采纳

使用ansible抛出错误来运行php脚本

I am trying to run a php script on a remote server using ansible. Running the script with the ansible user (which ansible uses to login to the server) works perfectly. The ansible task however fails when there are include statements in my php script.

My php script lays in

/srv/project

it tries to include

includes/someLibrary.php
Everything works fine when running the script as any user with the correct access rights but when running it via an ansible task
- name: run script
  shell: 'php /srv/project/script.php'

it fails with:

failed to open stream: No such file or directory in /srv/project/includes/someLibrary.php

Running a very basic php script works nicely though.

  • 写回答

2条回答 默认 最新

  • douchenbiao0916 2016-08-03 08:03
    关注

    I just found the solution to the problem. The problem was that when I executed the script by hand, I connected to the server and cd'd into the /srv/project directory before calling php script.php PHPs include in this case looks in the current directory for the files I want to include. When ansible connects to the server it did not change the directory thus producing the no such file or directory error. The solution to this is simple as the shell module takes a chdir as an argument to change the directory to the one specified before running the command.

    My ansible task now looks as follows:

    - name: run script
      shell: 'php /srv/project/script.php'
      args:
        chdir: '/srv/project'
    

    Thanks everyone for your help!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记