Code Monkey home page Code Monkey logo

puppet-windows-path's Introduction

puppet-windows-path

Manage individual entries in the Windows PATH variable as resources, that is, add and remove directories to the PATH in an idempotent manner.

There is already the excellent puppetlabs/registry module to manage registry entries. In the end, the Windows PATH is also a registry entry (or rather two, the system PATH and the user PATH of the current user), so you might wonder why this module exists. However, the registry module (or any other module I know of) does not offer the abstraction of managing a single entry in the PATH (like "C:\Program Files (x86)\puppetlabs\puppet\bin") as a resource. Thus adding specific directories to the PATH in an idempotent manner is a real headache. Naive attempts (for example, by using exec together with SET) might result in duplicated path entries or other issues.

This module solves this problem. Internally, it parses and splits the PATH up into individual entries (directories) and is thus able to check reliably if any given directory already is contained in the PATH or not.

The module is able to manage the system path as well as the user path. The default is to manage the system path.

Installation

Either install the latest release from puppet forge:

puppet module install basti1302/windows_path

or install the current head from the git repository by going to your puppet modules folder and do

git clone [email protected]:basti1302/puppet-windows-path.git windows_path

It is important that the folder where this module resisdes is named windows_path, not puppet-windows-path.

Usage

include windows_path

# Add an entry to the PATH or verify that it is already there.
windows_path {'add a PATH entry if it is not there yet':
  ensure      => present,
  directory   => 'C:\this\should\be\added',
}

# Remove an existing path entry or verify that the directory is not in the PATH.
windows_path {'remove a directory from PATH.':
  ensure      => absent,
  directory   => 'C:\this\should\be\removed',
}

# By specifying target => user you can manage the path of the current user.
# target => system (or omitting target) results in the sytem path being managed.
# Currently it is not possible to manage the path of an arbitrary user. Pull
# requests are welcome :-)
windows_path {'Manage the path of the current user.':
  ensure      => absent,
  directory   => 'C:\this\should\be\removed',
  target      => user,
}

# The namevar is, of course, the parameter directory.
windows_path {'C:\add\this\also\please':
    ensure      => present,
}

puppet-windows-path's People

Contributors

basti1302 avatar hunner avatar

Stargazers

Mattias Cockburn avatar Peter Liu avatar Liam Bennett avatar Nicholas Devenish avatar Vlastimil Holer avatar Rich Siegel avatar Sebastian Cole avatar

Watchers

 avatar James Cloos avatar JS avatar

puppet-windows-path's Issues

Maintain

Hello,

We are using this module. Can we maintain it as well?

Duplicate declaration warnings if puppet-windows_env is used, too

With both this module and puppet-windows_env installed, one gets duplicate declaration warnings for two constants used in the code:

C:/ProgramData/PuppetLabs/puppet/cache/lib/puppet/provider/windows_env/windows_env.rb:51: warning: already initialized constant HWND_BROADCAST
C:/ProgramData/PuppetLabs/puppet/cache/lib/puppet/provider/windows_path/path_provider.rb:9: warning: previous definition of HWND_BROADCAST was here
C:/ProgramData/PuppetLabs/puppet/cache/lib/puppet/provider/windows_env/windows_env.rb:52: warning: already initialized constant WM_SETTINGCHANGE
C:/ProgramData/PuppetLabs/puppet/cache/lib/puppet/provider/windows_path/path_provider.rb:11: warning: previous definition of WM_SETTINGCHANGE was here

PR to come...

Upcoming Puppet 3.7 / PE 3.4 x64 compatibility changes

As part of making Puppet compatible with Windows x64 / Ruby 2, we have had to make a number of changes to our included gems, and have removed sys-admin, windows-pr, win32-api and windows-api. Other gems have been upgraded to versions that require FFI and are compatible with x64.

We don't have builds released yet, but keep an eye on https://groups.google.com/forum/#!forum/puppet-announce

I have identified a small issue with the code in this module that will require some updating to ensure it maintains compatibility with both existing Puppet releases and the upcoming releases. I'm getting in touch with you now, so that you're not caught off guard, and so that your module is ready to go by the time 3.7 ships.

Issues:

  • Defines the SendMessageTimeout API call using Ruby's Win32API class, which won't work on x64 due to incorrect definitions for variables that have a platform specific width (such as HANDLE). These API calls should use FFI definitions, so that they are properly defined on both x86 and x64. Many examples exist in the Puppet codebase now in the lib/puppet/util/windows folder, such as https://github.com/puppetlabs/puppet/blob/master/lib/puppet/util/windows/process.rb#L214

We will be making an announcement to the puppet-dev list shortly mentioning some of these upcoming changes.
https://groups.google.com/forum/#!forum/puppet-dev

Let me know if you have any questions.

Thanks!

Create version tags

Could you, please, tag versions in the repository?
We are using r10k to deploy from github directly
Thanks,
Vadym

Publish on puppet forge

  • puppet module build does not work on Windows (actually, no puppet module xxx tool works on Windows)

  • On Linux, puppet module build gives

    Error: Could not autoload puppet/provider/windows_path/path_provider: no such file to load -- win32/registry.rb
    Error: Could not autoload puppet/provider/windows_path/path_provider: no such file to load -- win32/registry.rb
    Error: Try 'puppet help module build' for usage

So what? We probably need to pack the tar.gz by hand, which should not be so hard. Otoh, this is for Windows only and puppet module install also does not work on Windows, so the benefit is a bit questionable.

Make the new path available in the same run

Hi,
I'm using your module and it's useful for my windows machines. However, I can't make available the new path in the same run, I have to wait to the next one.

The scenario is the following: the module installs python, uses windows_path to add the python folder and scripts folder to the path, and then it uses the pip package provider for installing a new lib in python. The pip providers looks for pip command in the path, that as I said is not yet available until the next run.

What do you think?, could it be easily solved?

remove and add path?

Should I expect to be able to both remove a path and add a new one? As in:

# removes previous Java from path
windows_path {'removejavapath':
  ensure      => absent,
  directory   => "C:\\Program Files\\Java\\jdk1.7.0_51\\bin"
}

# Adds java to the path.
windows_path {'javaPath':
  ensure      => present,
  directory   => "C:\\Program Files\\Java\\$file\\bin",
 }

?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.