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

Editing the Content attribute in `systemd_unit` with `edit_resource` cannot get past validation #8640

Open
yaningzhu opened this issue Jun 7, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@yaningzhu
Copy link

commented Jun 7, 2019

Description

content attribute in systemd_unit fails validation when edit_resource was used.

Chef Version

Chef 14.12.3

Platform Version

Ubuntu 18.04

Replication Case

Create a recipe in your cookbook, something simple like this:

# standard chef-client things
include_recipe 'chef-client::delete_validation'
include_recipe 'chef-client::config'
include_recipe 'chef-client'

# the recipe should work up to this point, however it would fail when I include the blocks below

chef_client_service = {
  'Unit' => {
    'Description' => 'Chef Client daemon',
    'After' => 'network.target auditd.service',
  },
  'Service' => {
    'Type' => 'simple',
    'EnvironmentFile' => '/etc/default/chef-client',
    'ExecStart' => '/usr/bin/chef-client -c $CONFIG -i $INTERVAL -s $SPLAY $OPTIONS',
    'ExecReload' => '/bin/kill -HUP $MAINPID',
    'SuccessExitStatus' => 3,
    'Restart' => node['chef_client']['systemd']['restart'],
  },
  'Install' => { 'WantedBy' => 'multi-user.target' },
}

edit_resource!(:systemd_unit, 'chef-client.service') do
  content chef_client_service
end

My example content should work fine, since it's basically a copy-paste from the chef-client cookbook, with hardcoded variables.

Client Output

Recipe: chef-client::systemd_service
  * template[/etc/default/chef-client] action create
    - create new file /etc/default/chef-client
    - update content in file /etc/default/chef-client from none to 27f1d4
    --- /etc/default/chef-client	2019-06-07 22:50:37.702974499 +0000
    +++ /etc/default/.chef-chef-client20190607-75-zc8pql	2019-06-07 22:50:37.702974499 +0000
    @@ -1 +1,4 @@
    +CONFIG=/etc/chef/client.rb
    +INTERVAL=1800
    +SPLAY=300
    - change mode from '' to '0644'
  * directory[/etc/systemd/system] action create (up to date)
  * systemd_unit[chef-client.service] action create
  Recipe: <Dynamically Defined Resource>
    * file[/etc/systemd/system/chef-client.service] action create

      ================================================================================
      Error executing action `create` on resource 'file[/etc/systemd/system/chef-client.service]'
      ================================================================================

      Chef::Exceptions::ValidationFailed
      ----------------------------------
      Proposed content for /etc/systemd/system/chef-client.service failed verification :systemd_unit (Chef::Resource::File::Verification::SystemdUnit)

      Compiled Resource:
      ------------------
      # Declared in

      file("/etc/systemd/system/chef-client.service") do
        action [:create]
        default_guard_interpreter :default
        owner "root"
        group "root"
        content "[Unit]\nDescription = Chef Client daemon\nAfter = network.target auditd.service\n\n[Service]\nType = simple\nEnvironmentFile = /etc/default/chef-client\nExecStart = /usr/bin/chef-client -c $CONFIG -i $INTERVAL -s $SPLAY $OPTIONS\nExecReload = /bin/kill -HUP $MAINPID\nSuccessExitStatus = 3\nRestart = on-failure\n\n[Install]\nWantedBy = multi-user.target\n"
        path "/etc/systemd/system/chef-client.service"
        verifications [#<Chef::Resource::File::Verification:0x0000000006079850 @command_opts={}, @command=:systemd_unit, @block=nil, @parent_resource=<file[/etc/systemd/system/chef-client.service] @name: "/etc/systemd/system/chef-client.service" @before: nil @params: {} @provider: nil @allowed_actions: [:nothing, :create, :delete, :touch, :create_if_missing] @action: [:create] @updated: false @updated_by_last_action: false @source_line: nil @guard_interpreter: nil @default_guard_interpreter: :default @elapsed_time: 0 @owner: "root" @group: "root" @content: "[Unit]\nDescription = Chef Client daemon\nAfter = network.target auditd.service\n\n[Service]\nType = simple\nEnvironmentFile = /etc/default/chef-client\nExecStart = /usr/bin/chef-client -c $CONFIG -i $INTERVAL -s $SPLAY $OPTIONS\nExecReload = /bin/kill -HUP $MAINPID\nSuccessExitStatus = 3\nRestart = on-failure\n\n[Install]\nWantedBy = multi-user.target\n" @path: "/etc/systemd/system/chef-client.service" @verifications: [...] @mode: "0644">>]
        mode "0644"
      end

      System Info:
      ------------
      chef_version=14.12.3
      platform=ubuntu
      platform_version=18.04
      ruby=ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]
      program_name=/opt/chef/embedded/bin/chef-client
      executable=/opt/chef/embedded/bin/chef-client

I did try turning on debug level logging, but the above error report didn't change much.

@lamont-granquist

This comment has been minimized.

Copy link
Contributor

commented Jun 13, 2019

That will have nothing to do with edit_resource at all.

The systemd_unit property validation itself is fine with the argument.

What is failing is the file sub-resource has a file verifier to ensure the rendered file has sane content.

Offhand I'm not seeing a bug here unless there's something wrong with that file verifier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.