首页 文章

如何使用ansible playbook在sudo模式下运行命令?

提问于
浏览
0

我正在尝试使用我的ansible playbook运行“文件夹创建”命令 . (代码如下)

创建需要sudo登录才能执行 .

我按如下方式运行剧本:

ansible-playbook myfile.yml --ask-pass

这会提示输入远程计算机的用户帐户密码 . ssh连接已 Build ,但由于未获取超级用户密码,命令因权限被拒绝而失败 .

我该如何解决我的问题?

hosts: GSP
 tasks:
   - name: "make build directory"
     command: mkdir -p /home/build/
     become: true
     become_user: root
   - name: "change permissions on the directory"
     command: chmod 777 -R /home/
     become: true
     become_user: root

2 回答

  • 3

    还有 --ask-become-pass 开关 ansible-playbook cli来查询用户的sudo密码 .

  • 1

    您可以添加ansible_become_pass变量以指定playbook中的成为密码 .

    更多细节可以在这里找到:http://docs.ansible.com/ansible/latest/become.html

相关问题