首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过Ansible安装NVS

如何通过Ansible安装NVS
EN

Stack Overflow用户
提问于 2020-11-24 22:25:23
回答 1查看 30关注 0票数 1

我正在尝试通过Ansible安装NVS,但没有太多的运气。在instructions on the repo之后,我似乎应该首先确保设置NVS_HOME环境变量,然后克隆存储库,然后运行安装程序。

因此,下面是我如何在我的剧本中设置它的:

代码语言:javascript
复制
- 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调试器的任务结果:

代码语言:javascript
复制
[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': []}

所以我不知道现在该怎么做。有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2020-11-24 22:49:36

问题出在你的dest: "$NVS_HOME" in git任务上。我建议声明一个变量并在您的环境和任务中使用它

代码语言:javascript
复制
- hosts: all
  remote_user: "{{ new_user }}"
  gather_facts: true
  vars:
      nvs_home: "~/.nvs"
  environment:
     NVS_HOME: "{{ nvs_home }}"

在你的git任务中:

代码语言:javascript
复制
- 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)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64988495

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档