'knife ssh to odd numbered hosts
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"
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
