Page 1 sur 1

[RESOLU] Déployer Script sur WAPT

Posté : 05 déc. 2024 - 15:53
par soif_deconnaissances
- Version de WAPT installée : 2.5
- OS du serveur : Linux 22.04
- OS de la machine d'administration/création des paquets : Windows serveur 2016

Bonjour,
Je suis sous la version Discovery et j'aimerais savoir s’il existe un moyen pour déployer des scripts (.ps1, .bat, etc.) sur les machines agents ? Si oui, il y a un doc pour me guider car je ne l'ai pas trouvé sur le Net.
Je vous remercie !

Re: Déployer Script sur WAPT

Posté : 06 déc. 2024 - 14:17
par blemoigne
Bonjour,
ça va s'exécuter avec les commandes run() ou run_not_fatal() pour les bat, run_powershell, run_powershell_from_file() ou run_powershell_script() pour les ps1.
https://www.wapt.fr/apidoc/wapt-2.5/win ... elpers.run

Bonne journée,
Bertrand

Re: Déployer Script sur WAPT

Posté : 06 déc. 2024 - 16:53
par soif_deconnaissances
blemoigne a écrit : 06 déc. 2024 - 14:17 Bonjour,
ça va s'exécuter avec les commandes run() ou run_not_fatal() pour les bat, run_powershell, run_powershell_from_file() ou run_powershell_script() pour les ps1.
https://www.wapt.fr/apidoc/wapt-2.5/win ... elpers.run

Bonne journée,
Bertrand
Bonjour Bertrand,
Dsl si mes questions semblent être bêtes et let que les réponses paraissent évidentes pour vous.
Je suis vraiment un débutant du logiciel et j'aimerais savoir un peu plus de détails pour pouvoir déployer un script.
- Dois-je générer un modèle de paquet vide dans la console WAPT pour ce type de travail ?
- Par quel moyen (ou où) puis-je éditer un paquet via des lignes de commande ?
Je vous remercie !

Re: Déployer Script sur WAPT

Posté : 06 déc. 2024 - 18:01
par blemoigne
Déjà il faut s'assurer d'avoir installé un environnement de développement :
https://www.wapt.fr/fr/doc/wapt-create- ... pt-console

Effectivement ensuite, il faut créer un paquet vide. Par défaut le répertoire du paquet en cours de développement se met dans c:\waptdev.
Vous pourrez mettre les scripts dans le répertoire du paquet.

Bon week-end
Bertrand

Re: Déployer Script sur WAPT

Posté : 09 déc. 2024 - 16:01
par soif_deconnaissances
blemoigne a écrit : 06 déc. 2024 - 18:01 Déjà il faut s'assurer d'avoir installé un environnement de développement :
https://www.wapt.fr/fr/doc/wapt-create- ... pt-console

Effectivement ensuite, il faut créer un paquet vide. Par défaut le répertoire du paquet en cours de développement se met dans c:\waptdev.
Vous pourrez mettre les scripts dans le répertoire du paquet.

Bon week-end
Bertrand
J'ai réussi à déployer un fichier .bat avec la commande :

Code : Tout sélectionner

def install():
    run(r"mon_script.bat")
Par contre, pour le fichier powershell, le fichier du dépôt ne fonctionne pas. Voici ce que j'ai fait, vous pouvez vérifier si c'est correct ?

Code : Tout sélectionner

def install():
    run_powershell(r"mon_script.ps1")
Je vous remercie !

Re: Déployer Script sur WAPT

Posté : 09 déc. 2024 - 16:23
par fschelfaut
Bonjour,

La fonction run_powershell() attend une commande PowerShell à exécuter.
Pour exécuter un script *.ps1, il faut utiliser la fonction dédiée : run_powershell_script().

Voici quelques exemples d'utilisation :

Code : Tout sélectionner

def install():
    run_powershell_script("mon_script.ps1")
    run_powershell('Write-Host "Je suis un test"')
