Re: [ansible-project] Getting error for ".stdout_lines" for a registered variable

2019-09-24 Thread Rakesh Parida
Hi Kai,

I could do achieve what i intended. I made the following changes using 
Jinja format and my issue solved. 
Thanks for the help. Th echanges i made was:
In the Instance id section i used the foloing formula and it worked like a 
charm.

- name: Set fact for Instance id from Tenant ID
  delegate_to: localhost
  set_fact:
id_list: "{% for item in instid.results %}
{{ item.stdout_lines[0].split()[0] }}
{% endfor %}"

- name: Set fact for Desired Instance ids
  set_fact:
 desired_instid: "{{ id_list.split() }}"

On Tuesday, September 24, 2019 at 11:33:16 PM UTC+5:30, Karl Auer wrote:
>
> Post the *complete* output of
>
> - debug:
>var: instid
>
> Posting snippets is useless.
>
>
> On Wed, Sep 25, 2019 at 3:39 AM Rakesh Parida  > wrote:
>
>> There are 11 items , i will paste the out put of one item, all others are 
>> similar, or this mail will be lengthy. SO pasting the out put of one item.
>>
>>  "_ansible_delegated_vars": {
>> "ansible_delegated_host": "localhost", 
>> "ansible_host": "localhost"
>> }, 
>> "_ansible_ignore_errors": null, 
>> "_ansible_item_label": "TOMICS2", 
>> "_ansible_item_result": true, 
>> "_ansible_no_log": false, 
>> "_ansible_parsed": true, 
>> "changed": true, 
>> "cmd": "openstack server list --all-projects 
>> --project \"ca257bcbf01745aba61edd9699cd4902\" | awk 'NR > 3 { print $2, $4 
>> }' | grep -i \"TOMICS2\"", 
>> "delta": "0:00:02.312475", 
>> "end": "2019-09-24 09:15:48.113526", 
>> "failed": false, 
>> "invocation": {
>> "module_args": {
>> "_raw_params": "openstack server list 
>> --all-projects --project \"ca257bcbf01745aba61edd9699cd4902\" | awk 'NR > 3 
>> { print $2, $4 }' | grep -i \"TOMICS2\"", 
>> "_uses_shell": true, 
>> "argv": null, 
>> "chdir": null, 
>> "creates": null, 
>> "executable": null, 
>> "removes": null, 
>> "stdin": null, 
>> "warn": true
>> }
>> }, 
>> "item": "TOMICS2", 
>> "rc": 0, 
>> "start": "2019-09-24 09:15:45.801051", 
>> "stderr": "", 
>> "stderr_lines": [], 
>> "stdout": "e8ebc5a4-17f3-4b80-a935-03164211a804 
>> TOMICS2", 
>>   *  "stdout_lines": [*
>> *"e8ebc5a4-17f3-4b80-a935-03164211a804 TOMICS2"*
>> ]
>> }, 
>>
>>
>>
>> On Tuesday, September 24, 2019 at 10:55:00 PM UTC+5:30, Karl Auer wrote:
>>>
>>> What is the *complete* output from a debug of instid?
>>>
>>>
>>> Regards, K.
>>>
>>>
>>> On Wed, Sep 25, 2019 at 3:06 AM Rakesh Parida  
>>> wrote:
>>>
 Hi,

 I have  playbook to retrieve the Instance id of Openstack nodes.Now 
 everything works fine but the resgitered value for instid.stdout_lines 
 gets 
 an undefined error.
 *The error was: 'dict object' has no attribute 'stdout_lines'* .. but 
 when i debug the complete registered variable instid i see stdout_lines. 
 but why its failing when i debug it using instid.stdout_lines

  "item": "TOMCS2", 
 "rc": 0, 
 "start": "2019-09-24 09:15:45.801051", 
 "stderr": "", 
 "stderr_lines": [], 
 "stdout": "e8ebc5a4-17f3-4b80-a935-03164211a804 
 TOMICS2", 
 *"stdout_lines": [*
 *"e8ebc5a4-17f3-4b80-a935-03164211a804 TOMCS2"*


 - hosts: nodes[0]
   gather_facts: false
   tasks:
 - name: Collect  Hostnames
   set_fact:
  host_lists: "{{ 
 hostvars[inventory_hostname]['groups']['nodes'] }}"

 - name: Create Hostname as per the Name in openstack names
   set_fact:
  fact: '{{ (["TOM"] * 
 host_lists|length)|zip(host_lists)|map("join")|list}}'

 - name: Debug the required list
   debug:
 msg: "{{ fact }}"


 - hosts: 127.0.0.1
   gather_facts: false
   tasks:
 - name: Retrieve tenantID
   shell: openstack project list | awk '/ TOM / { print $2 }'
   register: tenantid

  - name: Retrieve instance id from tenant
