Exec onlyif registry value is missing

* * 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 will leave this message in case anyone else encounters a similar problem.

* * EDIT **


I am trying to write a puppet manifest to add a permanent 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 execute the command every time the puppet client checks with the puppet master.

I was hoping to use it onlyifin my class, but it seems a bit confusing when trying to check if the registry value containing my route is missing. Is this the best way to do this? Any other ideas?

I think 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 => ???
    }
}

, onlyif

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'

:

: 0 .

, , onlyif , , , .

- , ?

+4
1

, :

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",
        }
}

, -

+2

Source: https://habr.com/ru/post/1532189/


All Articles