我最近开始使用Ansible,并试图将其应用于无法访问Internet的环境中。
我已经设法创建了一个使用文件和模板安装Chocolatey的playbook,但目前每次我运行该playbook时,它都会安装Chocolatey。我目前正在使用的任务是:
---
- name: Create C:\temp
win_file:
path: C:\temp
state: directory
- name: Save InstallChocolatey.ps1 file
template:
src: InstallChocolatey.ps1.j2
dest: c:\temp\InstallChocolatey.ps1
- name: Run InstallChocolatey.ps1
win_shell: C:\temp\InstallChocolatey.ps1有没有办法检查巧克力是否已经安装了?使用它,我将能够使用一个块,以及何时避免重复执行这些操作。
感谢大家的任何建议:)
发布于 2021-01-17 17:05:16
您可以添加一个任务来检查choco命令是否就绪。并在choco不可用时执行script InstallChocolatey.ps1。
---
- name: Check if Chocolatey is already installed
win_shell: (Get-Command choco).Path
register: get_command_choco
- name: Create C:\temp
win_file:
path: C:\temp
state: directory
- name: Save InstallChocolatey.ps1 file
template:
src: InstallChocolatey.ps1.j2
dest: c:\temp\InstallChocolatey.ps1
- name: Run InstallChocolatey.ps1
win_shell: C:\temp\InstallChocolatey.ps1
when: not get_command_choco.stderr == ""https://stackoverflow.com/questions/65751640
复制相似问题