1

We can read yaml file within Runspace using code given in below post

How to read remote yaml file present in Azure VM from local machine using C# Runspace

But how to update existing remotely located yaml file.

I want to use code using YamlDotnet similar to one given in below post to create some new data to be updated into existing yaml file.

Build a Yaml document dynamically from c#

Update:

I have inventory yaml file with its contents as below

targets:
      - uri: 80.587.459.478
        config:
             transport: ssh
             ssh:
                 user: testlinuxuname
                 private-key: ~/ssh-key/SSH-PrivateKey.txt
                 host-key-check: false
                 run-as: root
      - uri: targetwindows123
        config:
             transport: winrm
             winrm:
                  user: testusername
                  password: testpwd
                  ssl-verify: false

Yaml file is located in remote Azure VM.

Requirement: I want to read yaml file which is present in remote azure vm from C# and check if particular uri value exists or not. If particular uri value doesn't exist, then I need to append new uri data to yaml file. So new record will be appended next to existing data in yaml file.

New record will be something like below.

- uri: targetwindows567
  config:
     transport: winrm
     winrm:
        user: testusername1
        password: testpwd1
        ssl-verify: false

I want to check if uri value targetwindows567 exists or not in yaml file. If it don't exist, then add above records into the remote yaml file.

S.Chandra Sekhar
  • 453
  • 3
  • 11
  • 22

1 Answers1

0

There are two ways u can try.

  1. To open the file over a UNC share (even the default "admin" share, if you have access to it: \servername\driveletter$\restofthepath\file)

  2. To copy the file to the local machine, edit it, and then push it back to the remote server, overwriting the old version.

For more details, you can see these post1 and post2.

I suggest you download file to local and modify it, then upload to server by powershell or C# code.

Jason Pan
  • 15,263
  • 1
  • 14
  • 29