Edit json file using ansible









up vote
0
down vote

favorite












I am trying to edit a particular JSON file using Ansible. The file is present in remote servers which have to be logged in using LDAP authentication.



The file path is /etc/sensu/conf.d/client.json



and the line that I want to edit is as follows:



"subscriptions": ["Nginx", "Primus", "B2B", "Docker_Process_Check", "EBS", "base"],


I want to add one more value ("filebeat") in that line which after that should look like



"subscriptions": ["Nginx", "Primus", "B2B", "Docker_Process_Check", "EBS", "base","filebeat"],









share|improve this question









New contributor




Antarjyoti Sen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • What did you try so far? What is your operating system?
    – Laurenz Albe
    19 hours ago










  • It is mac os..But I am trying to update the same in multiple ec2 linux instances..I was trying with lineinfile inbuilt module but that does not work for json I guess..Any inbuilt module present for doing the same.
    – Antarjyoti Sen
    17 hours ago















up vote
0
down vote

favorite












I am trying to edit a particular JSON file using Ansible. The file is present in remote servers which have to be logged in using LDAP authentication.



The file path is /etc/sensu/conf.d/client.json



and the line that I want to edit is as follows:



"subscriptions": ["Nginx", "Primus", "B2B", "Docker_Process_Check", "EBS", "base"],


I want to add one more value ("filebeat") in that line which after that should look like



"subscriptions": ["Nginx", "Primus", "B2B", "Docker_Process_Check", "EBS", "base","filebeat"],









share|improve this question









New contributor




Antarjyoti Sen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • What did you try so far? What is your operating system?
    – Laurenz Albe
    19 hours ago










  • It is mac os..But I am trying to update the same in multiple ec2 linux instances..I was trying with lineinfile inbuilt module but that does not work for json I guess..Any inbuilt module present for doing the same.
    – Antarjyoti Sen
    17 hours ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying to edit a particular JSON file using Ansible. The file is present in remote servers which have to be logged in using LDAP authentication.



The file path is /etc/sensu/conf.d/client.json



and the line that I want to edit is as follows:



"subscriptions": ["Nginx", "Primus", "B2B", "Docker_Process_Check", "EBS", "base"],


I want to add one more value ("filebeat") in that line which after that should look like



"subscriptions": ["Nginx", "Primus", "B2B", "Docker_Process_Check", "EBS", "base","filebeat"],









share|improve this question









New contributor




Antarjyoti Sen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I am trying to edit a particular JSON file using Ansible. The file is present in remote servers which have to be logged in using LDAP authentication.



The file path is /etc/sensu/conf.d/client.json



and the line that I want to edit is as follows:



"subscriptions": ["Nginx", "Primus", "B2B", "Docker_Process_Check", "EBS", "base"],


I want to add one more value ("filebeat") in that line which after that should look like



"subscriptions": ["Nginx", "Primus", "B2B", "Docker_Process_Check", "EBS", "base","filebeat"],






ansible file-manipulation






share|improve this question









New contributor




Antarjyoti Sen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Antarjyoti Sen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 14 hours ago









James Z

11.1k71735




11.1k71735






New contributor




Antarjyoti Sen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 19 hours ago









Antarjyoti Sen

1




1




New contributor




Antarjyoti Sen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Antarjyoti Sen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Antarjyoti Sen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • What did you try so far? What is your operating system?
    – Laurenz Albe
    19 hours ago










  • It is mac os..But I am trying to update the same in multiple ec2 linux instances..I was trying with lineinfile inbuilt module but that does not work for json I guess..Any inbuilt module present for doing the same.
    – Antarjyoti Sen
    17 hours ago

















  • What did you try so far? What is your operating system?
    – Laurenz Albe
    19 hours ago










  • It is mac os..But I am trying to update the same in multiple ec2 linux instances..I was trying with lineinfile inbuilt module but that does not work for json I guess..Any inbuilt module present for doing the same.
    – Antarjyoti Sen
    17 hours ago
















What did you try so far? What is your operating system?
– Laurenz Albe
19 hours ago




What did you try so far? What is your operating system?
– Laurenz Albe
19 hours ago












It is mac os..But I am trying to update the same in multiple ec2 linux instances..I was trying with lineinfile inbuilt module but that does not work for json I guess..Any inbuilt module present for doing the same.
– Antarjyoti Sen
17 hours ago





It is mac os..But I am trying to update the same in multiple ec2 linux instances..I was trying with lineinfile inbuilt module but that does not work for json I guess..Any inbuilt module present for doing the same.
– Antarjyoti Sen
17 hours ago













1 Answer
1






active

oldest

votes

















up vote
0
down vote













AFAIK there's still no builtin module for JSON manipulation.



Either use 3rd-party module (like ghetto-json),



or make a complex regular expression with replace module (i.e. search for "subscriptions": [<...>] and place ,"filebeat" just before closing ]. You can use regex101.com to craft and test required expression.



Please also inspect this answer for additional info.






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    Antarjyoti Sen is a new contributor. Be nice, and check out our Code of Conduct.









     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222124%2fedit-json-file-using-ansible%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    AFAIK there's still no builtin module for JSON manipulation.



    Either use 3rd-party module (like ghetto-json),



    or make a complex regular expression with replace module (i.e. search for "subscriptions": [<...>] and place ,"filebeat" just before closing ]. You can use regex101.com to craft and test required expression.



    Please also inspect this answer for additional info.






    share|improve this answer
























      up vote
      0
      down vote













      AFAIK there's still no builtin module for JSON manipulation.



      Either use 3rd-party module (like ghetto-json),



      or make a complex regular expression with replace module (i.e. search for "subscriptions": [<...>] and place ,"filebeat" just before closing ]. You can use regex101.com to craft and test required expression.



      Please also inspect this answer for additional info.






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        AFAIK there's still no builtin module for JSON manipulation.



        Either use 3rd-party module (like ghetto-json),



        or make a complex regular expression with replace module (i.e. search for "subscriptions": [<...>] and place ,"filebeat" just before closing ]. You can use regex101.com to craft and test required expression.



        Please also inspect this answer for additional info.






        share|improve this answer












        AFAIK there's still no builtin module for JSON manipulation.



        Either use 3rd-party module (like ghetto-json),



        or make a complex regular expression with replace module (i.e. search for "subscriptions": [<...>] and place ,"filebeat" just before closing ]. You can use regex101.com to craft and test required expression.



        Please also inspect this answer for additional info.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 19 hours ago









        Konstantin Suvorov

        34.6k43676




        34.6k43676




















            Antarjyoti Sen is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            Antarjyoti Sen is a new contributor. Be nice, and check out our Code of Conduct.












            Antarjyoti Sen is a new contributor. Be nice, and check out our Code of Conduct.











            Antarjyoti Sen is a new contributor. Be nice, and check out our Code of Conduct.













             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222124%2fedit-json-file-using-ansible%23new-answer', 'question_page');

            );

            Post as a guest














































































            這個網誌中的熱門文章

            How to combine Bézier curves to a surface?

            Mutual Information Always Non-negative

            Why am i infinitely getting the same tweet with the Twitter Search API?