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

Cannot alias Shellvar, resource already declared #31

Open
Hufschmidt opened this issue Apr 23, 2018 · 6 comments
Open

Cannot alias Shellvar, resource already declared #31

Hufschmidt opened this issue Apr 23, 2018 · 6 comments

Comments

@Hufschmidt
Copy link

Hufschmidt commented Apr 23, 2018

The following code works fine with version 2.2.2, but fails with catalog-compilation error on version 2.2.3.

  exec { 'update grub':
    command     => '/usr/sbin/update-grub',
    refreshonly => true,
  }

  shellvar { 'default to noop elevator':
    ensure       => present,
    target       => '/etc/default/grub',
    variable     => 'GRUB_CMDLINE_LINUX',
    value        => 'elevator=noop',
    array_append => true,
    notify       => Exec['update grub'],
  }

  if ($::kernel == 'Linux' and $::virtual == 'kvm') {
    shellvar { 'configure serial console':
      ensure       => present,
      target       => '/etc/default/grub',
      variable     => 'GRUB_CMDLINE_LINUX',
      value        => 'console=ttyS0,115200n8',
      array_append => true,
      notify       => Exec['update grub'],
    }
  }

Error message:

Error: Could not retrieve catalog from remote server:
Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement,
Cannot alias Shellvar[configure serial console] to ["/etc/default/grub", "GRUB_CMDLINE_LINUX"] at
[[second resource definition]];
resource ["Shellvar", "/etc/default/grub", "GRUB_CMDLINE_LINUX"] already declared at
[[first resource definition]] at
[[second resource definition]]
on node [[detracted]]
Warning: Not using cache on failed catalog

@Hufschmidt
Copy link
Author

Hufschmidt commented Apr 23, 2018

Maybe this helps. It seems like (at least with array_append => true) the value parameter needs to be part of the unique resource name (aka composite name)...

EDIT:
I don't know if properties can be used as (composite-) namevar, looking at this seems like yes, which would be a rather easy solution. Or we could try to use a similar trick as with the package type, see here

Otherwise I think the only solution is go the way of puppetlabs-inifile#subsetting and introduce a new (namevar-) parameter sub_variable as replacement for array_append, such that the above resources can have unique names.

@raphink
Copy link
Member

raphink commented Oct 18, 2018

I'm not really sure to understand how switching the title_patterns method would break this.

In any case:

  • I'm pretty sure array_append has nothing to do with this, it's just the fact of having two resources with the same target/variable combination
  • Properties cannot be used as namevars, as namevars need to be parameters since they identify the resource as primary keys.

Mainly, I can't reproduce this either on Puppet 4.10 or 5.5. Which version of Puppet are you using?

@Hufschmidt
Copy link
Author

  • I'm pretty sure array_append has nothing to do with this, it's just the fact of having two resources with the same target/variable combination

Oh ok, thanks you for clearing this confusion. I thought this is the intended use-case, similar to puppetlabs-inifile subsetting parameter.

Mainly, I can't reproduce this either on Puppet 4.10 or 5.5. Which version of Puppet are you using?

This happened with Puppet 4.10.

Since I was able to solve this using hercules-team/augeasproviders_grub instead and given your above explanation I think we can close this issue as it seems to be the intended behavior.

@kenyon
Copy link
Member

kenyon commented Feb 25, 2023

Running into this exact same problem now with Puppet 6.27.0 and augeasproviders_shellvar v5.0.0. 😒 I'm even trying to set the same variable in the same file as the original reporter, GRUB_CMDLINE_LINUX in /etc/default/grub, because I gave up on augeasproviders_grub due to voxpupuli/puppet-augeasproviders_grub#51 and voxpupuli/puppet-augeasproviders_grub#74 (it also has the same alias problem too though, if you want to set the same parameters for multiple bootmodes as you need to do to support both RHEL and Debian and need to modify GRUB_CMDLINE_LINUX_DEFAULT and GRUB_CMDLINE_LINUX).

It's starting to look like I might need to use file_line or just manage the whole /etc/default/grub file.

Update: turns out that /etc/default/grub doesn't really do anything on RHEL 8. So I'm using puppet module atsonkov/grubby to manage the grub config there. Reference: https://fedoraproject.org/wiki/Changes/BootLoaderSpecByDefault

Eventually I think this problem will go away for /etc/default/grub because that file will be irrelevant assuming Debian adopts the BLS like Fedora/RHEL have: https://uapi-group.org/specifications/specs/boot_loader_specification/

@kenyon kenyon changed the title Error with 2.2.3 and array_append Cannot alias Shellvar, resource already declared Feb 25, 2023
@kenyon kenyon reopened this Feb 25, 2023
@kenyon
Copy link
Member

kenyon commented Feb 26, 2023

Silly workaround, but it seems to work fine: add extra slashes to the target path.

shellvar { 'wanted kernel parameters':
  ensure       => present,
  variable     => 'GRUB_CMDLINE_LINUX',
  target       => '/etc/default//grub',
  value        => [
    'audit=1',
  ],
  array_append => true,
  notify       => Exec['update-grub'],
}

shellvar { 'unwanted kernel parameters':
  ensure       => absent,
  variable     => 'GRUB_CMDLINE_LINUX',
  target       => '/etc/default/grub',
  value        => [
    'nomodeset',
    'quiet',
    'splash',
  ],
  array_append => true,
  notify       => Exec['update-grub'],
}

@P6wG7
Copy link
Contributor

P6wG7 commented Mar 27, 2024

Got the same issue with puppet 8.5.1 and this very small patch fixed on my side:

diff --git a/lib/puppet/type/shellvar.rb b/lib/puppet/type/shellvar.rb
index 70c99c6..97378ae 100644
--- a/lib/puppet/type/shellvar.rb
+++ b/lib/puppet/type/shellvar.rb
@@ -55,6 +55,7 @@ Puppet::Type.newtype(:shellvar) do
 
   newparam(:name) do
     desc 'The default namevar'
+    isnamevar
   end
 
   newparam(:variable) do

This is added in that PR: #61

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

No branches or pull requests

4 participants