2024-12-17
你们都说我是弱智,其实只有我遵守了当年一起不长大的约定。 --- 《微博》 · 茶褐
Powershell离线安装Nuget
In order to execute the first time, PackageManagement requires an internet connection to download the NuGet package provider. However, if your computer does not have an internet connection and you need to use the NuGet or PowerShellGet provider, you can download them on another computer and copy them to your target computer. Use the following steps to do this:
- Run
Install-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201 -Force
to install the provider from a computer with an internet connection. - After the install, you can find the provider installed in
$env:ProgramFiles\PackageManagement\ProviderAssemblies\<ProviderName>\<ProviderVersion>
or$env:LOCALAPPDATA\PackageManagement\ProviderAssemblies\<ProviderName>\<ProviderVersion>
. - Place the
<ProviderName>
folder, which in this case is the NuGet folder, in the corresponding location on your target computer. If your target computer is a Nano server, you need to runInstall-PackageProvider
from Nano Server to download the correct NuGet binaries. - Restart PowerShell to auto-load the package provider. Alternatively, run
Get-PackageProvider -ListAvailable
to list all the package providers available on the computer. Then useImport-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201
to import the provider to the current Windows PowerShell session.
ansible deleget_to
在Ansible中,delegate_to
是一个关键字,用于将当前任务的执行委托给其他主机,而不是默认的目标主机。
作用
当你使用 delegate_to: localhost
时,意味着这个任务会在控制节点(运行 Ansible 的机器)上执行,而不是在默认目标主机(inventory 中指定的主机)上。
示例解释
- name: Store token to hostvars
ansible.builtin.set_fact:
join_command: "{{ token_create_output.stdout }}"
delegate_to: localhost
become: true
-
delegate_to: localhost
:- 任务会在控制节点上执行,而不是目标主机上。
- 控制节点是运行
ansible-playbook
命令的机器。
-
ansible.builtin.set_fact
:- 这里设置了一个变量
join_command
,其值来自于token_create_output.stdout
。
- 这里设置了一个变量
-
become: true
:- 提升权限(类似于
sudo
),确保任务在控制节点上以高权限执行。
- 提升权限(类似于
适用场景
使用 delegate_to: localhost
的典型场景包括:
- 需要在控制节点上执行某个任务,如生成密钥、令牌或临时文件。
- 任务需要与其他工具交互,而这些工具只在控制节点上可用。
- 收集数据或状态,然后分发给其他主机。
总结
delegate_to
使你可以在指定的主机上执行任务,而不是在当前的目标主机上。例如,delegate_to: localhost
让任务在 Ansible 控制节点上执行,而不是在 inventory 中定义的远程主机上。