我可以 ssh 到远程主机并执行source /home/username/.bashrc
- 一切正常。
但是如果我这样做:
- name: source bashrc
sudo: no
action: command source /home/username/.bashrc
I get:
failed: [hostname] => {"cmd": ["source", "/home/username/.bashrc"], "failed": true, "rc": 2}
msg: [Errno 2] No such file or directory
我不知道我做错了什么......
您有两种选择将源代码与 ansible 一起使用。一种是使用“shell:”命令和 /bin/sh (ansible 默认值)。 “源”称为“源”。在 /bin/sh 中。所以你的命令是:
- name: source bashrc
sudo: no
shell: . /home/username/.bashrc && [the actual command you want run]
请注意,您必须在获取 .bashrc b/c 之后运行命令,每个 ssh 会话都是不同的 - 每个 ansible 命令都在单独的 ssh 事务中运行。
您的第二个选择是强制 Ansible shell 使用 bash,然后您可以使用“source”命令:
- name: source bashrc
sudo: no
shell: source /home/username/.bashrc && [the actual command you want run]
args:
executable: /bin/bash
最后,我要指出的是,如果您使用的是 Ubuntu 或类似系统,您可能想要实际获取“/etc/profile”,这更完整地模拟本地登录。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)