Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get host ipaddress from hostname #1728

Closed
willzhang opened this issue Jul 17, 2023 · 1 comment
Closed

get host ipaddress from hostname #1728

willzhang opened this issue Jul 17, 2023 · 1 comment

Comments

@willzhang
Copy link

willzhang commented Jul 17, 2023

Please describe your feature request.
i want get host ipaddress from hostname

Note:

  • how to questions should be posted in the discussion board and not raised as an issue.
  • V3 will no longer have any enhancements.

Describe the solution you'd like
If we have config.yml like:
(please keep to around 10 lines )

hosts:
- {name: node1, address: 172.16.0.2, port: 22, user: ubuntu, password: "Ubuntu@123"}
- {name: node2, address: 172.16.0.3, port: 22, user: ubuntu, password: "Ubuntu@123"}
- {name: node3, address: 172.16.0.4, port: 22, user: ubuntu, password: "Ubuntu@123"}
- {name: node4, address: 172.16.0.5, port: 22, user: ubuntu, password: "Ubuntu@123"}
- {name: node5, address: 172.16.0.6, port: 22, user: ubuntu, password: "Ubuntu@123"}
- {name: node6, address: 172.16.0.7, port: 22, user: ubuntu, password: "Ubuntu@123"}
roleGroups:
  etcd:
  - node1
  - node2
  - node3
  ceph:
  - node1
  - node2
  - node3
  master:
  - node1
  - node2
  - node3
  worker:
  - node1
  - node2
  - node3

And we run a command:

masters_hostname=$(yq .roleGroups.master.[] config.yaml)

it could output

node1
node2
node3

Describe alternatives you've considered
i want get node1 node2 node3 ip address, any suggestion

masters_ipaddress=$(yq .hosts.env(.roleGroups.master).address config.yaml)  ?

i want get output like this, but i don't know i can i do this

172.16.0.2
172.16.0.3
172.16.0.4

Additional context
Add any other context or screenshots about the feature request here.

@willzhang
Copy link
Author

yq eval '.roleGroups.master[] as $server | .hosts[] | select(.name == $server)| .address' config.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant