Knife ssh 到奇数主机

发布于 2025-01-15 09:04:21 字数 182 浏览 2 评论 0原文

有没有办法可以 ssh 到奇数主机?

这有效:

# knife ssh "webhost1*" "chef-client"

这不起作用

# knife ssh "webhost1[13579]" "chef-client"

Is there a way I can ssh to odd numbered hosts?

this works:

# knife ssh "webhost1*" "chef-client"

this does not work

# knife ssh "webhost1[13579]" "chef-client"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剑心龙吟 2025-01-22 09:04:21

要以本机方式实现此目的,您需要查看可以搜索。例如角色、标签等。一种方法是标记节点。例如,我们可以将节点标记为oddeven,即webhost1[13579]将被标记为奇数。

然后可以通过以下方式定位奇数主机:

knife ssh "name:webhost1* AND tags:odd" "chef-client"

为要使用的 knife ssh 命令生成奇数更多的是 Shell 功能,例如:

for num in $(seq 1 2 10); do knife ssh "webhost1$num" "chef-client"; done

seq 命令将生成一个序列从 1 开始,增量为 2,直到 10
请注意,这使得 SSH 执行串行,并且可能有更好或更有效的方法来生成奇数。此外,如果需要,您可以使用类似的 for 循环来标记节点。例子:

for num in $(seq 1 2 10); do knife tag create "webhost1$num" odd; done

To achieve this natively, you'll need to look at other properties of node that can be searched. Like roles, tags, etc. One way is to tag the nodes. For example, we can tag the nodes as odd and even, i.e. webhost1[13579] will be tagged as odd.

Then the odd hosts can be targeted by:

knife ssh "name:webhost1* AND tags:odd" "chef-client"

Generating odd numbers for the knife ssh command to use is more of a Shell functionality, e.g.:

for num in $(seq 1 2 10); do knife ssh "webhost1$num" "chef-client"; done

The seq command will generate a sequence starting from 1 with increments of 2, till 10.
Note that this makes the SSH execution serial, and there may be better or more efficient ways to generate the odd numbers. Also, you can use a similar for loop to tag the nodes if required. Example:

for num in $(seq 1 2 10); do knife tag create "webhost1$num" odd; done
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文