shell: openstack server list --all-projects --project "{{ 
 tenantid.stdout }}" | awk 'NR > 3 { print $2, $4 }' | grep -i "{{ item }}"
   

Re: [ansible-project] Getting error for ".stdout_lines" for a registered variable

2019-09-24 Thread Karl Auer
Post the *complete* output of

- debug:
   var: instid

Posting snippets is useless.


On Wed, Sep 25, 2019 at 3:39 AM Rakesh Parida 
wrote:

> There are 11 items , i will paste the out put of one item, all others are
> similar, or this mail will be lengthy. SO pasting the out put of one item.
>
>  "_ansible_delegated_vars": {
> "ansible_delegated_host": "localhost",
> "ansible_host": "localhost"
> },
> "_ansible_ignore_errors": null,
> "_ansible_item_label": "TOMICS2",
> "_ansible_item_result": true,
> "_ansible_no_log": false,
> "_ansible_parsed": true,
> "changed": true,
> "cmd": "openstack server list --all-projects --project
> \"ca257bcbf01745aba61edd9699cd4902\" | awk 'NR > 3 { print $2, $4 }' | grep
> -i \"TOMICS2\"",
> "delta": "0:00:02.312475",
> "end": "2019-09-24 09:15:48.113526",
> "failed": false,
> "invocation": {
> "module_args": {
> "_raw_params": "openstack server list
> --all-projects --project \"ca257bcbf01745aba61edd9699cd4902\" | awk 'NR > 3
> { print $2, $4 }' | grep -i \"TOMICS2\"",
> "_uses_shell": true,
> "argv": null,
> "chdir": null,
> "creates": null,
> "executable": null,
> "removes": null,
> "stdin": null,
> "warn": true
> }
> },
> "item": "TOMICS2",
> "rc": 0,
> "start": "2019-09-24 09:15:45.801051",
> "stderr": "",
> "stderr_lines": [],
> "stdout": "e8ebc5a4-17f3-4b80-a935-03164211a804
> TOMICS2",
>   *  "stdout_lines": [*
> *"e8ebc5a4-17f3-4b80-a935-03164211a804 TOMICS2"*
> ]
> },
>
>
>
> On Tuesday, September 24, 2019 at 10:55:00 PM UTC+5:30, Karl Auer wrote:
>>
>> What is the *complete* output from a debug of instid?
>>
>>
>> Regards, K.
>>
>>
>> On Wed, Sep 25, 2019 at 3:06 AM Rakesh Parida 
>> wrote:
>>
>>> Hi,
>>>
>>> I have  playbook to retrieve the Instance id of Openstack nodes.Now
>>> everything works fine but the resgitered value for instid.stdout_lines gets
>>> an undefined error.
>>> *The error was: 'dict object' has no attribute 'stdout_lines'* .. but
>>> when i debug the complete registered variable instid i see stdout_lines.
>>> but why its failing when i debug it using instid.stdout_lines
>>>
>>>  "item": "TOMCS2",
>>> "rc": 0,
>>> "start": "2019-09-24 09:15:45.801051",
>>> "stderr": "",
>>> "stderr_lines": [],
>>> "stdout": "e8ebc5a4-17f3-4b80-a935-03164211a804
>>> TOMICS2",
>>> *"stdout_lines": [*
>>> *"e8ebc5a4-17f3-4b80-a935-03164211a804 TOMCS2"*
>>>
>>>
>>> - hosts: nodes[0]
>>>   gather_facts: false
>>>   tasks:
>>> - name: Collect  Hostnames
>>>   set_fact:
>>>  host_lists: "{{ hostvars[inventory_hostname]['groups']['nodes']
>>> }}"
>>>
>>> - name: Create Hostname as per the Name in openstack names
>>>   set_fact:
>>>  fact: '{{ (["TOM"] *
>>> host_lists|length)|zip(host_lists)|map("join")|list}}'
>>>
>>> - name: Debug the required list
>>>   debug:
>>> msg: "{{ fact }}"
>>>
>>>
>>> - hosts: 127.0.0.1
>>>   gather_facts: false
>>>   tasks:
>>> - name: Retrieve tenantID
>>>   shell: openstack project list | awk '/ TOM / { print $2 }'
>>>   register: tenantid
>>>
>>>  - name: Retrieve instance id from tenant
>>>shell: openstack server list --all-projects --project "{{
>>> tenantid.stdout }}" | awk 'NR > 3 { print $2, $4 }' | grep -i "{{ item }}"
>>>with_items: "{{ hostvars[groups['nodes'][0]]['fact'] }}"
>>>register: instid
>>>
>>> - name: Debug Instance id and Tennat id
>>>   delegate_to: localhost
>>>   debug:
>>> msg:
>>>  - "Tenant ID:"
>>>  - "{{ tenantid.stdout }}"
>>>  - "==="
>>>  - "Instance ID of the VMs in TOM
>>>  - "{{ instid.stdout_lines}}"
>>>
>>> --
>>> 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 ansible...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/cc57f323-5d44-4b9b-97e9-ccc1e9f19542%40googlegroups.com
>>> 

