0

I Need help with on how to can I run PowerShell in Puppet TASK

I do not want it to run using exec cmd or Bolt.

exec { 'test':

  command   => '& C:\fail.ps1',

  provider  => powershell,

}
Anandhu Raj
  • 137
  • 1
  • 6
User
  • 43
  • 1
  • 3

1 Answers1

3

Check more on: write your first task in powershell. From the example above:

  1. In your module, have the folder tasks containing your powershell script. e.g print.ps1:
param ($message)
Write-Output "$env:computername received the message: $message"
  1. Create the print.json metadata file for the task (more on writing tasks)
{
  "description": "Print something",
  "parameters": {
    "message": {
      "type": "String",
      "description": "Something to print"
    }
  },
  "implementations": [
    {"name": "print.ps1"}
  ]
}

3.1. Run the task (with bolt).

bolt task run <your-module>::print message="hello powershell" --nodes $WINNODE --modulepath ./modules --no-ssl
The result:
Started on localhost...
Finished on localhost:
  Nano received the message: hello powershell
  {
  }
Successful on 1 node: winrm://vagrant:vagrant@localhost:55985
Ran on 1 node in 3.87 seconds

3.2. Run the task (with Puppet Console UI)

You would need to install the puppet module (where you have developed the task), by either adding it to the Puppetfile or installing it manually.

After that, you login to Puppet Console UI and run the task.

azbarcea
  • 3,323
  • 1
  • 20
  • 25
  • this would require the installation of BOLT. I do not want to use bolt. Can I create a run a task without Bolt for powershell – User Oct 17 '19 at 04:44
  • actually it doesn't need bolt. Will update my reply to show how it works without bolt. You execute as task – azbarcea Oct 17 '19 at 22:59
  • You execute as task (that instantiated in Console is a Job) ... I was just lazy to upload a screenshot, as soon as you push the module to Puppet Master, is seen in the tasks dropdown. – azbarcea Oct 17 '19 at 23:06