在Ansible中,可以使用become选项来指定在运行playbook时切换到其他用户身份。下面是一个示例代码解决方法:
---
- name: Run playbook without root user
hosts: all
become: yes
become_user: other_user
tasks:
- name: Example task
shell: echo "Hello World!"
在上面的示例中,become设置为yes表示在运行任务时切换用户身份。become_user指定了要切换到的用户身份。在这个例子中,任务会以other_user的身份运行。
你可以将上面的示例保存为一个名为playbook.yml的文件,并使用以下命令运行:
ansible-playbook playbook.yml
这样,Ansible就会以other_user的身份运行playbook中的任务。
上一篇:ansible部署kafka
下一篇:Ansible不再起作用