Re: [ansible-project] Getting error for ".stdout_lines" for a registered variable

2019-09-24 Thread Kai Stian Olstad
On 24.09.2019 19:48, Rakesh Parida wrote:
> Hi Kai,
> 
> I had already tried it it gives me o/p as same as :
> debug:
>  msg: {{ instid }}
> 
> Both the o/ps are similar.
> 
> Now  i want the stdout_lines for each item as my desired o/p
> something like:
> e8ebc5a4-17f3-4b80-a935-03164211a804 TOMICS2
> 7865dvgsf-17f3-4b80-a935-03164211a804 TOMICS1
> abc12345g-17f3-4b80-a935-03164211a804 TOMIAS2

As I wrote instid contains a results which is a list so you need to loop over 
it to get the individual results.

- debug: msg="{{ item.stdout }}"
  with_items: "{{ instid.results }}"

-- 
Kai Stian Olstad

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/94242458-ca59-cb83-ad99-27b7ba3a8fa6%40olstad.com.


Re: [ansible-project] Getting error for ".stdout_lines" for a registered variable

2019-09-24 Thread Rakesh Parida
Hi Kai,

I had already tried it it gives me o/p as same as :
debug:
msg: {{ instid }}

Both the o/ps are similar.

Now  i want the stdout_lines for each item as my desired o/p
something like:
e8ebc5a4-17f3-4b80-a935-03164211a804 TOMICS2
7865dvgsf-17f3-4b80-a935-03164211a804 TOMICS1
abc12345g-17f3-4b80-a935-03164211a804 TOMIAS2

On Tuesday, September 24, 2019 at 11:05:06 PM UTC+5:30, Kai Stian Olstad 
wrote:
>
> On 24.09.2019 19:06, Rakesh Parida wrote: 
> >   - name: Retrieve instance id from tenant 
> > shell: openstack server list --all-projects --project "{{ 
> > tenantid.stdout }}" | awk 'NR > 3 { print $2, $4 }' | grep -i "{{ item 
> }}" 
> > with_items: "{{ hostvars[groups['nodes'][0]]['fact'] }}" 
> > register: instid 
> > 
> >  - name: Debug Instance id and Tennat id 
> >delegate_to: localhost 
> >debug: 
> >  msg: 
> >   - "Tenant ID:" 
> >   - "{{ tenantid.stdout }}" 
> >   - "===" 
> >   - "Instance ID of the VMs in TOM 
> >   - "{{ instid.stdout_lines}}" 
>
> When using register with with_items/loop you'll have instid.results which 
> is a list where each item contain the output for each command. 
>
> When you get errors like this always run a 
>   - debug: var=instid 
>
> -- 
> Kai Stian Olstad 
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/50aaf43a-f2b3-48a0-bff5-651e8fd78b67%40googlegroups.com.


Re: [ansible-project] Getting error for ".stdout_lines" for a registered variable

