Hi Lucy,

Thanks for the explanation. Yeah, we are trying to run the powershell
script on the puppet server through a ruby task.

script_path = "/etc/puppetlabs/code/environments/#{env_name}/modules/<module
name>/files/testfile.ps1"
      script_params = "<parameters>"
      # Execute the script
      cmd_output = `/opt/microsoft/powershell/7/pwsh -NonInteractive -File
#{script_path} #{script_params}`

Here the env_name is varied either it should be a DEVELOPMENT or PRODUCTION
, so I would like to replace the path with relative path. Please suggest if
any alternative approach is there to achieve this ?


Thanks & Regards
Cordially,

VINAYABABU KORRAPATI
+91-9703333781
vinay....@gmail.com



On Thu, Oct 22, 2020 at 10:52 PM Lucy Wyman <l...@puppet.com> wrote:

> Right, I don't think you can "import" a powershell script into a ruby
> script (at all, in any situation), but you can call the script directly
> from the ruby script with something like:
> $result = `powershell.exe ../../testfile.ps1`
>
> Having the file in your environment is mostly useful for being able to
> load it through Puppetserver and being able to reference it by
> `module/name`, but when PE goes to run the task it will upload it to the
> remote machine to a temporary directory to execute it. By specifying the
> file in your task metadata, PE will *also* upload the required file
> alongside the task file so it's in a predictable location and can be used
> on the remote system.
>
> On Thu, Oct 22, 2020 at 9:19 AM Vinay Korrapati <vinay....@gmail.com>
> wrote:
>
>> Hi Lucy,
>>
>> Thanks for your response.
>>
>> I already tried and faced the below issue while loading the file.
>>
>> `require_relative': cannot load such file -- 
>> /opt/puppetlabs/pxp-agent/spool/98/temp_task_5881-56e6-b035-6d66/files/testfile.ps1
>>
>>
>> Its pointing the different path than the expected one : 
>> etc/puppetlabs/code/environment/<env name>/modules/<modulename>/files
>>
>> Thanks & Regards
>> Cordially,
>>
>> VINAYABABU KORRAPATI
>> +91-9703333781
>> vinay....@gmail.com
>>
>>
>>
>> On Thu, Oct 22, 2020 at 8:07 PM lu...@puppet.com <l...@puppet.com> wrote:
>>
>>> Hi!
>>>
>>> You'll want to specify the .ps1 file as a 'file' in your task metadata,
>>> and then can refer to it relative to the task itself as ../../file.ps1 from
>>> your ruby task. This doc
>>> (https://puppet.com/docs/pe/2019.8/writing_tasks.html#sharing_task_code)
>>> <https://puppet.com/docs/pe/2019.8/writing_tasks.html#sharing_task_code>
>>> explains it a bit better.
>>>
>>> On Thursday, October 22, 2020 at 1:09:24 AM UTC-7 vina...@gmail.com
>>> wrote:
>>>
>>>> Hi Team,
>>>>
>>>> I have a ruby task which calls a .ps1 file on puppet master. As a part
>>>> of calling the puppet file i need to define the file path in ruby task.
>>>>
>>>>
>>>> file_path = "/etc/puppetlabs/code/environments/<env
>>>> name>/modules/<module name>/files/<file name>.ps1"
>>>>       script_params = "<parameters>"
>>>>
>>>> # execution of the script
>>>>
>>>> cmd_output = `/opt/microsoft/powershell/7/pwsh -NonInteractive -File 
>>>> #{file_path} #{script_params}`
>>>>
>>>> Can someone please suggest how to replace the file_path with relative
>>>> paths in ruby task?
>>>>
>>>> Regards
>>>> Vinay
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Puppet Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to puppet-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/puppet-users/d0a40520-bea2-4aa4-954e-132bbb73affcn%40googlegroups.com
>>> <https://groups.google.com/d/msgid/puppet-users/d0a40520-bea2-4aa4-954e-132bbb73affcn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Puppet Users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/puppet-users/Tiq9RKG0z1A/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> puppet-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/puppet-users/CAD5yi9o92qXitarAUNRpP%2BQfnC0SPZji0rKnt6p8SVhnCEw2cQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/puppet-users/CAD5yi9o92qXitarAUNRpP%2BQfnC0SPZji0rKnt6p8SVhnCEw2cQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to puppet-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/CAEoeGiJ5S8MzB_ekJcw6e3c8GciFWRtdj-a4%2BGyMyO8p48Mo3w%40mail.gmail.com
> <https://groups.google.com/d/msgid/puppet-users/CAEoeGiJ5S8MzB_ekJcw6e3c8GciFWRtdj-a4%2BGyMyO8p48Mo3w%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CAD5yi9p3%3DtTZ59OYWd9fx08-OedV826c0RY-o7A-agUzRmZ_aw%40mail.gmail.com.

Reply via email to