would anyone please help me on this request?

Regards,
Suresh

On Tue, May 5, 2020 at 2:45 AM Suresh Karpurapu <[email protected]>
wrote:

> Here is my playbook, i would like to display all lines in stdout_lines in
> below format without miss. I am able to display only first 3 lines but
> host03 has more than 3 lines even it may be more lines for other hosts.
> Would anyone please help me?
>
> Required output fle:
> ==================
> host1,nfsflr01:/app01,/app,na,/etc/fstab
> host2,nfsflr02:/app02,/app02,na,/etc/fstab
> host3,nfsflr03:/app03,/app03,na,/etc/fstab
> host3,nfsflr03:/app03,/app03,na,/etc/rc.willows
> host4,nfsflr04:/app04,na,na,na
>
>
> ---
>   - name: nullify the ansible log file
>     local_action: copy content="" dest="{{ playbook_dir
> }}/logs/volmigration.log"
>     ignore_errors: true
>     run_once: True
>   - name: nullify the file content
>     local_action: copy content="" dest="{{ playbook_dir
> }}/logs/volcheck.txt"
>     ignore_errors: true
>     run_once: True
>   - name: Making the txt header information to volcheck.txt file
>     local_action:
>       module: lineinfile
>       path: "{{ playbook_dir }}/logs/volcheck.txt"
>       line: "host,python,old_path,mnt_path,new_path,map_path,csv_path"
>       state: present
>       create: yes
>     run_once: True
>   - name: Fetch the volume mounted status
>     shell: |-
>       {% if ansible_os_family == "Solaris" %}
>       grep -ws "{{ item.0 }}" /etc/vfstab|awk '{print $1}'
>       grep -ws "{{ item.0 }}" /etc/vfstab|awk '{print $3}'
>       grep -wls "{{ item.0 }}" /etc/vfstab
>       grep -wls "{{ item.0 }}" /etc/auto*|head -1|xargs grep -w "{{ item.0
> }}"|awk '{print $2}'
>       grep -wls "{{ item.0 }}" /etc/auto*|head -1|xargs grep -w "{{ item.0
> }}"|awk '{print $1}'
>       grep -wls "{{ item.0 }}" /etc/auto*|head -1
>       {%- else %}
>       grep -rws "{{ item.0 }}" /etc/fstab|awk '{print $1}'
>       grep -rws "{{ item.0 }}" /etc/fstab|awk '{print $2}'
>       grep -wls "{{ item.0 }}" /etc/fstab
>       grep -rls "{{ item.0 }}" /etc/auto*|head -1|xargs grep -w "{{ item.0
> }}"|awk '{print $3}'
>       grep -rls "{{ item.0 }}" /etc/auto*|head -1|xargs grep -w "{{ item.0
> }}"|awk '{print $1}'
>       grep -rwls "{{ item.0 }}" /etc/auto*|head -1
>       grep -rwls "{{ item.0 }}" /etc/rc*|head -1|xargs grep -w "{{ item.0
> }}"|awk '{print $6}'
>       grep -rwls "{{ item.0 }}" /etc/rc*|head -1|xargs grep -w "{{ item.0
> }}"|awk '{print $7}'
>       grep -rwls "{{ item.0 }}" /etc/rc*|head -1
>       {%- endif %}
>     with_together:
>       - "{{ var1 }}"
>     register: volchk
>     args:
>       warn: false
>     ignore_errors: true
>   - name: Making the final volcheck.txt file
>     local_action:
>       module: lineinfile
>       path: "{{ playbook_dir }}/logs/volcheck.txt"
>       line: |-
>         {% if item.stdout|length>0 %}
>         {{ inventory_hostname }},{{ ansible_python_interpreter }},{{
> item.stdout_lines[0] }},{{ item.stdout_lines[1] }},NA,{{
> item.stdout_lines[2] }},{{ item.item.0 }},
>         {%- else %}
>         {{ inventory_hostname }},{{ ansible_python_interpreter
> }},NA,NA,NA,NA,{{ item.item.0 }},
>         {%- endif %}
>       insertafter: EOF
>       state: present
>       create: yes
>     with_items: "{{ volchk.results }}"
>   - name: mark the entry of /etc/fstab and /etc/vfstab as fstab
>     replace:
>       path: "{{ playbook_dir }}/logs/volcheck.txt"
>       regexp: "{{ item.stdout_lines[2] }}"
>       replace: "fstab"
>     when: item.stdout|length>0 and (item.stdout_lines[2] |
> regex_search("/etc/fstab") or item.stdout_lines[2] |
> regex_search("/etc/vfstab"))
>     with_items: "{{ volchk.results }}"
>     delegate_to: localhost
>   - debug:
>       msg: "Final volume check file is located at {{ playbook_dir
> }}/logs/volcheck.txt"
>     delegate_to: localhost
>     run_once: true
>   - name: Send the final report email
>     local_action:
>       module: mail
>       host: host10.google.com
>       port: 25
>       to: [email protected]
>       subject: Ansible volume pre-check report
>       attach: "{{ playbook_dir }}/logs/volcheck.txt"
>     run_once: true
> ...
>
> Debug:
> Debug "volchk.result" output:
> ===============
> host1:
>      "stdout": "nfsflr01:/app01\n/app\n/etc/fstab",
>      "stdout_lines": [
>                 "nfsflr01:/app01",
>                 "/app",
>                 "/etc/fstab"
>
> host2:
>     "stdout": "nfsflr02:/app02\n/app02\n/etc/fstab",
>     "stdout_lines": [
>         "nfsflr02:/app02",
>         "/app02",
>         "/etc/fstab"
> host3:
>      "stdout":
> "nfsflr03:/app03\n/app03\n/etc/fstab\nnfsflr03:/app03\n/app03\n/etc/rc.willows",
>      "stdout_lines": [
>          "nfsflr03:/app03",
>          "/app03",
>          "/etc/fstab",
>          "nfsflr03:/app03",
>          "/app03",
>          "/etc/rc.willows"
>
> On Mon, May 4, 2020 at 2:57 PM Suresh Karpurapu <
> [email protected]> wrote:
>
>> Hi Sai Stian,
>>
>> This syntax would be helpful but i may be using in wrong way as i am
>> getting below errors. Please help on fixing the issue.
>>
>>   - name: debug with with sequence
>>     debug:
>>       msg:"{{ volchk[item.stdout | int] }},{{ volchk[item.stdout | int +
>> 1] }},{{ volchk[item.stdout | int + 2] }}"
>>     with_sequence: start=0 end={{ (volchk | length)-1 }} stride=3
>> *error:*
>> FAILED! => {"msg": "The task includes an option with an undefined
>> variable. The error was: 'ansible.utils.unsafe_proxy.AnsibleUnsafeBytes
>> object' has no attribute 'stdout'\n\nThe error appears to be in
>> '/suresh/suresh_playbooks/nfsvolmigration/roles/mountcheck/tasks/volcheck.yml':
>> line 44, column 5, but may\nbe elsewhere in the file depending on the exact
>> syntax problem.\n\nThe offending line appears to be:\n\n    ignore_errors:
>> true\n  - name: debug with with sequence\n    ^ here\n"}
>>
>> Debug "volchk.result" output:
>> ===============
>> host1:
>>      "stdout": "nfsflr01:/app01\n/app\n/etc/fstab",
>>      "stdout_lines": [
>>                 "nfsflr01:/app01",
>>                 "/app",
>>                 "/etc/fstab"
>>
>> host2:
>>     "stdout": "nfsflr02:/app02\n/app02\n/etc/fstab",
>>     "stdout_lines": [
>>         "nfsflr02:/app02",
>>         "/app02",
>>         "/etc/fstab"
>> host3:
>>      "stdout":
>> "nfsflr03:/app03\n/app03\n/etc/fstab\nnfsflr03:/app03\n/app03\n/etc/rc.willows",
>>      "stdout_lines": [
>>          "nfsflr03:/app03",
>>          "/app03",
>>          "/etc/fstab",
>>          "nfsflr03:/app03",
>>          "/app03",
>>          "/etc/rc.willows"
>>
>> Regards,
>> Suresh
>>
>>
>>
>> FAILED! => {"msg": "'dict object' has no attribute 'stdout'"}
>>
>> On Sat, May 2, 2020 at 2:32 PM Kai Stian Olstad <
>> [email protected]> wrote:
>>
>>> On Wed, Apr 29, 2020 at 03:44:14PM -0700, Suresh Karpurapu wrote:
>>> > Would anyone please help me formatting mountchk.result. I am able to
>>> get
>>> > the required output with
>>> > item.stdout_lines[0],item.stdout_lines[1],item.stdout_lines[2] but
>>> host3
>>> > has 6 entries. So, please help me in filtering
>>>
>>> You can use with_sequence or range in a for loop.
>>>
>>>   vars:
>>>     myvar:
>>>       - one
>>>       - two
>>>       - three
>>>       - four
>>>       - five
>>>       - six
>>>   tasks:
>>>     - debug: msg="{{ myvar[item | int] }},{{ myvar[item | int + 1] }},{{
>>> myvar[item | int + 2] }}"
>>>       with_sequence: start=0 end={{ (myvar | length) - 1 }} stride=3
>>>
>>>     - debug:
>>>         msg: |
>>>           {% for i in range(0, myvar | length, 3) %}
>>>           {{ myvar[i] }},{{ myvar[i + 1] }},{{ myvar[i + 2] }}
>>>           {% endfor %}
>>>
>>> --
>>> 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 [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/20200502090224.zygkso3iqpjok2bk%40olstad.com
>>> .
>>>
>>

-- 
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/CAHedzh%2BjAhN4o5Q7X7crpjxGMOJtxJ5M3VXTZUzrmCDk0HAVZA%40mail.gmail.com.

Reply via email to