2019-09-24 Thread Rakesh Parida
There are 11 items , i will paste the out put of one item, all others are 
similar, or this mail will be lengthy. SO pasting the out put of one item.

 "_ansible_delegated_vars": {
"ansible_delegated_host": "localhost", 
"ansible_host": "localhost"
}, 
"_ansible_ignore_errors": null, 
"_ansible_item_label": "TOMICS2", 
"_ansible_item_result": true, 
"_ansible_no_log": false, 
"_ansible_parsed": true, 
"changed": true, 
"cmd": "openstack server list --all-projects --project 
\"ca257bcbf01745aba61edd9699cd4902\" | awk 'NR > 3 { print $2, $4 }' | grep 
-i \"TOMICS2\"", 
"delta": "0:00:02.312475", 
"end": "2019-09-24 09:15:48.113526", 
"failed": false, 
"invocation": {
"module_args": {
"_raw_params": "openstack server list 
--all-projects --project \"ca257bcbf01745aba61edd9699cd4902\" | awk 'NR > 3 
{ print $2, $4 }' | grep -i \"TOMICS2\"", 
"_uses_shell": true, 
"argv": null, 
"chdir": null, 
"creates": null, 
"executable": null, 
"removes": null, 
"stdin": null, 
"warn": true
}
}, 
"item": "TOMICS2", 
"rc": 0, 
"start": "2019-09-24 09:15:45.801051", 
"stderr": "", 
"stderr_lines": [], 
"stdout": "e8ebc5a4-17f3-4b80-a935-03164211a804 
TOMICS2", 
  *  "stdout_lines": [*
*"e8ebc5a4-17f3-4b80-a935-03164211a804 TOMICS2"*
]
}, 



On Tuesday, September 24, 2019 at 10:55:00 PM UTC+5:30, Karl Auer wrote:
>
> What is the *complete* output from a debug of instid?
>
>
> Regards, K.
>
>
> On Wed, Sep 25, 2019 at 3:06 AM Rakesh Parida  > wrote:
>
>> Hi,
>>
>> I have  playbook to retrieve the Instance id of Openstack nodes.Now 
>> everything works fine but the resgitered value for instid.stdout_lines gets 
>> an undefined error.
>> *The error was: 'dict object' has no attribute 'stdout_lines'* .. but 
>> when i debug the complete registered variable instid i see stdout_lines. 
>> but why its failing when i debug it using instid.stdout_lines
>>
>>  "item": "TOMCS2", 
>> "rc": 0, 
>> "start": "2019-09-24 09:15:45.801051", 
>> "stderr": "", 
>> "stderr_lines": [], 
>> "stdout": "e8ebc5a4-17f3-4b80-a935-03164211a804 
>> TOMICS2", 
>> *"stdout_lines": [*
>> *"e8ebc5a4-17f3-4b80-a935-03164211a804 TOMCS2"*
>>
>>
>> - hosts: nodes[0]
>>   gather_facts: false
>>   tasks:
>> - name: Collect  Hostnames
>>   set_fact:
>>  host_lists: "{{ hostvars[inventory_hostname]['groups']['nodes'] 
>> }}"
>>
>> - name: Create Hostname as per the Name in openstack names
>>   set_fact:
>>  fact: '{{ (["TOM"] * 
>> host_lists|length)|zip(host_lists)|map("join")|list}}'
>>
>> - name: Debug the required list
>>   debug:
>> msg: "{{ fact }}"
>>
>>
>> - hosts: 127.0.0.1
>>   gather_facts: false
>>   tasks:
>> - name: Retrieve tenantID
>>   shell: openstack project list | awk '/ TOM / { print $2 }'
>>   register: tenantid
>>
>>  - name: Retrieve instance id from tenant
>>shell: openstack server list --all-projects --project "{{ 
>> tenantid.stdout }}" | awk 'NR > 3 { print $2, $4 }' | grep -i "{{ item }}"
>>with_items: "{{ hostvars[groups['nodes'][0]]['fact'] }}"
>>register: instid
>>
>> - name: Debug Instance id and Tennat id
>>   delegate_to: localhost
>>   debug:
>> msg:
>>  - "Tenant ID:"
>>  - "{{ tenantid.stdout }}"
>>  - "==="
>>  - "Instance ID of the VMs in TOM
>>  - "{{ instid.stdout_lines}}"
>>
>> -- 
>> 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 ansible...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/cc57f323-5d44-4b9b-97e9-ccc1e9f19542%40googlegroups.com
>>  
>> 
>> .
>>
>
>
> -- 
> Karl Auer
>
> Email  : ka...@2pisoftware.com 
> Website: http://2pisoftware.com
>
> GPG/PGP : 301B 1F4E 624D AD99 242

