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

迪格鲁兹

我必须以用户apache 的身份在多个主机上运行 symfony 清除缓存,该用户在 /etc/passwd 中/sbin/nologin作为 shell。通常我使用以下命令执行此操作: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 运行此任务的最佳方法。

JGK
---
- 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"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何输入用户帐户并从以root用户身份运行的Shell脚本中运行命令?

以root身份运行select shell命令而不给用户sudo权限?

以root用户身份在jenkins中运行shell命令吗?

没有密码以固定命令的根用户身份运行命令?

没有sudo或su命令时如何以其他用户身份运行命令

如何以特定用户身份运行 aws cli 命令?

如何以ubuntu用户身份运行bash命令?

如何以系统用户身份运行bash命令而不授予该用户以任何用户身份运行命令的权限

如何在Shell中为连接的用户打印运行命令?

以另一个没有密码的用户身份运行Shell脚本

Ansible将以什么用户身份运行我的命令?

如何以特定用户身份运行 Ansible 任务

有没有我可以以非root用户身份运行的命令,以查看用户是否可以运行某些sudo命令

如何从shell运行Vim命令?

如何快速运行shell命令?

如何以编程方式从 android studio 运行 cmd/shell 命令?

如何以没有密码的其他用户身份运行脚本?

如何以其他用户身份运行命令

如何以其他用户身份在脚本中运行命令?

在Fedora启动时,如何以其他用户身份运行命令?

如何以另一个用户身份运行交互式命令

在Ansible运行的shell命令中插入变量

如何以根用户身份运行Dolphin?

如何以受限用户身份运行uWSGI?

如何等待用户关闭vim然后在shell脚本中运行命令

如何在Ansible的检查模式下运行Shell命令?

如何在 Ubuntu 中使用 python 以非 root 用户身份运行 root 用户命令

Rails用用户输入运行shell命令

subprocess.Popen没有运行shell命令