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 计算二重积分∫∫e^(x+y)dxdy,其中0≤x≤1,0≤y≤1,试分别用复合辛普森公式(取n=4)以及高斯求积公式(取n=4)计算积分 给出matlab程序
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的