我正在尝试将当前用户添加到系统中的某个组,然后执行需要该组权限的命令。我的剧本是这样的:
- name: Add this user to RVM group
sudo: true
user: state=present name=vagrant append=yes groups=rvm group=rvm
- name: Install Ruby 1.9.3
command: rvm install ruby-1.9.3-p448 creates=/usr/local/rvm/bin/ruby-1.9.3-p448
问题是所有这些都发生在同一个 shell 中。 vagrant 的 shell 尚未使用新组进行更新。 Ansible 中是否有一种干净的方法来刷新用户当前的组?我想我需要让它重新连接或打开一个新的外壳。
但是我尝试打开一个新的外壳,它只是挂起:
- name: Open a new shell for the new groups
shell: bash
当然它会挂起:进程永远不会退出!
与 newgrp 相同
- name: Refresh the groups
shell: newgrp
因为它基本上做同样的事情。
有任何想法吗?
阅读手册。
这里的解决方案是对“命令”或“shell”模块使用“可执行”参数。
所以我尝试使用命令模块,如下所示:
- name: install ruby 1.9.3
command: rvm install ruby-1.9.3-p448 executable=/bin/bash creates=/usr/local/rvm/bin/ruby-1.9.3-p448
ignore_error: true
但剧本却无限期地搁置了。这manual http://www.ansibleworks.com/docs/modules.html#command states:
如果您想通过 shell 运行命令(假设您正在使用 、| 等),您实际上需要 shell 模块。命令模块更加安全,因为它不受用户的影响
环境。
所以我尝试使用 shell 模块:
- name: install ruby 1.9.3
shell: rvm install ruby-1.9.3-p448 executable=/bin/bash creates=/usr/local/rvm/bin/ruby-1.9.3-p448
ignore_error: true
它有效!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)