Skip to content

Commit

Permalink
implement distro constants
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Chamberland <chamberland.marc@gmail.com>
  • Loading branch information
bobchaos authored and ramereth committed Jun 7, 2020
1 parent 83bf4be commit fc48e5c
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 85 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
.vagrant
*.log
coverage/
pkg/
*.swap

# Chef Workstation is the source of truth for all locked gems
Gemfile.lock
74 changes: 37 additions & 37 deletions i18n/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
cli:
telemetry_enabled: |
Telemetry has been enabled by default for this beta release
of chef-run. The anonymous data we gather is used to
determine how we can impove your chef-run experience.
of %1. The anonymous data we gather is used to
determine how we can impove your %2 experience.
To disable it, add the following entry to
%1:
%2:
[telemetry]
enabled=false
Expand All @@ -31,7 +31,7 @@ cli:
options, visit https://chef.sh/docs/chef-workstation/privacy/
description: |
Chef Run is a tool to execute ad-hoc tasks using Chef.
%1 is a tool to execute ad-hoc tasks using %2.
creating_config: "Creating config file in %1."
default_config_location: "Location of config file. Default: %1"
identity_file: "SSH identity file to use when connecting. Keys loaded into ssh-agent will also be used."
Expand All @@ -44,9 +44,9 @@ cli:
Current default: %1
cookbook_repo_paths: "Comma separated list of cookbook repository paths."
install_description: |
Install Chef client on the target host(s) if it is not installed.
Install %1 on the target host(s) if it is not installed.
This defaults to enabled - the installation will be performed
if there is no Chef client on the target(s).
if there is no %1 installation on the target(s).
user_description: |
Username to use for authentication to the target(s). The same
username will be used for all targets.
Expand All @@ -69,47 +69,47 @@ cli:
password is required for sudo on the target(s). The same sudo password
will be used for all targets.
help:
description: Show help and usage for `chef-run`
description: Show help and usage for `%1`
usage: |
chef-run <TARGET[S]> <RESOURCE> <RESOURCE_NAME> [PROPERTIES] [FLAGS]
chef-run <TARGET[S]> <RECIPE> [FLAGS]
%1 <TARGET[S]> <RESOURCE> <RESOURCE_NAME> [PROPERTIES] [FLAGS]
%1 <TARGET[S]> <RECIPE> [FLAGS]
usage_full: |
chef-run <TARGET[S]> <RESOURCE> <RESOURCE_NAME> [PROPERTIES] [FLAGS]
%1 <TARGET[S]> <RESOURCE> <RESOURCE_NAME> [PROPERTIES] [FLAGS]
Runs a single <RESOURCE> on the specified <TARGET[S]>.
[PROPERTIES] should be specified as key=value.
For example:
chef-run web01 service nginx action=restart
chef-run web01,web02 service nginx action=restart
chef-run web0[1:2] service nginx action=restart
%1 web01 service nginx action=restart
%1 web01,web02 service nginx action=restart
%1 web0[1:2] service nginx action=restart
chef-run <TARGET[S]> <RECIPE> [FLAGS]
%1 <TARGET[S]> <RECIPE> [FLAGS]
Runs a single recipe located at <RECIPE> on the specified <TARGET[S]>.
For example:
chef-run web01 path/to/cookbook/recipe.rb
chef-run web01,web02 path/to/cookbook
chef-run web0[1:2] cookbook_name
chef-run web01 cookbook_name::recipe_name
%1 web01 path/to/cookbook/recipe.rb
%1 web01,web02 path/to/cookbook
%1 web0[1:2] cookbook_name
%1 web01 cookbook_name::recipe_name
ARGUMENTS:
<TARGET[S]> The hosts or IPs to target. Can also be an SSH or WinRM URLs
in the form:
ssh://[USERNAME]@example.com[:PORT]
<RESOURCE> A Chef resource, such as 'user' or 'package'
<RESOURCE> A %2 resource, such as 'user' or 'package'
<RESOURCE_NAME> The name, usually used to specify what 'thing' to set up with
the resource. For example, given resource 'user', 'name' would be
the name of the user you wanted to create.
<RECIPE> The recipe to converge. This can be provided as one of:
1. Full path to a recipe file
2. Cookbook name. First we check the working directory for this
cookbook, then we check in the chef repository path. If a
cookbook, then we check in the %3 repository path. If a
cookbook is found we run the default recipe.
3. This behaves similarly to 'cookbook name' above, but it also allows
you to specify which recipe to use from the cookbook.
Expand All @@ -125,10 +125,10 @@ cli:
Missing configuration file.
Please provide the path to a valid chef-run configuration file
Please provide the path to a valid %1 configuration file
as an argument to --config-path. For example:
--config-path /home/user1/.chef-workstation/config.toml
--config-path /home/user1/%2/config.toml
invalid_config_key: |
Expand All @@ -152,18 +152,18 @@ cli:
unsupported_installation: |
Use of chef-run within ChefDK is not supported.
Use of %1 within %2 is not supported.
Chef Workstation is the successor to the ChefDK, and contains the
same components including a supported chef-run.
%3 is the successor to the %2, and contains the
same components including a supported %1.
Download the latest here:
https://downloads.chef.io/chef-workstation/stable
https://%4/chef-workstation/stable
version:
description: Show the current version of Chef Run.
show: "chef-run: %1"
show: "%1: %2"
status:
connecting: "Connecting as %1..."
connected: "Connected."
Expand All @@ -178,16 +178,16 @@ status:
exporting: Generating local policyfile... exporting...
success: Generating local policyfile... exporting... done!
install_chef:
checking_for_client: Checking for Chef client.
verifying: Verifying Chef client installation.
downloading: Downloading Chef client installer into local cache.
uploading: Uploading Chef client installer to target.
installing: Installing Chef client version %1.
upgrading: Upgrading Chef client from version %1 to %2.
already_present: Chef client version %1 already installed on target.
install_success: Successfully installed Chef client version %1
upgrade_success: Successfully upgraded Chef client from version %1 to %2.
failure: "An error occurred while installing Chef client: %1"
checking_for_client: Checking for Chef client. # Not currently in use
verifying: Verifying %1 client installation.
downloading: Downloading %1 client installer into local cache.
uploading: Uploading %1 client installer to target.
installing: Installing %1 client version %2.
upgrading: Upgrading %1 client from version %2 to %3.
already_present: "%1 client version %2 already installed on target."
install_success: Successfully installed %1 client version %2
upgrade_success: Successfully upgraded %1 client from version %2 to %3.
failure: "An error occurred while installing Chef client: %1" # Not currently in use
converge:
header: !!pl
1: Applying %2 from %3 to target.
Expand Down
20 changes: 10 additions & 10 deletions i18n/errors/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,25 @@ errors:
# Installer action errors
CHEFINS002:
text: |
The target does not have chef-client installed.
The target does not have %1 installed.
This command is powered by the Chef client. In order to make use of it
on this node, the Chef client must be installed first.
This command is powered by the %2 client. In order to make use of it
on this node, the %2 client must be installed first.
Re-running this command without the '--no-install' flag will
automatically perform the installation.
CHEFINS003: |
The target's installed version of Chef Client is too old.
The target's installed version of %1 Client is too old.
Version %1 is installed, but this command requires a
minimum version of %2 (Chef 13) or %3 (Chef 14).
Version %2 is installed, but this command requires a
minimum version of %3 (%1 13) or %4 (%1 14).
CHEFINS004: |
The target's installed version of Chef Client is too old.
The target's installed version of %1 Client is too old.
Version %1 is installed, but this command requires a
minimum version of %2.
Version %2 is installed, but this command requires a
minimum version of %3.
CHEFINS003:
text: |
Expand Down Expand Up @@ -161,7 +161,7 @@ errors:
CHEFCCR005:
text: |
'%1' is not a valid Chef resource.
'%1' is not a valid resource.
Please consult the documentation for a list of valid resources:
Expand Down
10 changes: 6 additions & 4 deletions lib/chef_apply/action/converge_target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# FLAG: require "chef/util/path_helper"
require "chef/util/path_helper"

