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

can't purge cron resources #19

Open
vchepkov opened this issue Jun 24, 2020 · 6 comments
Open

can't purge cron resources #19

vchepkov opened this issue Jun 24, 2020 · 6 comments

Comments

@vchepkov
Copy link
Contributor

while attempting removing 'unmanaged' cron entries, module recognizes those, but fails to remove

how to reproduce:

# crontab -u user -l
0 0 * * * /bin/echo test

puppet resource reports it as 'unmanaged'

# puppet resource cron 
cron { 'unmanaged:/bin/echo_test-1':
  ensure   => 'present',
  command  => '/bin/echo test',
  hour     => ['0'],
  minute   => ['0'],
  provider => 'crontab',
  target   => 'user',
  user     => 'user',
}

Code to apply:

purge { 'cron':
  if => [ 'user', '==', 'user' ],
}

Result of puppet apply:

Notice: /Stage[main]/Main/Purge[cron]/ensure: ensure changed 'purgable' to 'purged'
Notice: /Stage[main]/Main/Cron[unmanaged:/bin/echo_test-1]/ensure: removed

But cron entry remains intact.

Thanks,
Vadym

@lelutin
Copy link

lelutin commented Aug 20, 2021

Hello,

I've just hit this while trying to use the module.

I'm able to get cronjobs purged for the root user using a snippet similar to @vchepkov 's, but any for other user the cronjobs get marked as getting removed but they just stay there in the crontab file like what is described by OP.

@lelutin
Copy link

lelutin commented Aug 20, 2021

I'm trying to figure out what's present in the catalog, but with with a request of the following type against puppetdb, I'm not seeing a resource for the cronjob that's not getting removed:

catalogs { certname = "node-name.fqdn" }

nothing in the output is mentioning "unmanaged:" or "echo" (which is part of the test cronjob that should get removed).

I don't know why that resource is not in the catalog but visibly getting processed by the agent

@lelutin
Copy link

lelutin commented Aug 20, 2021

ah, sorry for my confusion in the previous message. I've read the type code and I can see the resources are injected by the purge type. if I look at the reports (instead of the catalogs) for that same machine, I can see that puppet claims to have removed the resource:

      {
        "status": "success",
        "timestamp": "2021-08-20T12:33:12.795-04:00",
        "resource_type": "Cron",
        "resource_title": "unmanaged:/usr/bin/echo_blah_toisssi-1",
        "property": "ensure",
        "corrective_change": null,
        "new_value": "absent",
        "old_value": "present",
        "message": "removed",
        "file": null,
        "line": null,
        "containment_path": [
          "Stage[main]",
          "Profile::Cron",
          "Cron[unmanaged:/usr/bin/echo_blah_toisssi-1]"
        ],
        "containing_class": "Profile::Cron"
      },

as stated before though, it's still present in the crontab file for the www-data user.

@vchepkov
Copy link
Contributor Author

vchepkov commented Jan 3, 2023

It's being awhile, anyone was able to find a solution?

@vchepkov
Copy link
Contributor Author

vchepkov commented Jan 4, 2023

I have inspected the res object in generate function and I found that

res[:user] -> nil
res[:target] -> "root"

I believe both are wrong and should be set to an actual user

@vchepkov
Copy link
Contributor Author

FYI, module fails to remove previously managed entries, i.e. those that have Puppet Name: prefix

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

2 participants