From ddb7e6669e05615417087adf9bdb22250f9e9b35 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Wed, 18 Jun 2014 09:32:02 -0500 Subject: [PATCH] Add start for powershell setup module --- windows/assemble.ps1 | 6 ++-- windows/async_wrapper.ps1 | 6 ++-- windows/command.ps1 | 6 ++-- windows/copy.ps1 | 6 ++-- windows/file.ps1 | 6 ++-- windows/ping.ps1 | 6 ++-- windows/setup.ps1 | 71 +++++++++++++++++++++++++++++++++++++++ windows/slurp.ps1 | 6 ++-- windows/stat.ps1 | 6 ++-- windows/win_ping.ps1 | 6 ++-- 10 files changed, 98 insertions(+), 27 deletions(-) create mode 100644 windows/setup.ps1 diff --git a/windows/assemble.ps1 b/windows/assemble.ps1 index e5c4a01907e..c4627bb48ae 100644 --- a/windows/assemble.ps1 +++ b/windows/assemble.ps1 @@ -1,7 +1,4 @@ #!powershell -# WANT_JSON -# POWERSHELL_COMMON - # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify @@ -17,6 +14,9 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +# WANT_JSON +# POWERSHELL_COMMON + $params = Parse-Args $args; $data = 'FIXME'; diff --git a/windows/async_wrapper.ps1 b/windows/async_wrapper.ps1 index e5c4a01907e..c4627bb48ae 100644 --- a/windows/async_wrapper.ps1 +++ b/windows/async_wrapper.ps1 @@ -1,7 +1,4 @@ #!powershell -# WANT_JSON -# POWERSHELL_COMMON - # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify @@ -17,6 +14,9 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +# WANT_JSON +# POWERSHELL_COMMON + $params = Parse-Args $args; $data = 'FIXME'; diff --git a/windows/command.ps1 b/windows/command.ps1 index e5c4a01907e..c4627bb48ae 100644 --- a/windows/command.ps1 +++ b/windows/command.ps1 @@ -1,7 +1,4 @@ #!powershell -# WANT_JSON -# POWERSHELL_COMMON - # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify @@ -17,6 +14,9 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +# WANT_JSON +# POWERSHELL_COMMON + $params = Parse-Args $args; $data = 'FIXME'; diff --git a/windows/copy.ps1 b/windows/copy.ps1 index e5c4a01907e..c4627bb48ae 100644 --- a/windows/copy.ps1 +++ b/windows/copy.ps1 @@ -1,7 +1,4 @@ #!powershell -# WANT_JSON -# POWERSHELL_COMMON - # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify @@ -17,6 +14,9 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +# WANT_JSON +# POWERSHELL_COMMON + $params = Parse-Args $args; $data = 'FIXME'; diff --git a/windows/file.ps1 b/windows/file.ps1 index e5c4a01907e..c4627bb48ae 100644 --- a/windows/file.ps1 +++ b/windows/file.ps1 @@ -1,7 +1,4 @@ #!powershell -# WANT_JSON -# POWERSHELL_COMMON - # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify @@ -17,6 +14,9 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +# WANT_JSON +# POWERSHELL_COMMON + $params = Parse-Args $args; $data = 'FIXME'; diff --git a/windows/ping.ps1 b/windows/ping.ps1 index 74311119c58..6d1af14e9e3 100644 --- a/windows/ping.ps1 +++ b/windows/ping.ps1 @@ -1,7 +1,4 @@ #!powershell -# WANT_JSON -# POWERSHELL_COMMON - # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify @@ -17,6 +14,9 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +# WANT_JSON +# POWERSHELL_COMMON + $params = Parse-Args $args; $data = 'pong'; diff --git a/windows/setup.ps1 b/windows/setup.ps1 new file mode 100644 index 00000000000..9b77487c421 --- /dev/null +++ b/windows/setup.ps1 @@ -0,0 +1,71 @@ +#!powershell +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +# WANT_JSON +# POWERSHELL_COMMON + +$params = Parse-Args $args; + +$fact_path = "C:\ansible\facts.d" +If ($params.fact_path.GetType) +{ + $fact_path = $params.fact_path; +} + +$filter = "*" +If ($params.filter.GetType) +{ + $filter = $params.filter; +} + +$result = New-Object psobject @{ + ansible_facts = New-Object psobject + changed = $false +}; + +If (Test-Path $fact_path) +{ + Get-ChildItem $fact_path -Filter *.fact | Foreach-Object + { + $facts = Get-Content $_ | ConvertFrom-Json + # TODO: Need to concatentate this with $result + } +} + +$osversion = [Environment]::OSVersion + +Set-Attr $result.ansible_facts "ansible_hostname" $env:COMPUTERNAME; +Set-Attr $result.ansible_facts "ansible_fqdn" "$([System.Net.Dns]::GetHostByName((hostname)).HostName)" +Set-Attr $result.ansible_facts "ansible_system" $osversion.Platform +Set-Attr $result.ansible_facts "ansible_os_family" "Windows" +Set-Attr $result.ansible_facts "ansible_distribution" $osversion.VersionString +Set-Attr $result.ansible_facts "ansible_distribution_version" $osversion.Version.ToString() + +# Need to figure out how to filter the code. Below is a start but not implemented +#If ($filter != "*") +#{ +# $filtered = New-Object psobject; +# $result.psobject.properties | Where +# { +# $_.Name -like $filter | +# } +#} +#Else +#{ +# $filtered = $result; +#} + +echo $result | ConvertTo-Json; diff --git a/windows/slurp.ps1 b/windows/slurp.ps1 index 6f001a4924f..8fedcdc2f9e 100644 --- a/windows/slurp.ps1 +++ b/windows/slurp.ps1 @@ -1,7 +1,4 @@ #!powershell -# WANT_JSON -# POWERSHELL_COMMON - # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify @@ -17,6 +14,9 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +# WANT_JSON +# POWERSHELL_COMMON + $params = Parse-Args $args; $src = ''; diff --git a/windows/stat.ps1 b/windows/stat.ps1 index bf422858abc..50a46064d2e 100644 --- a/windows/stat.ps1 +++ b/windows/stat.ps1 @@ -1,7 +1,4 @@ #!powershell -# WANT_JSON -# POWERSHELL_COMMON - # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify @@ -17,6 +14,9 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +# WANT_JSON +# POWERSHELL_COMMON + $params = Parse-Args $args; $path = ''; diff --git a/windows/win_ping.ps1 b/windows/win_ping.ps1 index 74311119c58..6d1af14e9e3 100644 --- a/windows/win_ping.ps1 +++ b/windows/win_ping.ps1 @@ -1,7 +1,4 @@ #!powershell -# WANT_JSON -# POWERSHELL_COMMON - # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify @@ -17,6 +14,9 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +# WANT_JSON +# POWERSHELL_COMMON + $params = Parse-Args $args; $data = 'pong';