Is there any other approach to achieve this?
On Wed, 24 Mar, 2021, 2:20 PM Sakshi Rathore, <[email protected]>
wrote:
> i have written a python script to list all the ips for master nodes and
> worker nodes with respect to cluster name.
> but i am not sure how to do it for nested ip addresses.
>
> i have also tried converting json to csv and then fetch the ip addresses
> from this using this approach i am getting csv file but not getting the
> required data (ip addresses for master and worker nodes ) in dynamic
> inventory.
>
> on other hand i am also trying using jsonquery as follows but it gives me
> 2 set of lists and from this my requirement is to get only one list for
> master and worker nodes:
> - name: get auth-token from ccp
> uri:
> url: '{{ ccp_url }}/system/login'
> return_content: yes
> body:
> username: '{{ ccp_user }}'
> password: '{{ ccp_pass }}'
> body_format: form-urlencoded
> validate_certs: no
> method: POST
> headers:
> Content-Type: application/x-www-form-urlencoded
> register: token
>
> - name: printtoken
> debug:
> msg: "{{ token.x_auth_token }}"
>
> - name: create list of all CCP-Nodes
> uri:
> url: '{{ ccp_url }}/clusters'
> validate_certs: no
> method: GET
> dest: ../cluster.txt
> headers:
> Content-Type: application/x-www-form-urlencoded
> x-auth-token: '{{ token.x_auth_token }}'
> register: jsoncontent
>
>
> - name: master ip list from json content
> debug: msg="{{ input | json_query(jmesquery) }}"
> #debug: msg="{{ input1 | json_query(jmesquery1) }}"
> #copy: content="{{ input | json_query(jmesquery) || input1 |
> json_query(jmesquery1) }}" dest=../ip_address.txt
> vars:
> input : "{{ lookup('template', '../cluster.txt') }}"
> target: "{{ input | json_query(jmesquery) }}"
> jmesquery: "[*].master_group[].nodes[].private_ip"
> input1 : "{{ lookup('template', '../cluster.txt') }}"
> target1: "{{ input1 | json_query(jmesquery1) }}"
> jmesquery1: "[*].node_groups[].nodes[].private_ip"
>
> - name: worker ip list from json content
> debug: msg="{{ input1 | json_query(jmesquery1) }}"
> #debug: msg="{{ input1 | json_query ("
> [*].node_groups[].nodes[].private_ip ||
> [*].master_group[].nodes[].private_ip ") }}"
> #copy: content="{{ input1 | json_query(jmesquery1) }}"
> dest=../ip_address1.txt
> vars:
> input1 : "{{ lookup('template', '../cluster.txt') }}"
> target1: "{{ input1 | json_query(jmesquery1) }}
> jmesquery1: "[*].node_groups[].nodes[].private_ip"
>
> On Wed, Mar 24, 2021 at 2:07 PM Abhijeet Kasurde <[email protected]>
> wrote:
>
>> What have you tried so far and what is required output?
>>
>> On Wed, Mar 24, 2021 at 6:29 PM Sakshi Rathore <
>> [email protected]> wrote:
>>
>>> please find attached json file.
>>>
>>> On Wed, Mar 24, 2021 at 1:03 PM Abhijeet Kasurde <[email protected]>
>>> wrote:
>>>
>>>> Please provide a sample complex json file.
>>>>
>>>> On Wed, Mar 24, 2021 at 5:29 PM Sakshi Rathore <
>>>> [email protected]> wrote:
>>>>
>>>>> hi all,
>>>>>
>>>>> i am having a complex json file with nested json structure. how can i
>>>>> create dynamic inventory using json file into ansible.
>>>>>
>>>>> i have tried many tutorials but due to compley json structure i am not
>>>>> getting it completely.
>>>>>
>>>>> please advise.
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Ansible Project" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/ansible-project/848dadea-ba06-4019-872c-7d07c5b7c845n%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/ansible-project/848dadea-ba06-4019-872c-7d07c5b7c845n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>>
>>>>
>>>> --
>>>> Thanks,
>>>> Abhijeet Kasurde
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Ansible Project" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/ansible-project/CAFwWkHo6tXWGc5EZg%3Der-C4czkYU9YUGYKXyYb-56bZRdnfz%2BA%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/ansible-project/CAFwWkHo6tXWGc5EZg%3Der-C4czkYU9YUGYKXyYb-56bZRdnfz%2BA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Ansible Project" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/CAJeB3MPvO3zKCb-8oM4u2vFPytRZb%3D6LZ9NH6o6MYT0Et8iFHg%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/ansible-project/CAJeB3MPvO3zKCb-8oM4u2vFPytRZb%3D6LZ9NH6o6MYT0Et8iFHg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
>>
>> --
>> Thanks,
>> Abhijeet Kasurde
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Ansible Project" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/ansible-project/IOyUATc2x1g/unsubscribe
>> .
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/CAFwWkHrfe%2B24qwQZ5KqdNdehF4KNPZKnT_erfhWhWR_V6rG25g%40mail.gmail.com
>> <https://groups.google.com/d/msgid/ansible-project/CAFwWkHrfe%2B24qwQZ5KqdNdehF4KNPZKnT_erfhWhWR_V6rG25g%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAJeB3MNCD3aJ07jbLuoQ_hoyEuKjS1pspE9gKr-apn6BDHj3fQ%40mail.gmail.com.