require_relative "../dist"

module ChefApply::Action
class ConvergeTarget < Base

Expand Down Expand Up @@ -105,7 +107,7 @@ def create_remote_config(dir)
data_collector.server_url "#{dc.url}"
data_collector.token "#{dc.token}"
data_collector.mode :solo
data_collector.organization "Chef Workstation"
data_collector.organization "#{ChefApply::Dist::WORKSTATION}"
EOM
end

Expand Down Expand Up @@ -172,7 +174,7 @@ def handle_ccr_error
# stale stacktrace.
target_host.del_file(chef_report_path)
report = JSON.parse(content)
ChefApply::Log.error("Remote chef-client error follows:")
ChefApply::Log.error("Remote #{ChefApply::Dist::CLIENT} error follows:")
ChefApply::Log.error(report["exception"])
end
mapper = ConvergeTarget::CCRFailureMapper.new(report["exception"], mapper_opts)
Expand All @@ -191,14 +193,14 @@ def run_chef_cmd(working_dir, config_file, policy)
when :windows
"Set-Location -Path #{working_dir}; " +
# We must 'wait' for chef-client to finish before changing directories and Out-Null does that
"chef-client -z --config #{File.join(working_dir, config_file)} --recipe-url #{File.join(working_dir, policy)} | Out-Null; " +
"#{ChefApply::Dist::CLIENT} -z --config #{File.join(working_dir, config_file)} --recipe-url #{File.join(working_dir, policy)} | Out-Null; " +
# We have to leave working dir so we don't hold a lock on it, which allows us to delete this tempdir later
"Set-Location C:/; " +
"exit $LASTEXITCODE"
else
# cd is shell a builtin, so we'll invoke bash. This also means all commands are executed
# with sudo (as long as we are hardcoding our sudo use)
"bash -c 'cd #{working_dir}; chef-client -z --config #{File.join(working_dir, config_file)} --recipe-url #{File.join(working_dir, policy)}'"
"bash -c 'cd #{working_dir}; #{ChefApply::Dist::CLIENT} -z --config #{File.join(working_dir, config_file)} --recipe-url #{File.join(working_dir, policy)}'"
end
end

