Don't mind the messed up indent...

On Monday, March 12, 2018 at 1:50:23 PM UTC+5:30, Varun Chopra wrote:
>
> You can use it as a role and loop over it:
>
> - name: Disk role.
>       include_role:
>         name: disk_role
>       vars:
>         mount_point: "{{ item }}"
>
>       with_items:
>         - "/dev"
>         - "/backup"
>
>
> On Monday, March 12, 2018 at 12:15:33 PM UTC+5:30, Kiran Shrimali wrote:
>>
>> ---
>>  - hosts: test-servers
>>    user: gamesroot
>>    become: true
>>    become_user: root
>>    gather_facts: yes 
>>    vars:
>>        mountpoint: "{{m}}"
>>
>>    tasks:
>>    - shell: df -h "{{mountpoint}}" | tail -n 1 | awk {'print $5 '}  | sed 
>> 's/%//g'
>>      register: test
>>
>>    - shell: rm -rf /tmp/disk.txt; touch /tmp/disk.txt
>>      delegate_to: localhost
>>  
>>    - shell: echo "{{ inventory_hostname }}"
>>      register: op
>>
>>    - debug:
>>        msg:
>>          - "{{test.stdout}}"
>>          - "{{ op.stdout }}"
>>
>>    - name: add lines
>>      lineinfile: 
>>        dest: /tmp/disk.txt 
>>        line: "{{ m }} HAS REACHED {{ test.stdout }} % ON {{ op.stdout }}, 
>> KINDLY CHECK !!!"
>>        state: present
>>      delegate_to: 127.0.0.1 
>>      register: msgtxt
>>      with_items:
>>        - "{{ test.stdout }}"
>>        - "{{ op.stdout }}"
>>      when: test.stdout|int > 5 
>>    - local_action: copy content= "{{ msgtxt.results }}" 
>> dest=/tmp/disk2.txt 
>>
>>
>> I have create this , everything is working fine.. Now i am giving 
>> mountpoint at the run time. 
>> Now if i want to define more then one 1 mountpoint, how can it will 
>> compete the full loop for one mount point and next it will jump on second 
>> mountpoint. 
>>
>> e.g. vars:
>>        mountpoint: 
>>            - /
>>            - /home
>>            - /backup
>>            - /dev
>>
>> On Friday, March 9, 2018 at 6:52:58 PM UTC+5:30, Thomas Hikade wrote:
>>>
>>> In addition you might like to print out the name of your FS which is too 
>>> big. For that you need the names again in the last debug loop.
>>> You could fix that like this, using advanced looping statement 
>>> "with_together" (Ansible Loops 
>>> <https://docs.ansible.com/ansible/latest/playbooks_loops.html#looping-over-parallel-sets-of-data>
>>> )
>>>
>>>   vars:
>>>     filesystems:
>>>       - /
>>>       - /tmp
>>>
>>>     size_too_big: "20"
>>>
>>>   tasks:
>>>
>>> ...
>>>
>>>   - name: Size is big v2
>>>     debug:
>>>       msg:  "{{ item.1 }} is too big! size={{ item.0 }} "
>>>     when: item.0 > size_too_big
>>>     with_together:
>>>        - "{{ test.results|map(attribute='stdout')|list }}"
>>>        - "{{ filesystems }}"
>>>
>>> This will produce the following output:
>>>
>>> TASK [Size is big v2] 
>>> **********************************************************
>>> ok: [demobox] => (item=[u'37', u'/']) => {
>>>     "item": [
>>>         "37",
>>>         "/"
>>>     ],
>>>     "msg": "/ is too big! size=37 "
>>> }
>>> ok: [demobox] => (item=[u'37', u'/tmp']) => {
>>>     "item": [
>>>         "37",
>>>         "/tmp"
>>>     ],
>>>     "msg": "/tmp is too big! size=37 "
>>> }
>>>
>>>
>>>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/96c1e197-5098-4c11-a581-433f876d18f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to