Re: [ansible-project] Getting error for ".stdout_lines" for a registered variable

2019-09-24 Thread Kai Stian Olstad
On 24.09.2019 19:06, Rakesh Parida wrote:
>   - name: Retrieve instance id from tenant
> shell: openstack server list --all-projects --project "{{
> tenantid.stdout }}" | awk 'NR > 3 { print $2, $4 }' | grep -i "{{ item }}"
> with_items: "{{ hostvars[groups['nodes'][0]]['fact'] }}"
> register: instid
> 
>  - name: Debug Instance id and Tennat id
>delegate_to: localhost
>debug:
>  msg:
>   - "Tenant ID:"
>   - "{{ tenantid.stdout }}"
>   - "==="
>   - "Instance ID of the VMs in TOM
>   - "{{ instid.stdout_lines}}"

When using register with with_items/loop you'll have instid.results which is a 
list where each item contain the output for each command.

When you get errors like this always run a
  - debug: var=instid

-- 
Kai Stian Olstad

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ad12016d-c5e5-c89b-c225-1d6d99edaedc%40olstad.com.


Re: [ansible-project] Getting error for ".stdout_lines" for a registered variable

2019-09-24 Thread Karl Auer
What is the *complete* output from a debug of instid?


Regards, K.


On Wed, Sep 25, 2019 at 3:06 AM Rakesh Parida 
wrote:

> Hi,
>
> I have  playbook to retrieve the Instance id of Openstack nodes.Now
> everything works fine but the resgitered value for instid.stdout_lines gets
> an undefined error.
> *The error was: 'dict object' has no attribute 'stdout_lines'* .. but
> when i debug the complete registered variable instid i see stdout_lines.
> but why its failing when i debug it using instid.stdout_lines
>
>  "item": "TOMCS2",
> "rc": 0,
> "start": "2019-09-24 09:15:45.801051",
> "stderr": "",
> "stderr_lines": [],
> "stdout": "e8ebc5a4-17f3-4b80-a935-03164211a804
> TOMICS2",
> *"stdout_lines": [*
> *"e8ebc5a4-17f3-4b80-a935-03164211a804 TOMCS2"*
>
>
> - hosts: nodes[0]
>   gather_facts: false
>   tasks:
> - name: Collect  Hostnames
>   set_fact:
>  host_lists: "{{ hostvars[inventory_hostname]['groups']['nodes']
> }}"
>
> - name: Create Hostname as per the Name in openstack names
>   set_fact:
>  fact: '{{ (["TOM"] *
> host_lists|length)|zip(host_lists)|map("join")|list}}'
>
> - name: Debug the required list
>   debug:
> msg: "{{ fact }}"
>
>
> - hosts: 127.0.0.1
>   gather_facts: false
>   tasks:
> - name: Retrieve tenantID
>   shell: openstack project list | awk '/ TOM / { print $2 }'
>   register: tenantid
>
>  - name: Retrieve instance id from tenant
>shell: openstack server list --all-projects --project "{{
> tenantid.stdout }}" | awk 'NR > 3 { print $2, $4 }' | grep -i "{{ item }}"
>with_items: "{{ hostvars[groups['nodes'][0]]['fact'] }}"
>register: instid
>
> - name: Debug Instance id and Tennat id
>   delegate_to: localhost
>   debug:
> msg:
>  - "Tenant ID:"
>  - "{{ tenantid.stdout }}"
>  - "==="
>  - "Instance ID of the VMs in TOM
>  - "{{ instid.stdout_lines}}"
>
> --
> 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 ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/cc57f323-5d44-4b9b-97e9-ccc1e9f19542%40googlegroups.com
> 
> .
>


-- 
Karl Auer

Email  : ka...@2pisoftware.com
Website: http://2pisoftware.com

GPG/PGP : 301B 1F4E 624D AD99 242C 7A68 EC24 7113 E854 4A4E
Previous: 958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CA%2B%2BT08QYC5y4gQJ5OtthTRVZaS5TmRU7qxtoCjrJRNq3w8Y%2Bew%40mail.gmail.com.