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

added bash completion for Ubuntu and Debian - others untested #581

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ The following parameters are available in the `consul` class:
* [`acl_api_token`](#-consul--acl_api_token)
* [`arch`](#-consul--arch)
* [`archive_path`](#-consul--archive_path)
* [`bash_completion`](#-consul--bash_completion)
* [`bash_completion_compat_dir`](#-consul--bash_completion_compat_dir)
* [`bin_dir`](#-consul--bin_dir)
* [`binary_group`](#-consul--binary_group)
* [`binary_mode`](#-consul--binary_mode)
Expand Down Expand Up @@ -206,6 +208,22 @@ Path used when installing consul via the url

Default value: `undef`

##### <a name="-consul--bash_completion"></a>`bash_completion`

Data type: `Boolean`

Whether to setup bash completion. Adjust bin_dir when install_method == package.

Default value: `$consul::params::bash_completion`

##### <a name="-consul--bash_completion_compat_dir"></a>`bash_completion_compat_dir`

Data type: `String[1]`

Directory to place bash-completion file for Consul into.

Default value: `$consul::params::bash_completion_compat_dir`

##### <a name="-consul--bin_dir"></a>`bin_dir`

Data type: `Stdlib::Absolutepath`
Expand Down
4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# @param acl_api_token Global token of ACL API, will be merged with consul_token resources
# @param arch Architecture of consul binary to download
# @param archive_path Path used when installing consul via the url
# @param bash_completion Whether to setup bash completion. Adjust bin_dir when install_method == package.
# @param bash_completion_compat_dir Directory to place bash-completion file for Consul into.
# @param bin_dir Directory to create the symlink to the consul binary in.
# @param binary_group The group that the file belongs to.
# @param binary_mode Permissions mode for the file.
Expand Down Expand Up @@ -95,6 +97,8 @@
String[0] $acl_api_token = '', # lint:ignore:params_empty_string_assignment
String[1] $arch = $consul::params::arch,
Optional[Stdlib::Absolutepath] $archive_path = undef,
Boolean $bash_completion = $consul::params::bash_completion,
String[1] $bash_completion_compat_dir = $consul::params::bash_completion_compat_dir,
Stdlib::Absolutepath $bin_dir = $consul::params::bin_dir,
Optional[String[1]] $binary_group = $consul::params::binary_group,
String[1] $binary_mode = $consul::params::binary_mode,
Expand Down
14 changes: 14 additions & 0 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,18 @@
system => true,
}
}

if ($consul::bash_completion) and ($consul::install_method != 'docker' ) {
file { $consul::bash_completion_compat_dir:
ensure => 'directory',
}

file { "${consul::bash_completion_compat_dir}/consul":
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => "complete -C ${consul::bin_dir}/${consul::binary_name} consul\n",
}
}
}
4 changes: 4 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
default: {
# 0 instead of root because OS X uses "wheel".
$data_dir_mode = '0755'
$bash_completion_compat_dir = '/etc/bash_completion.d/'
Copy link
Member

Choose a reason for hiding this comment

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

please don't add the value here, instead directly in the init.pp. that enabled puppet-strings to pickup the default value.

Copy link
Contributor Author

@jardleex jardleex Jun 2, 2023

Choose a reason for hiding this comment

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

Thanks for the feedback. I hope I got you right with this?

diff --git a/REFERENCE.md b/REFERENCE.md
index ffaf8db..e93022a 100644
--- a/REFERENCE.md
+++ b/REFERENCE.md
@@ -222,7 +222,7 @@ Data type: `String[1]`
 
 Directory to place bash-completion file for Consul into.
 
-Default value: `$consul::params::bash_completion_compat_dir`
+Default value: `'/etc/bash_completion.d/'`
 
 ##### <a name="-consul--bin_dir"></a>`bin_dir`
 
diff --git a/manifests/init.pp b/manifests/init.pp
index 20586b2..95fb6ec 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -98,7 +98,7 @@ class consul (
   String[1]                             $arch                        = $consul::params::arch,
   Optional[Stdlib::Absolutepath]        $archive_path                = undef,
   Boolean                               $bash_completion             = $consul::params::bash_completion,
-  String[1]                             $bash_completion_compat_dir  = $consul::params::bash_completion_compat_dir,
+  String[1]                             $bash_completion_compat_dir  = '/etc/bash_completion.d/',
   Stdlib::Absolutepath                  $bin_dir                     = $consul::params::bin_dir,
   Optional[String[1]]                   $binary_group                = $consul::params::binary_group,
   String[1]                             $binary_mode                 = $consul::params::binary_mode,
diff --git a/manifests/params.pp b/manifests/params.pp
index 3d3f6ed..bcabcb2 100644
--- a/manifests/params.pp
+++ b/manifests/params.pp
@@ -47,7 +47,6 @@ class consul::params {
     default: {
       # 0 instead of root because OS X uses "wheel".
       $data_dir_mode = '0755'
-      $bash_completion_compat_dir = '/etc/bash_completion.d/'
       $binary_group = '0'
       $binary_mode = '0555'
       $binary_name = 'consul'

$binary_group = '0'
$binary_mode = '0555'
$binary_name = 'consul'
Expand All @@ -63,12 +64,14 @@

case $facts['os']['name'] {
'Ubuntu': {
$bash_completion = true
$shell = '/usr/sbin/nologin'
}
'RedHat': {
$shell = '/sbin/nologin'
}
'Debian': {
$bash_completion = true
$shell = '/usr/sbin/nologin'
}
'Archlinux': {
Expand All @@ -81,6 +84,7 @@
$shell = '/usr/sbin/nologin'
}
default: {
$bash_completion = false
$shell = undef
}
}
Expand Down