Windows copy and file modules

I have recently been trying to get a windows copy module to work. I noticed the win_copy pull request but it is trying to use a samba share and as some of the comments pointed out you could easily piggy back on the same system ansible uses to push the powershell modules to the device. Then I realized by just adding a copy.ps1 and file.ps1 module I was able to reuse the copy ( and template ) action plugins as is. I posted my two powershell scripts here https://gist.github.com/akinsley

The problem comes when trying to change file permissions for windows. I was trying to convert a linux chmod mode into windows ACLs and while I think i got a hacky conversion working I completely failed to actually apply the file permissions. I am not a windows guy so powershell and windows administration in general are new to me.

I wanted to see if anybody had ideas how file permissions and copying should work in ansible. I was pleasently surprised when i was able to reuse the action plugin, however I think converting the linux arguments to windows is not what ansible wants to do. Is anybody else working on these modules? Is there a way to use different modules but still reuse the action plugins?

Tony

Very interested in seeing bits.

Looks like the files might have been cut off on https://gist.github.com/akinsley, can you check?

I’m not sure what you mean about the chmod command part, but I think the problem is you are adding a “copy.ps1” for a remote module, and instead should name it “win_copy”, as it’s trying to go down the Linux path we don’t want it to.

Rather, it MIGHT need it’s own action plugin, but I can’t be sure.

Alternatively, we might not worry about it, and just require a seperate win_file call or something to set permissions.

Here is the full url. https://gist.github.com/akinsley/4a273aa44227e736278c for copy.ps1 and https://gist.github.com/akinsley/ba5d4f1b19a4547d83e5 for file.ps1.

By the chmod part I mean the mode like “0644”. I put my conversion stuff in a function, but it errors out and we decided we do not need it this moment. Any help would be very much appreciated.

I called it copy.ps1 because then the action plugin picked it up without any edits to it. The copy action plugin also calls out the file module which is a really feature rich module. I tried to duplicate just the file permissions stuff but windows is really difficult.

Like I said I dont believe this is what ansible officially wants to do, and I was curious and it worked.

Nice one! For the file ACL stuff, I think we just have to realize the fundamentally different workings of access control on Linux and NTFS file systems.

An NTFS object (file or folder) does have an “owner” attribute (either group or user), and attributes (such as read-only, hidden and so forth). In addition, an NTFS object has an ACL which is essentially an array with each item consisting of a user/group, a set of permissions (read/write/execute/delete and so forth), along with some extra attributes which control whether the ACL entry recurses to subdirectories/files, for instance.

I don’t think there’s much point in trying to replicate the existing “file” module, except for the fact that server-side modules such as copy (and template?) use them. We might have to implement some windows-specific modules such as win_copy and win_template to deal with that - although it would be great to have the existing modules (copy/template) also work on Windows.

Can you check the access to these files. I would use them until there is something better :wink:

OK, ignore :wink: Found the proper urls:

https://gist.github.com/tkinz27/8a0b49f3c8b0ea4575c6

https://gist.github.com/tkinz27/fd92ba9af0e0309614ee

I just tried the copy module and it works great. We should get this PR’ed and into core as soon as possible, as it’s a critical piece for windows support.

Has anyone PRed this one? The only thing I’m thinking is that we might be better off creating a win_copy (and win_file), to reflect the differences in permission models. I don’t think its a good idea to try and “port” the NTFS permission model to the linux one, that’s never gonna work. This probably means that the “server-side” modules need a win_copy/win_file flavor as well, right?

No PRs yet on this one; I've replied in more detail on
https://groups.google.com/forum/#!topic/ansible-devel/Jl5qP73CiKo