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

Adding --node_list option #55

Merged
merged 1 commit into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ $ puppet catalog diff \
--output_report "${HOME}/lastrun-$$.json" \
--debug \
\ #--fact_search kernel='Darwin' \
--threads 50
--threads 50 \
\ #--node_list=node1.example.come,node2.example.com
```


Expand All @@ -174,6 +175,12 @@ This currently defaults to `kernel=Linux` if you do not pass it.
This query will be passed as a filter to the PuppetDB to retrieve the list of
nodes to compare.

### Node list

Passing `--node_list` will bypass the dynamic generation of node lists from PuppetDB
including the `--fact_search` filter. The list of nodes are not validated against
PuppetDB, and it is up to the user to ensure that the nodes exist and are active.

### Changed depth

Once each catalog is compiled , it is saved to the /tmp directory on the system and the
Expand Down
7 changes: 6 additions & 1 deletion lib/puppet/face/catalog/diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
summary 'Use the certless catalog API (Puppet >= 6.3.0)'
end

option '--node_list=' do
summary 'A manual list of nodes to run catalog diffs against'
end

description <<-'EOT'
Prints the differences between catalogs compiled by different puppet master to help
during migrating to a new Puppet version.
Expand Down Expand Up @@ -171,7 +175,8 @@
filter_old_env: options[:filter_old_env],
certless: options[:certless],
old_catalog_from_puppetdb: options[:old_catalog_from_puppetdb],
new_catalog_from_puppetdb: options[:new_catalog_from_puppetdb]
new_catalog_from_puppetdb: options[:new_catalog_from_puppetdb],
node_list: options[:node_list]
)
diff_output = Puppet::Face[:catalog, '0.0.1'].diff(old_catalogs, new_catalogs, options)
nodes = diff_output
Expand Down
10 changes: 9 additions & 1 deletion lib/puppet/face/catalog/pull.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
summary 'Use the certless catalog API (Puppet >= 6.3.0)'
end

option '--node_list=' do
summary 'A manual list of nodes to run catalog diffs against'
end

description <<-'EOT'
This action is used to seed a series of catalogs from two servers
EOT
Expand All @@ -64,7 +68,11 @@
when_invoked do |catalog1, catalog2, args, options|
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'catalog-diff', 'searchfacts.rb'))
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'catalog-diff', 'compilecatalog.rb'))
nodes = Puppet::CatalogDiff::SearchFacts.new(args).find_nodes(options)
nodes = if options[:node_list].nil?
Puppet::CatalogDiff::SearchFacts.new(args).find_nodes(options)
else
options[:node_list].split(',')
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly more Rubyish way to write this (and also easier to understand if/else instead of unless/else b/c it’s not a double-negative):

nodes = if options[:node_list].nil?
          Puppet::CatalogDiff::SearchFacts.new(args).find_nodes(options)
        else
          options[:node_list].split(',')
        end

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call!

raise "Problem finding nodes with query #{args}" unless nodes

total_nodes = nodes.size
Expand Down