Toutes les fonctions utilisables dans un paquet WAPT sont documentées ici
- https://www.wapt.fr/apidoc/wapt-2.6/win ... ell_script
- https://www.wapt.fr/apidoc/wapt-2.6/win ... powershell

Flavien

Re: Déployer Script sur WAPT

Posté : 10 déc. 2024 - 11:26
par soif_deconnaissances
Bonjour,

J'ai toujours des erreurs qui concernent le déploiement des scripts .ps1 :(
Dans le package vide qui se trouve à C:\waptdev auquel j'ai placé mon fichier scripts test.ps1 :

Code : Tout sélectionner

$sourceFilePath = "\\lan.xxx.xxx\NETLOGON\GPOs\Scripts\TEST WAPT\test.txt"
$destinationFilePath = "C:\test.txt"

if (Test-Path -Path $destinationFilePath) {
    exit
} else {
    Copy-Item -Path $sourceFilePath -Destination $destinationFilePath -Force
}
Voici le code dans setup.py :

Code : Tout sélectionner

# -*- coding: utf-8 -*-
from setuphelpers import *

def install():
    run_powershell_script(r"test.ps1")
Après, j'ai créé le paquet avec la commande sous cmd :

Code : Tout sélectionner

wapt-get build-package C:\waptdev\idvet-testscript_1.0.0_x64_Windows_PROD-wapt
Sur le paquet vide, j'ai paramétré l'architecture en x64 et OS ciblés en Windows.
Lorsque je le déploie, ce code d'erreur s'affiche :

Code : Tout sélectionner

