Ansible:如何以没有shell的用户身份运行命令

Ansible:如何以没有shell的用户身份运行命令,ansible,Ansible,我必须以用户apache的身份在多台主机上运行symfony clear缓存,而apache在/etc/passwd中以shell的形式运行了/sbin/nologin。通常,我使用以下命令执行此操作:sudo su-apache-s/bin/bash-c“php/var/www/html/api.sellsecure.com/bin/console cache:clear--env=prod” 目前,我的剧本如下所示: --- - name: "test" hosts:

我必须以用户apache的身份在多台主机上运行symfony clear缓存,而apache在/etc/passwd中以shell的形式运行了/sbin/nologin。通常,我使用以下命令执行此操作:
sudo su-apache-s/bin/bash-c“php/var/www/html/api.sellsecure.com/bin/console cache:clear--env=prod”

目前,我的剧本如下所示:

    ---
    - name: "test"
    hosts: app-servers
    gather_facts: yes
    become: yes
    tasks:
      - name: "Clear symfony cache"
        command: sudo su - apache -s /bin/bash -c "php /var/www/html/api.sellsecure.com/bin/console cache:clear --env=prod"
但在跑步过程中,我收到了一个警告:

[WARNING]: Consider using 'become', 'become_method', and 'become_user' rather than running sudo
我试过几种组合,但都没能成功


我是ansible noobie,我想了解使用ansible运行此任务的最佳方式。

该警告将在您通过命令或shell模块使用sudo时出现。这只是信息性的,不会影响尝试执行的命令,我理解,但该警告使我认为我没有使用正确的方法执行任务。使用
been:yes
sudo
是多余的。我将尝试删除<代码> SUDO 命令的一部分,并测试它运行。但是现在我得到一个警告:<代码> [警告]:考虑使用“变成”、“BeMeMyApple”和“BeMeMuxAuthor”,而不是运行SU/<代码>,当您通过命令或shell模块使用SUDO时,警告会发生。这只是信息性的,不会影响尝试执行的命令,我理解,但该警告使我认为我没有使用正确的方法执行任务。使用
been:yes
sudo
是多余的。我将尝试删除<代码> SUDO 命令的一部分,并测试它运行。但现在我得到一个警告:<代码> [警告]:考虑使用“变成”、“BeMeMeAy方法”和“BeMeMuxAuthor”,而不是运行SU/< > >
---
- name: "test"
hosts: app-servers
gather_facts: yes
become: yes
become_user: apache
become_flags: '-s /bin/bash'
tasks:
  - name: "Clear symfony cache"
    command: "php /var/www/html/api.sellsecure.com/bin/console cache:clear --env=prod"