Exec onlyif registry value is not present

允我心安 提交于 2019-12-19 09:28:42

问题


**EDIT**

I found a solution by playing around:

class add_route
{
        exec { "route_to_internal_network":
                command => "C:\Windows\System32\ROUTE.EXE add 192.168.5.254 mask 255.255.255.255 10.5.5.5 -p",
                unless => "C:\Windows\System32\reg.exe query HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\PersistentRoutes /f 192.168.5.254,255.255.252.0,10.5.5.5,1",
        }
}

I'll leave this post up in case anyone else is running into a similar problem

**EDIT**


I am trying to write a puppet manifest to add a persistent static route to some of my Windows host servers. So far, I am thinking of creating a class that does:

class add_route
{
    exec { "route_to_internal_network":
        command => "C:\Windows\System32\ROUTE.EXE add 192.168.5.254 mask 255.255.255.255 10.5.5.5 -p",
    }
}

However, this manifest will exec the command every time the puppet client checks in with the puppet master.

I was hoping to use onlyif in my class, but it seems a little confusing when trying to check for an absent registry value that contains my route. Is this the best way to do this? Any other ideas?

I imagine I need to do something like:

class add_route
{
    exec { "route_to_internal_network":
        command => "C:\Windows\System32\ROUTE.EXE add 192.168.5.254 mask 255.255.255.255 10.5.5.5 -p",
        onlyif => ???
    }
}

I was hoping my onlyif statement would match to

C:\Windows\System32\reg.exe query HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\PersistentRoutes /f '192.168.5.254,255.255.255.255,10.5.5.5,1'

If the result of the above command is:

End of search: 0 match(es) found.

However, I think the onlyif is just looking for a return code, so whether or not this value is found, the command completes successfully.

Does anyone know how I could check for the absence of a registry value in a puppet manifest?


回答1:


I found a solution by playing around:

class add_route
{
        exec { "route_to_internal_network":
                command => "C:\Windows\System32\ROUTE.EXE add 192.168.5.254 mask 255.255.255.255 10.5.5.5 -p",
                unless => "C:\Windows\System32\reg.exe query HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\PersistentRoutes /f 192.168.5.254,255.255.255.255,10.5.5.5,1",
        }
}

I'll leave this post up in case anyone else is running into a similar problem



来源:https://stackoverflow.com/questions/22462383/exec-onlyif-registry-value-is-not-present

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!