https://xxx.xxx.xxx.xxx/wapt/idvet-testscript_1.0.0-0_x64_windows_PROD.wapt : 5522 / 5522 (100%) (15 KB/s)
Erreur lors de l'installation de ['idvet-testscript(=1.0.0-0)']: erreurs dans les paquets [[PackageRequest(package='idvet-testscript',version=(Version('1.0.0.0'), 0),architectures=['x64'],locales=['fr'],maturities=['PROD'],tags=['windows-10', 'win-10', 'w-10', 'windows10', 'win10', 'w10', 'windows', 'win', 'w'],min_os_version=Version('10.0.19045'),max_os_version=Version('10.0.19045')), PackageEntry('idvet-testscript','1.0.0-0' architecture='x64',maturity='PROD',target_os='windows'), 'Traceback (most recent call last):\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1237, in run_powershell\n    return json.loads(\'\\n\'.join(lines))\n  File "json\\__init__.py", line 357, in loads\n  File "json\\decoder.py", line 337, in decode\n  File "json\\decoder.py", line 355, in raw_decode\njson.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 5348, in install\n    result = self.install_wapt(p.localpath,\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 4328, in install_wapt\n    raise e\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 4235, in install_wapt\n    exitstatus = setup.install()\n  File "C:\\Windows\\TEMP\\wapt8smn47lj\\setup.py", line 5, in install\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1266, in run_powershell_script\n    return run_powershell(\'(invoke-expression -Command "%s")\' % script_filename, output_format, **kwargs)\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1239, in run_powershell\n    raise ValueError(\'%s returned non json data:\\n%s\\n%s\' % (cmd, result, e))\nValueError: "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -OutputFormat text -EncodedCommand "JABQAHIAbwBnAHIAZQBzAHMAUAByAGUAZgBlAHIAZQBuAGMAZQAgAD0AIAAiAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAIgAKACgAaQBuAHYAbwBrAGUALQBlAHgAcAByAGUAcwBzAGkAbwBuACAALQBDAG8AbQBtAGEAbgBkACAAIgB0AGUAcwB0AC4AcABzADEAIgApACAAIAB8ACAAQwBvAG4AdgBlAHIAdABUAG8ALQBKAHMAbwBuACAA"  returned non json data:\n#< CLIXML\r\n<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">test.ps1 : Le terme «test.ps1» n\'est pas reconnu comme nom d\'applet de commande, fonction, fichier de script ou _x000D__x000A_</S><S S="Error">programme exécutable. Vérifiez l\'orthographe du nom, ou si un chemin d\'accès existe, vérifiez que le chemin d\'accès _x000D__x000A_</S><S S="Error">est correct et réessayez._x000D__x000A_</S><S S="Error">Au caractère Ligne:1 : 1_x000D__x000A_</S><S S="Error">+ test.ps1_x000D__x000A_</S><S S="Error">+ ~~~~~~~~_x000D__x000A_</S><S S="Error">    + CategoryInfo          : ObjectNotFound: (test.ps1:String) [], CommandNotFoundException_x000D__x000A_</S><S S="Error">    + FullyQualifiedErrorId : CommandNotFoundException_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>\nExpecting value: line 1 column 1 (char 0)\n']]
Traceback (most recent call last):
  File "<string>", line 1943, in run
  File "C:\Program Files (x86)\wapt\waptservice\waptservice_common.py", line 737, in run
    self._run()
  File "C:\Program Files (x86)\wapt\waptservice\waptservice_common.py", line 1341, in _run
    raise Exception(_('Error during install of {}: errors in packages {}').format(
Exception: Erreur lors de l'installation de ['idvet-testscript(=1.0.0-0)']: erreurs dans les paquets [[PackageRequest(package='idvet-testscript',version=(Version('1.0.0.0'), 0),architectures=['x64'],locales=['fr'],maturities=['PROD'],tags=['windows-10', 'win-10', 'w-10', 'windows10', 'win10', 'w10', 'windows', 'win', 'w'],min_os_version=Version('10.0.19045'),max_os_version=Version('10.0.19045')), PackageEntry('idvet-testscript','1.0.0-0' architecture='x64',maturity='PROD',target_os='windows'), 'Traceback (most recent call last):\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1237, in run_powershell\n    return json.loads(\'\\n\'.join(lines))\n  File "json\\__init__.py", line 357, in loads\n  File "json\\decoder.py", line 337, in decode\n  File "json\\decoder.py", line 355, in raw_decode\njson.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 5348, in install\n    result = self.install_wapt(p.localpath,\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 4328, in install_wapt\n    raise e\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 4235, in install_wapt\n    exitstatus = setup.install()\n  File "C:\\Windows\\TEMP\\wapt8smn47lj\\setup.py", line 5, in install\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1266, in run_powershell_script\n    return run_powershell(\'(invoke-expression -Command "%s")\' % script_filename, output_format, **kwargs)\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1239, in run_powershell\n    raise ValueError(\'%s returned non json data:\\n%s\\n%s\' % (cmd, result, e))\nValueError: "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -OutputFormat text -EncodedCommand "JABQAHIAbwBnAHIAZQBzAHMAUAByAGUAZgBlAHIAZQBuAGMAZQAgAD0AIAAiAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAIgAKACgAaQBuAHYAbwBrAGUALQBlAHgAcAByAGUAcwBzAGkAbwBuACAALQBDAG8AbQBtAGEAbgBkACAAIgB0AGUAcwB0AC4AcABzADEAIgApACAAIAB8ACAAQwBvAG4AdgBlAHIAdABUAG8ALQBKAHMAbwBuACAA"  returned non json data:\n#< CLIXML\r\n<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">test.ps1 : Le terme «test.ps1» n\'est pas reconnu comme nom d\'applet de commande, fonction, fichier de script ou _x000D__x000A_</S><S S="Error">programme exécutable. Vérifiez l\'orthographe du nom, ou si un chemin d\'accès existe, vérifiez que le chemin d\'accès _x000D__x000A_</S><S S="Error">est correct et réessayez._x000D__x000A_</S><S S="Error">Au caractère Ligne:1 : 1_x000D__x000A_</S><S S="Error">+ test.ps1_x000D__x000A_</S><S S="Error">+ ~~~~~~~~_x000D__x000A_</S><S S="Error">    + CategoryInfo          : ObjectNotFound: (test.ps1:String) [], CommandNotFoundException_x000D__x000A_</S><S S="Error">    + FullyQualifiedErrorId : CommandNotFoundException_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>\nExpecting value: line 1 column 1 (char 0)\n']]

Exception: Erreur lors de l'installation de ['idvet-testscript(=1.0.0-0)']: erreurs dans les paquets [[PackageRequest(package='idvet-testscript',version=(Version('1.0.0.0'), 0),architectures=['x64'],locales=['fr'],maturities=['PROD'],tags=['windows-10', 'win-10', 'w-10', 'windows10', 'win10', 'w10', 'windows', 'win', 'w'],min_os_version=Version('10.0.19045'),max_os_version=Version('10.0.19045')), PackageEntry('idvet-testscript','1.0.0-0' architecture='x64',maturity='PROD',target_os='windows'), 'Traceback (most recent call last):\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1237, in run_powershell\n    return json.loads(\'\\n\'.join(lines))\n  File "json\\__init__.py", line 357, in loads\n  File "json\\decoder.py", line 337, in decode\n  File "json\\decoder.py", line 355, in raw_decode\njson.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 5348, in install\n    result = self.install_wapt(p.localpath,\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 4328, in install_wapt\n    raise e\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 4235, in install_wapt\n    exitstatus = setup.install()\n  File "C:\\Windows\\TEMP\\wapt8smn47lj\\setup.py", line 5, in install\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1266, in run_powershell_script\n    return run_powershell(\'(invoke-expression -Command "%s")\' % script_filename, output_format, **kwargs)\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1239, in run_powershell\n    raise ValueError(\'%s returned non json data:\\n%s\\n%s\' % (cmd, result, e))\nValueError: "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -OutputFormat text -EncodedCommand "JABQAHIAbwBnAHIAZQBzAHMAUAByAGUAZgBlAHIAZQBuAGMAZQAgAD0AIAAiAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAIgAKACgAaQBuAHYAbwBrAGUALQBlAHgAcAByAGUAcwBzAGkAbwBuACAALQBDAG8AbQBtAGEAbgBkACAAIgB0AGUAcwB0AC4AcABzADEAIgApACAAIAB8ACAAQwBvAG4AdgBlAHIAdABUAG8ALQBKAHMAbwBuACAA"  returned non json data:\n#< CLIXML\r\n<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">test.ps1 : Le terme «test.ps1» n\'est pas reconnu comme nom d\'applet de commande, fonction, fichier de script ou _x000D__x000A_</S><S S="Error">programme exécutable. Vérifiez l\'orthographe du nom, ou si un chemin d\'accès existe, vérifiez que le chemin d\'accès _x000D__x000A_</S><S S="Error">est correct et réessayez._x000D__x000A_</S><S S="Error">Au caractère Ligne:1 : 1_x000D__x000A_</S><S S="Error">+ test.ps1_x000D__x000A_</S><S S="Error">+ ~~~~~~~~_x000D__x000A_</S><S S="Error">    + CategoryInfo          : ObjectNotFound: (test.ps1:String) [], CommandNotFoundException_x000D__x000A_</S><S S="Error">    + FullyQualifiedErrorId : CommandNotFoundException_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>\nExpecting value: line 1 column 1 (char 0)\n']]
Traceback (most recent call last):
  File "<string>", line 1943, in run
  File "C:\Program Files (x86)\wapt\waptservice\waptservice_common.py", line 737, in run
    self._run()
  File "C:\Program Files (x86)\wapt\waptservice\waptservice_common.py", line 1341, in _run
    raise Exception(_('Error during install of {}: errors in packages {}').format(
Exception: Erreur lors de l'installation de ['idvet-testscript(=1.0.0-0)']: erreurs dans les paquets [[PackageRequest(package='idvet-testscript',version=(Version('1.0.0.0'), 0),architectures=['x64'],locales=['fr'],maturities=['PROD'],tags=['windows-10', 'win-10', 'w-10', 'windows10', 'win10', 'w10', 'windows', 'win', 'w'],min_os_version=Version('10.0.19045'),max_os_version=Version('10.0.19045')), PackageEntry('idvet-testscript','1.0.0-0' architecture='x64',maturity='PROD',target_os='windows'), 'Traceback (most recent call last):\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1237, in run_powershell\n    return json.loads(\'\\n\'.join(lines))\n  File "json\\__init__.py", line 357, in loads\n  File "json\\decoder.py", line 337, in decode\n  File "json\\decoder.py", line 355, in raw_decode\njson.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 5348, in install\n    result = self.install_wapt(p.localpath,\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 4328, in install_wapt\n    raise e\n  File "C:\\Program Files (x86)\\wapt\\common.py", line 4235, in install_wapt\n    exitstatus = setup.install()\n  File "C:\\Windows\\TEMP\\wapt8smn47lj\\setup.py", line 5, in install\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1266, in run_powershell_script\n    return run_powershell(\'(invoke-expression -Command "%s")\' % script_filename, output_format, **kwargs)\n  File "C:\\Program Files (x86)\\wapt\\setuphelpers_windows.py", line 1239, in run_powershell\n    raise ValueError(\'%s returned non json data:\\n%s\\n%s\' % (cmd, result, e))\nValueError: "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -OutputFormat text -EncodedCommand "JABQAHIAbwBnAHIAZQBzAHMAUAByAGUAZgBlAHIAZQBuAGMAZQAgAD0AIAAiAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAIgAKACgAaQBuAHYAbwBrAGUALQBlAHgAcAByAGUAcwBzAGkAbwBuACAALQBDAG8AbQBtAGEAbgBkACAAIgB0AGUAcwB0AC4AcABzADEAIgApACAAIAB8ACAAQwBvAG4AdgBlAHIAdABUAG8ALQBKAHMAbwBuACAA"  returned non json data:\n#< CLIXML\r\n<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">test.ps1 : Le terme «test.ps1» n\'est pas reconnu comme nom d\'applet de commande, fonction, fichier de script ou _x000D__x000A_</S><S S="Error">programme exécutable. Vérifiez l\'orthographe du nom, ou si un chemin d\'accès existe, vérifiez que le chemin d\'accès _x000D__x000A_</S><S S="Error">est correct et réessayez._x000D__x000A_</S><S S="Error">Au caractère Ligne:1 : 1_x000D__x000A_</S><S S="Error">+ test.ps1_x000D__x000A_</S><S S="Error">+ ~~~~~~~~_x000D__x000A_</S><S S="Error">    + CategoryInfo          : ObjectNotFound: (test.ps1:String) [], CommandNotFoundException_x000D__x000A_</S><S S="Error">    + FullyQualifiedErrorId : CommandNotFoundException_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>\nExpecting value: line 1 column 1 (char 0)\n']]
À savoir que j'ai bien testé de lancer manuellement le script sur le PC host et il fonctionne correctement.
J'ai testé également avec l'argument run_powershell_script(r"test.ps1", output_format='text') sans savoir à quoi ça sert vraiment, le paquet est lancé sans problème mais le script ne fonctionne pas sur le host.

Vous avez des idées sur ce problème à m'aider ? Merci !

Re: Déployer Script sur WAPT

Posté : 11 déc. 2024 - 13:28
par soif_deconnaissances
Bonjour,

J'ai trouvé finalement la solution pour pouvoir lancer le script. Voici mon code sur le fichier setup.py pour pouvoir lancer le script test.ps1 qui se trouve dans le paquet WAPT vide :

Code : Tout sélectionner

# -*- coding: utf-8 -*-
from setuphelpers import *
import os  # Import du module os pour gérer les chemins

def install():
    """
    Cette fonction est exécutée lors de l'installation du paquet.
    """
    current_dir = os.getcwd()
    script_path = os.path.join(current_dir, "test.ps1")

    # Exécuter le script PowerShell
    run(f"powershell.exe -ExecutionPolicy Bypass -File \"{script_path}\"")

def uninstall():
    """
    Cette fonction peut être utilisée pour désinstaller si nécessaire.
    """
    print("Uninstallation is not defined for this package.")
Merci à vous et bonne journée !