我有一个有趣的剧本,它使用become
来使用来获得远程主机上的root访问权限
become: yes
我还有一些 pre_tasks ,它们必须在以前的可运行主机上运行本地命令。
如何强制使用默认用户(运行ansible-playbook
的用户)执行本地任务?
这是我的剧本(它是要作为默认用户执行local copy操作作为前置任务)
---
- hosts: all
vars:
proprietary_files: "/some/files/not/managed/by/vcs"
filesToWorkOnLater: "config_files"
pre_tasks:
- name: "Copy from {{proprietary_files}} to {{filesToWorkOnLater}}"
local_action:
module: copy
src: "{{proprietary_files}}/"
dest: "{{filesToWorkOnLater}}/"
become: yes
roles:
...
...
此刻,我从本地计算机收到投诉
sudo: a password is required
答案 0 :(得分:1)
使用command
和delegate_to
和become: no
代替local_action
可以做到:
---
- hosts: all
vars:
proprietary_files: "/some/files/not/managed/by/vcs"
filesToWorkOnLater: "config_files"
pre_tasks:
- name: "Copy from {{proprietary_files}} to {{filesToWorkOnLater}}"
command: cp -r {{proprietary_files}}/ {{filesToWorkOnLater}}/
delegate_to: localhost
become: no
become: yes
roles:
...
...