我正在尝试通过Ansible安装NVS,但没有太多的运气。在instructions on the repo之后,我似乎应该首先确保设置NVS_HOME环境变量,然后克隆存储库,然后运行安装程序。
因此,下面是我如何在我的剧本中设置它的:
- hosts: all
remote_user: "{{ new_user }}"
gather_facts: true
environment:
NVS_HOME: ~/.nvs
tasks:
- name: See if NVS is already installed
lineinfile:
path: ~/.zshrc
line: export NVS_HOME="$HOME/.nvs"
state: present
check_mode: true
register: zshrc
- name: Clone the NVS repo
git:
repo: https://github.com/jasongin/nvs
dest: "$NVS_HOME"
version: v1.6.0
ignore_errors: true
when: (zshrc is changed) or (zshrc is failed)
- name: Ensure NVS is installed
shell: ". \"$NVS_HOME/nvs.sh\" install"
when: (zshrc is changed) or (zshrc is failed)这样,它首先检查是否安装了NVS,如果安装了NVS,则不会处理以下两个任务。克隆不是问题,因此剩下安装的最后一步。
当Ansible到达最后一个任务时,它会输出一个错误。下面是Ansible调试器的任务结果:
[localhost] TASK: Ensure NVS is installed (debug)> p result._result
{'_ansible_no_log': False,
'_ansible_parsed': True,
'changed': True,
'cmd': '. "$NVS_HOME/nvs.sh" install',
'delta': '0:00:00.002482',
'end': '2020-11-24 12:53:52.983307',
'failed': True,
'invocation': {'module_args': {'_raw_params': '. "$NVS_HOME/nvs.sh" install',
'_uses_shell': True,
'argv': None,
'chdir': None,
'creates': None,
'executable': None,
'removes': None,
'stdin': None,
'stdin_add_newline': True,
'strip_empty_ends': True,
'warn': True}},
'msg': 'non-zero return code',
'rc': 127,
'start': '2020-11-24 12:53:52.980825',
'stderr': "/bin/sh: 1: .: Can't open ~/.nvs/nvs.sh",
'stderr_lines': ["/bin/sh: 1: .: Can't open ~/.nvs/nvs.sh"],
'stdout': '',
'stdout_lines': []}所以我不知道现在该怎么做。有什么想法吗?
发布于 2020-11-24 22:49:36
问题出在你的dest: "$NVS_HOME" in git任务上。我建议声明一个变量并在您的环境和任务中使用它
- hosts: all
remote_user: "{{ new_user }}"
gather_facts: true
vars:
nvs_home: "~/.nvs"
environment:
NVS_HOME: "{{ nvs_home }}"在你的git任务中:
- name: Clone the NVS repo
git:
repo: https://github.com/jasongin/nvs
dest: "{{ nvs_home }}"
version: v1.6.0
ignore_errors: true
when: (zshrc is changed) or (zshrc is failed)https://stackoverflow.com/questions/64988495
复制相似问题