首页 文章

如何实现sudo su - root并在ansible中运行所有命令

提问于
浏览
0

我们无法将ansible playbook连接切换为root id . 例如 . “sudo su - ”然后执行权限命令 . 请检查和建议正确的方法 . 它使用原始模块正常工作但在剧本中失败

下面提到的命令在命令提示符下正常工作......如何通过playbook配置相同的命令 .

ansible 13.127.209.209 -e "ansible_user=ec2-user" --private-key ~/Downloads/cc-shaadi-test.pem -m shell -a "sudo su - root ; cd /data/xyz/ ; ./start-xyz.sh" -vvvv

Playbook Sample - name: Start 18 Service shell: sudo su - root ; cd /data/xyz/ ; ./xyz.sh

1 回答

  • 0

    您应该使用 become_user 以另一个用户身份运行脚本,同时shell使用 chdir 支持更改文件夹

    如:

    - name: Start 18 Service
        hosts: yourhost
        become: true
        become_user: root 
        shell: "./xyz.sh"
        args:
          chdir: /data/xyz/
    

相关问题