Ask Your Question
0

Cannot alias / already declared

asked 2018-03-13 08:13:34 -0500

erichymowitz gravatar image

updated 2018-03-13 08:23:04 -0500

I must be missing something obvious.

I have a module. In some situations, i want to create a file:

define createCronJob {    # this is line 154
  $lines = split ($name,',')
  $lines[0] = split ($lines[0],':')
  $lines[1] = split ($lines[1],':')
  file { 'symantec.cron' :
        ensure => file,
        path => "/etc/cron.d/symantec.liveupdate.cron",
        mode => 600,
        seltype  => 'system_cron_spool_t',
        content =>
"#
# this file is managed by puppet.
#
${lines[0][2]} ${lines[0][1]} * * ${lines[0][0]} root /opt/Symantec/symantec_antivirus/sav liveupdate -u
${lines[1][2]} ${lines[1][1]} * * ${lines[1][0]} root /opt/Symantec/symantec_antivirus/sav liveupdate -u
"
      }                   # this is line 166
}

But in other situations, I want to make sure that file does not exist.

if $style == "manual"
{
  file { 'remove.symantec.cron' :      # this is line 117
    ensure => absent,
    path => "/etc/cron.d/symantec.liveupdate.cron",
  }
}

But I'm getting an error

Error: Failed to apply catalog: Cannot alias File[symantec.cron] to ["/etc/cron.d/symantec.liveupdate.cron"] at /etc/puppet/modules/symantec/manifests/init.pp:166; resource ["File", "/etc/cron.d/symantec.liveupdate.cron"] already declared at /etc/puppet/modules/symantec/manifests/init.pp:117

I thought that using different names -- symantec.cron and remove.symantec.cron -- was designed to resolve this problem.

How do I set up two different rules -- one to create, one to remove -- that potentially operate on the same file?

edit retag flag offensive close merge delete

Comments

You probably need to pass the 'manual' information into the define createCronJob, and switch your logic there, other wise as you saw, you get two separate 'resources' in your catalog, one trying to add the file and another to remove it.

DarylW gravatar imageDarylW ( 2018-03-13 08:51:54 -0500 )edit

maybe you are using createCronJob many time with the file resource symantec.cron

c4f4t0r gravatar imagec4f4t0r ( 2018-03-14 06:54:45 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-03-14 03:08:02 -0500

natemccurdy gravatar image

path is the unique identifier for files (also known as the namevar).

You have two separate file resources both managing the same path which is why you're getting that error message.

edit flag offensive delete link more

Comments

Bummer. Thanks. I did what @DarylW suggested and rewrote the createCronJob definition.

erichymowitz gravatar imageerichymowitz ( 2018-03-14 11:13:34 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2018-03-13 08:13:34 -0500

Seen: 240 times

Last updated: Mar 14