使用 become
更改用户的默认 shell 不会给出预期的结果。使用:
- name: Change default shell to zsh
shell: sudo chsh -s $(which zsh) $(whoami)
/etc/passwd
好像:root:x:0:0:root:/root:/bin/bash
ubuntu:x:1000:1000:Ubuntu:/home/ubuntu:/usr/bin/zsh
这是预期的结果,即更改 ubuntu
的默认 shell用户到 zsh
.现在,我宁愿使用 become
:- name: Change default shell to zsh
become: true
shell: chsh -s $(which zsh)
但是后来/etc/passwd
好像:root:x:0:0:root:/root:/usr/bin/zsh
ubuntu:x:1000:1000:Ubuntu:/home/ubuntu:/bin/bash
请注意 zsh
设置为 root
只要。 我在这里想念什么?不是
become: true
加 shell: chsh -s $(which zsh)
与 sudo chsh -s $(which zsh) $(whoami)
相同或 sudo chsh -s $(which zsh)
?如果我添加
$(whoami)
喜欢:- name: Change default shell to zsh
become: true
shell: chsh -s $(which zsh) $(whoami)
我也一样,root
与 zsh
但不是我要更改的用户。
最佳答案
我会使用这样的东西:
- name: Ensure the user 'ubuntu' has a zsh shell.
user:
name: ubuntu
shell: /bin/zsh
state: present
become: yes
关于shell - 使用 "become: true"在 Ansible 不工作的情况下更改默认 shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72319038/