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

list nodes and groups #537

Closed
scoopex opened this issue Jul 30, 2018 · 9 comments · Fixed by #1293
Closed

list nodes and groups #537

scoopex opened this issue Jul 30, 2018 · 9 comments · Fixed by #1293
Labels
Feature New features and improvements.

Comments

@scoopex
Copy link
Contributor

scoopex commented Jul 30, 2018

To allow convenient inspection of group/node definitions bolt should support a "list" and "show" option for groups and nodes.

$ bolt group list
mygroup-01
mygroup-02
mygroup-03
$ bolt group show mygroup-02
foo-001,foo-002,foo-003
$ bolt group show mygroup-02 --with-spaces
foo-001 foo-002 foo-003
$ bolt group show mygroup-02 --with-newlines
foo-001
foo-002
foo-003

$ bolt group show all --with-newlines
foo-001
foo-002
foo-003
...
foo-400

This is a precondition to add host and group completion for shell completions like "./resources/bolt_bash_completion.sh"
See also: #495

@adreyer
Copy link
Contributor

adreyer commented Jul 30, 2018

To keep this aligned with the behavior of the task and plan show commands it should be:

$bolt group show
mygroup_01
mygroup_02
mygroup_03
$bolt group show mygroup_01
foo-001
foo-002
foo-003

If the goal is autocompletion should the object be groups or targets?

bolt target show
mygroup_01
mygroup_02
mygroup_03
foo-001
foo-002
foo-003

Latter bolt target show mygroup_01 could be added to show more info about the group itself.

@scoopex
Copy link
Contributor Author

scoopex commented Aug 1, 2018

Sounds good :-)

@lucywyman lucywyman added the Feature New features and improvements. label Sep 27, 2018
@lucywyman
Copy link
Contributor

We now have a command bolt inventory show (https://puppet.com/docs/bolt/latest/bolt_command_reference.html#inventory-show) which accepts a TargetSpec and lists nodes that match that spec. This includes listing groups in the inventory, so bolt inventory show -n mygroupname will list nodes in that group. Let me know if this issue needs to be reopened.

@scoopex
Copy link
Contributor Author

scoopex commented Sep 21, 2019

Clone the recent repository: https://github.com/puppetlabs/bolt and executed bolt directly in the repository.

Played around with the first example of https://puppet.com/docs/bolt/latest/inventory_file.html#inventory-facts-vars-and-features

How can i gather the list of group-names? (this is essential for the bash completion)

Also other things are working not in a expected way:

# ok
$ bolt inventory show -n all
10.23.27.148
10.23.27.149
10.23.27.150
10.23.27.151
10.23.27.152
10.23.27.153
10.23.27.154
10.23.27.155

# wrong: result should be  192.168.100.179, 192.168.100.180, 192.168.100.181
$ bolt inventory show -n webservers
webservers
1 target

# wrong: result should be 192.168.100.179, 192.168.100.180, 192.168.100.181,192.168.101.50, 192.168.101.60
$ bolt inventory show -n ssh_nodes
ssh_nodes
1 target

# wrong: execution should be on 192.168.100.179, 192.168.100.180, 192.168.100.181,192.168.101.50
$ bolt command run "uptime" -n ssh_nodes
Started on ssh_nodes...
Failed on ssh_nodes:
  Failed to connect to ssh_nodes: getaddrinfo: Name or service not known
Failed on 1 node: ssh_nodes
an on 1 node in 0.1 sec

@lucywyman
Copy link
Contributor

Can you post a (scrubbed) version of your inventory? Are you using inventory version 1 or 2?

@lucywyman
Copy link
Contributor

It's working as expected for me locally with both inventory v1 and v2...

@scoopex
Copy link
Contributor Author

scoopex commented Sep 24, 2019

I am sorry, i accidentally placed the example to ~/.bolt/inventory.yaml.
The correct location "~/.puppetlabs/bolt/inventory.yaml" contained a outdated file.

Probably it is a good idea to enhance the last line "x targets" with the origin of the targets.
(i.e. '12 targets, loaded from "~/.puppetlabs/bolt/inventory.yaml" ')

How can i query the list of group-names? (this is essential for shell completion)

@lucywyman
Copy link
Contributor

lucywyman commented Sep 25, 2019

There isn't currently, but I think we can have a way to expose that.

The Solution

This should be a new subcommand bolt groups show, which will need a new elsif in this block: https://github.com/puppetlabs/bolt/blob/master/lib/bolt/cli.rb#L291-L311. That should call a new function in cli.rb called list_groups, which should be defined right after the def list_targets definition and look like this:

def list_groups
  groups = inventory.group_names
  outputter.print_groups(groups)
end

Then we'll need to define simple formatted output in both the JSON and human outputters (https://github.com/puppetlabs/bolt/tree/master/lib/bolt/outputter).

Testing should include printing nothing when the inventory is empty, and test for inventory versions 1 and 2.

@genebean
Copy link

Probably it is a good idea to enhance the last line "x targets" with the origin of the targets.
(i.e. '12 targets, loaded from "~/.puppetlabs/bolt/inventory.yaml" ')

^^ would be a great addition too.

nmaludy added a commit to nmaludy/bolt that referenced this issue Oct 8, 2019
nmaludy added a commit to nmaludy/bolt that referenced this issue Oct 8, 2019
nmaludy added a commit to nmaludy/bolt that referenced this issue Oct 15, 2019
nmaludy added a commit to nmaludy/bolt that referenced this issue Oct 15, 2019
lucywyman added a commit that referenced this issue Oct 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New features and improvements.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants