通过ansible composer模块运行composer dump-env产品

时间:2019-07-16 14:57:15

标签: symfony ansible composer-php

我无法使用ansible作曲器模块运行symfony flex命令composer dump-env prod。我想知道是否有可能?我的任务看起来像这样:

- name: Composer dump env for production
  composer:
      command: dump-env
      working_dir: "{{ app_composer_package_dir }}"
      arguments: prod
  become_user: "{{app_apache_user}}"
  become: yes

我得到的错误是:

  

“ stderr”:“ \ n
  \ n [Symfony \ Component \ Console \ Exception \ CommandNotFoundException]   \ n没有定义命令\“ dump-env \”。
  \ n

可记录的详细日志:

fatal: [testhost.com]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "apcu_autoloader": false,
            "arguments": "prod",
            "classmap_authoritative": false,
            "command": "dump-env",
            "executable": null,
            "global_command": false,
            "ignore_platform_reqs": false,
            "no_dev": true,
            "no_plugins": false,
            "no_scripts": false,
            "optimize_autoloader": true,
            "prefer_dist": false,
            "prefer_source": false,
            "working_dir": "/var/www/source"
        }
    },
    "msg": "[Symfony\\Component\\Console\\Exception\\CommandNotFoundException] Command \"dump-env\" is not defined. help [--xml] [--format FORMAT] [--raw] [--] [<command_name>]"
}
                                                          ",

我尝试使用ansible command模块直接运行命令,但出现相同的错误。

但是,我可以通过切换到远程(centos)实例来运行命令:

sudo -u apache composer dump-env prod
  

将“ symfony / symfony”中列出的软件包限制为“ 4.3。*”
  成功将.env文件转储到.env.local.php

1 个答案:

答案 0 :(得分:0)

到目前为止,我无法使用ansible作曲器模块运行composer dump-env prod命令。但是,以下使用ansible命令模块的任务成功运行,例如

- name: Composer dump env for production
  command: "{{composer_install_path}}  --working-dir={{ app_composer_package_dir }} dump-env prod"
  become_user: "{{app_apache_user}}"
  become: yes

翻译成sth:

sudo -u apache /usr/local/bin/composer --working-dir=/var/www/source dump-env prod