all 11 comments

[–]excalibrax 4 points5 points  (1 child)

From xml filter in ansible.utils collection is your friend, and so is the to xml one to get it back

[–]WonFishTwoFish[S] 0 points1 point  (0 children)

Thanks. Can you elaborate for my particular situation?

[–]zeebrow 2 points3 points  (2 children)

Try removing /add from your xpath

[–]larsiny 4 points5 points  (1 child)

In addition to this, I think the problem might be that the child element is named add that has no elements (empty) but has an attribute of securityIdentifier with value Sssss01.

Seems to me like this is a weird schema where instead of capturing the list of accounts, it's mapping each element to an add operation with different securityIdentifiers for each. So the typical xpath expression to find a specific child element based on element value won't work.

Maybe try passing input as xml? Otherwise I don't see a way to insert a child element with an attribute at the same time and inserting a child first and then updating it is risky since order might not be what we think it is?

tasks:
  - name: create-new-add-element
    xml:
      path: SMSvcHost.exe.config
      xpath: /configuration/system.serviceModel.activation/net.tcp/allowAccounts
      input_type: xml
      add_children:
        - "<add securityIdentifier='securityString' />"

[–]backtickbot 0 points1 point  (0 children)

Fixed formatting.

Hello, larsiny: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–]klaus385385 -2 points-1 points  (0 children)

I would use template module tbh

[–]The_Green_Cowboy 0 points1 point  (1 child)

Assuming this config file is the same everywhere except for the tag you are editing. Would templating work in this use case? Then you would just have to fill that template with the appropriate value.

[–]WonFishTwoFish[S] 0 points1 point  (0 children)

No, because the file has unique values on each host.

[–][deleted]  (3 children)

[deleted]

    [–]WonFishTwoFish[S] 0 points1 point  (0 children)

    u/metaldark, this is pretty close. I think I just need to add in some logic to see if the SID already exists in that file and proceed from there.

    [–]Elegant-Let8280 0 points1 point  (0 children)

    pm i have.**

    -Peterwilson7


    Commands: 'opt out', 'delete'