[ansible-project] Re: Delete based on directory size
Does this help? I created a directory structure with four files: $ find /tmp/dirsize/ -ls | cut -c 18- drwxrwxr-x 5 dan dan 100 May 11 14:59 /tmp/dirsize/ drwxrwxr-x 2 dan dan60 May 11 15:00 /tmp/dirsize/d3 -rw-rw-r-- 1 dan dan 5242880 May 11 15:00 /tmp/dirsize/d3/5M. file drwxrwxr-x 2 dan dan60 May 11 15:00 /tmp/dirsize/d2 -rw-rw-r-- 1 dan dan 3145728 May 11 15:00 /tmp/dirsize/d2/3M. file drwxrwxr-x 2 dan dan80 May 11 15:00 /tmp/dirsize/d1 -rw-rw-r-- 1 dan dan 3145728 May 11 15:00 /tmp/dirsize/d1/3M. file -rw-rw-r-- 1 dan dan 6291456 May 11 14:59 /tmp/dirsize/d1/6M. file Then using this playbook: --- - hosts: all gather_facts: false vars: log_dir: "/tmp/dirsize/" max_dirsize: 4 max_logsize: 4 tasks: - name: Test using du command shell: du -sm "{{ log_dir }}"/* register: du_files changed_when: false - name: "Work on directories greater than {{ max_dirsize }}m in {{ log_dir }}" debug: msg: "Files- {{ item.split('\t')[1] }} - {{ item.split('\t')[0] }}m" when: item.split('\t')[0]|int >= max_dirsize|int with_items: "{{ du_files.stdout_lines }}" The playbook runs and uses the "du" command to find the size of all the files and directories, then that list is parsed to find only those items that are larger than "max_dirsize" MB. $ ansible-playbook dirsize.yml --connection local -i localhost, PLAY [all] * TASK [Test using du command] ***ok: [localhost] TASK [Work on directories greater than 4m in /tmp/dirsize/] ok: [localhost] => (item=9 /tmp/dirsize/d1) => {"msg": "Files- /tmp/dirsize/d1 - 9m"}skipping: [localhost] => (item=3 /tmp/dirsize/d2) ok: [localhost] => (item=5 /tmp/dirsize/d3) => {"msg": "Files- /tmp/dirsize/d3 - 5m"} PLAY RECAP *localhost : ok=2changed=0unreachable=0failed=0 Replace the "debug:" module call with the action(s) you want to take on those large files. On Saturday, May 11, 2019 at 7:00:16 AM UTC-5, Nicholas Britton wrote: > > I have been looking for a module for something similar to the du command. > I would like to have a play that looks at the log directory to detect if > it's a certian size or larger and if so find the sub folders with gbs of > data and remove or tar that data up. > > So far I am not finding that and parsing the return of the du command is > not is not somethig I am having luck with. > > Has anyone tried to do something similar? Have any ideas or pointers for > me? > > -- 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/b14aa866-c695-4fff-a507-4546e655d2bb%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [ansible-project] How to choose the var list based on a condition
On 11.05.2019 20:40, Saranya N wrote: > I have a list of dictionary variables something like below in vars file. > > App01: > A : value1 > B : value2 > C : value3 > > App02: >A : value4 >C : value5 >B : value6 > > And so on... > > When I run my playbook with -e option app=01 "{{ hostvars[inventory_hostname]['App' ~ app] }}" > or app=App01 "{{ hostvars[inventory_hostname][app] }}" > I want to use App01 variables in with_items in my task . App01 and App02 is not a list so you can't use with_items, but you could use with_dict instead. -- 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 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/0029ab72-cb6b-ebae-dd01-5fe4b16512e8%40olstad.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] How to choose the var list based on a condition
I have a list of dictionary variables something like below in vars file. App01: A : value1 B : value2 C : value3 App02: A : value4 C : value5 B : value6 And so on... When I run my playbook with -e option app=01 or app=App01 I want to use App01 variables in with_items in my task . How can I achieve this? -- 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/2ebce4ff-8a81-4f1f-a978-1aefa38ada97%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] set_facts with if-else clause, also check if the var contains digits?
Im trying to set a variable based on below condition where templname is an external variable with below options ansible-playbook -i hosts -e "templname=CTrl03_kerbs_09" OR ansible-playbook -i hosts -e "templname=CTrl05" set_fact: dbn: "{{ CTrl03_kerbs_09 | lower }} dbnum: "{ % 'prefix-' + templname.split('_')[-1] if '_' in templname else 'prefix' %}"##if templname contains "_" then dbnum should append "prefix-" to the last digit of templname i.e I want "prefix-9" I want vars set like below: 1) dbn = ctrl03_kerbs_09 dbnum = prefix-9 2) dbn = ctrl05 dbnum = prefix But this doesngt seem to work? Any problem in syntax? I get syntax error... Also is there a ansible way to check if the string(templname) contains digits?? -- 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/309b7ced-c42c-4ab9-869f-e4d57bc67e9b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [ansible-project] ansible cron with 2.8rc3
On 11.05.2019 19:15, Kai Stian Olstad wrote: > On 11.05.2019 18:38, Michael Ströder wrote: >> I'm testing my ansible roles with ansible 2.8rc3. >> The roles work with ansible 2.7.10. >> >> This cron task fails with 2.8rc3 using Python 2.7.16 (see details >> attached at message end): >> >> - name: "Remove obsolete CRON jobs from /etc/cron.d/aedir_tools" >> cron: >> name: "{{ item }}" >> state: absent >> cron_file: aedir_tools >> with_items: >> - aedirpwd_cron >> - aedirpwd_expiry_check >> >> What's wrong with that? >> > > > >> "msg": "missing parameter(s) required by 'cron_file': user" >> } >> > > As the message say you are missing the user parameter, per documentation this > is required. > > That said, the user parameter is irrelevant when state is absent so I would > call this a bug. Here is the culprit PR https://github.com/ansible/ansible/pull/28662 -- 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 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/aed1cb4a-06fc-81b6-5f29-d4cf06a84071%40olstad.com. For more options, visit https://groups.google.com/d/optout.
Re: [ansible-project] ansible cron with 2.8rc3
On 11.05.2019 18:38, Michael Ströder wrote: > I'm testing my ansible roles with ansible 2.8rc3. > The roles work with ansible 2.7.10. > > This cron task fails with 2.8rc3 using Python 2.7.16 (see details > attached at message end): > > - name: "Remove obsolete CRON jobs from /etc/cron.d/aedir_tools" >cron: > name: "{{ item }}" > state: absent > cron_file: aedir_tools >with_items: > - aedirpwd_cron > - aedirpwd_expiry_check > > What's wrong with that? > > "msg": "missing parameter(s) required by 'cron_file': user" > } > As the message say you are missing the user parameter, per documentation this is required. That said, the user parameter is irrelevant when state is absent so I would call this a bug. -- 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 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/41930af4-07d6-289d-5eee-93b35cc8fe72%40olstad.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] ansible cron with 2.8rc3
HI! I'm testing my ansible roles with ansible 2.8rc3. The roles work with ansible 2.7.10. This cron task fails with 2.8rc3 using Python 2.7.16 (see details attached at message end): - name: "Remove obsolete CRON jobs from /etc/cron.d/aedir_tools" cron: name: "{{ item }}" state: absent cron_file: aedir_tools with_items: - aedirpwd_cron - aedirpwd_expiry_check What's wrong with that? Ciao, Michael. snip The full traceback is: WARNING: The below traceback may *not* be related to the actual failure. File "/tmp/ansible_cron_payload_HHWGrW/ansible_cron_payload.zip/ansible/module_utils/basic.py", line 1529, in _check_required_by check_required_by(spec, param) File "/tmp/ansible_cron_payload_HHWGrW/ansible_cron_payload.zip/ansible/module_utils/common/validation.py", line 164, in check_required_by raise TypeError(to_native(msg)) failed: [ae-dir-suse-p1.virtnet1.stroeder.local] (item=aedirpwd_cron) => { "ansible_loop_var": "item", "changed": false, "invocation": { "module_args": { "backup": false, "cron_file": "aedir_tools", "day": "*", "disabled": false, "hour": "*", "minute": "*", "month": "*", "name": "aedirpwd_cron", "reboot": false, "state": "absent", "weekday": "*" } }, "item": "aedirpwd_cron", "msg": "missing parameter(s) required by 'cron_file': user" } -- 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/21b82225-703d-4a8a-cd9c-a1d427b70c9d%40stroeder.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] Delete based on directory size
I have been looking for a module for something similar to the du command. I would like to have a play that looks at the log directory to detect if it's a certian size or larger and if so find the sub folders with gbs of data and remove or tar that data up. So far I am not finding that and parsing the return of the du command is not is not somethig I am having luck with. Has anyone tried to do something similar? Have any ideas or pointers for me? -- 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/27c07b39-4955-4645-8e61-e68b96872da6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.