Expand Down
8 changes: 5 additions & 3 deletions lib/chef_apply/action/install_chef/minimum_chef_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

require_relative "../../error"
require_relative "minimum_chef_version"
require_relative "../../dist"

module ChefApply
module Action
class InstallChef < Base
class MinimumChefVersion

D = ChefApply::Dist
CONSTRAINTS = {
windows: {
13 => Gem::Version.new("13.10.4"),
Expand Down Expand Up @@ -65,18 +67,18 @@ def self.check!(target, check_only)
end

class ClientNotInstalled < ChefApply::ErrorNoLogs
def initialize(); super("CHEFINS002"); end
def initialize(); super("CHEFINS002", D::CLIENT, D::SHORT); end
end

class Client13Outdated < ChefApply::ErrorNoLogs
def initialize(current_version, min_13_version, min_14_version)
super("CHEFINS003", current_version, min_13_version, min_14_version)
super("CHEFINS003", D::SHORT, current_version, min_13_version, min_14_version)
end
end

class Client14Outdated < ChefApply::ErrorNoLogs
def initialize(current_version, target_version)
super("CHEFINS004", current_version, target_version)
super("CHEFINS004", D::SHORT, current_version, target_version)
end
end
end
Expand Down
21 changes: 12 additions & 9 deletions lib/chef_apply/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
require_relative "action/generate_local_policy"
require_relative "action/converge_target"

require_relative "dist"

module ChefApply
class CLI
attr_reader :temp_cookbook, :archive_file_location, :target_hosts
Expand All @@ -56,6 +58,7 @@ class CLI
RC_COMMAND_FAILED = 1
RC_UNHANDLED_ERROR = 32
RC_ERROR_HANDLING_FAILED = 64
D = ChefApply::Dist

def initialize(argv)
@argv = argv.clone
Expand Down Expand Up @@ -181,28 +184,28 @@ def connect_target(target_host, reporter)
def install(target_host, reporter)
require_relative "action/install_chef"
context = TS.install_chef
reporter.update(context.verifying)
reporter.update(context.verifying(D::SHORT))
installer = Action::InstallChef.new(target_host: target_host, check_only: !parsed_options[:install])
installer.run do |event, data|
case event
when :installing
if installer.upgrading?
message = context.upgrading(target_host.installed_chef_version, installer.version_to_install)
message = context.upgrading(D::SHORT, target_host.installed_chef_version, installer.version_to_install)
else
message = context.installing(installer.version_to_install)
message = context.installing(D::SHORT, installer.version_to_install)
end
reporter.update(message)
when :uploading
reporter.update(context.uploading)
reporter.update(context.uploading(D::SHORT))
when :downloading
reporter.update(context.downloading)
reporter.update(context.downloading(D::SHORT))
when :already_installed
reporter.update(context.already_present(target_host.installed_chef_version))
reporter.update(context.already_present(D::SHORT, target_host.installed_chef_version))
when :install_complete
if installer.upgrading?
message = context.upgrade_success(target_host.installed_chef_version, installer.version_to_install)
message = context.upgrade_success(D::SHORT, target_host.installed_chef_version, installer.version_to_install)
else
message = context.install_success(installer.version_to_install)
message = context.install_success(D::SHORT, installer.version_to_install)
end
reporter.update(message)
else
Expand Down Expand Up @@ -340,6 +343,6 @@ def do_connect(target_host, reporter)
end

class LicenseCheckFailed < ChefApply::Error
def initialize(); super("CHEFLIC001"); end
def initialize(); super("CHEFLIC001", ChefApply::Dist::CLIENT, ChefApply::Dist::SHORT); end
end
end
4 changes: 2 additions & 2 deletions lib/chef_apply/cli/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ def format_flags
end

def usage
T.usage
T.usage(ChefApply::Dist::RUNEXEC)
end

def show_version
require_relative "../version"
UI::Terminal.output T.version.show(ChefApply::VERSION)
UI::Terminal.output T.version.show(ChefApply::Dist::RUNEXEC, ChefApply::VERSION)
end
end
end
Expand Down
Loading

0 comments on commit fc48e5c

Please sign in to comment.