Ubuntu ansible:sudo-iu用于交互式shell
当需要交互式shell时,是否有更好的方法为ansible中的每个命令编写Ubuntu ansible:sudo-iu用于交互式shell,ubuntu,automation,ansible,Ubuntu,Automation,Ansible,当需要交互式shell时,是否有更好的方法为ansible中的每个命令编写sudo-iu username-command- 例如: - name: Install nodejs {{ node_version }} shell: sudo -iu {{ nvm_user }} nvm install {{ node_version }} && sudo -iu {{ nvm_user }} nvm alias default {{ node_version }} whe
sudo-iu username-command-
例如:
- name: Install nodejs {{ node_version }}
shell: sudo -iu {{ nvm_user }} nvm install {{ node_version }} && sudo -iu {{ nvm_user }} nvm alias default {{ node_version }}
when: not np.stat.isdir is defined
您可以请求Ansible为您创建sudo,并直接调用
bash
,如下所示:
- name: Install nodejs {{ node_version }}
sudo_user: "{{ nvm_user }}"
sudo: true
shell: bash -lc 'nvm install {{ node_version }} && nvm alias default {{ node_version }}'
when: np.stat.isdir is not defined
请注意:
不会被插值Install nodejs{{node_version}}
- 您可以用更自然的
替换x未定义
x未定义
- 您可能希望在以下时间添加“
以控制命令的更改状态,因此您的TAK是幂等的(但似乎只有在某个目录不存在时才运行任务,因此我猜只能跳过任务状态/changed\u:
)更改
bash-lc
是的,完全忘记了这一点:)。bash-lc
对我不起作用,但bash-lci
起作用。