Thank you so much Abhijeet.

On Tuesday, September 8, 2020 at 2:49:51 PM UTC+5:30 Abhijeet Kasurde wrote:

> ---
> - hosts: localhost
>   gather_facts: no
>   vars:
>     user: bk
>   tasks:
>     - shell: chage -l {{ user }}
>       register: r
>
>     - set_fact:
>         user_expire_date: "{{ r.stdout | regex_findall('Password 
> expires.*: (.*)\\n') }}"
>
>     - shell: date +"%b %d, %Y"
>       register: today
>
>     - set_fact:
>         days_to_expire: "{{ ((user_expire_date[0] | to_datetime('%b %d, 
> %Y')) - (today.stdout| to_datetime('%b %d, %Y'))).days }}"
>
>     - debug:
>         msg: "Password is expiring within 10 days"
>       when: "days_to_expire| int <= 10"
>
>
> Add the necessary checks and conditions.
>
> On Tue, Sep 8, 2020 at 2:01 PM Kundan Singh <[email protected]> wrote:
>
>> Thanks Abhijit
>>
>> I made the changes in the code.
>> But still have dout how to use when condition to send a alter so that 
>> user can change there password for endpoints
>>
>> On Tue, Sep 8, 2020, 1:52 PM Abhijeet Kasurde <[email protected]> wrote:
>>
>>> "Name or service not known" tells that "smtp_host_name" is not reachable.
>>>
>>> On Tue, Sep 8, 2020 at 1:45 PM Kundan Singh <[email protected]> 
>>> wrote:
>>>
>>>> Hi All,
>>>>
>>>> Need your Guidance to achieve the milestone.
>>>>
>>>> I am creating a playbook to validate the user password expiry date . if 
>>>> it expires withing 15 days it should send a mail to user mail id.
>>>> but not sure how to enable mail alter after execution of command .
>>>>
>>>> Below is the palybook task detail :-
>>>>
>>>>   tasks:
>>>>     - name: check users password valid time
>>>>       shell: chage -l "{{ item }}"
>>>>       register: validate
>>>>      # loop: users
>>>>
>>>>     - debug:
>>>>         msg: "{{ validate }}"
>>>>       when: validate.rc !=0
>>>>    
>>>>      - name: Intimate concern team by mail if lock occurs
>>>>       mail:
>>>>        host: "{{ smtp_host_name }}"
>>>>        port: "{{ smtp_port }}"
>>>>        to: "{{ receiver_username }}"
>>>>        attach:
>>>>        -  /home/kundan/
>>>>        subject: "Warning!!! Please check the server password "
>>>>        body:  " password getting expires in 10 days"
>>>>
>>>> ======================================================================================
>>>>
>>>> Also counter below error
>>>>
>>>> The full traceback is:
>>>> Traceback (most recent call last):
>>>>   File 
>>>> "/home/kundan/.ansible/tmp/ansible-tmp-1599552344.19-19386-201872757872573/AnsiballZ_mail.py",
>>>>  
>>>> line 102, in <module>
>>>>     _ansiballz_main()
>>>>   File 
>>>> "/home/kundan/.ansible/tmp/ansible-tmp-1599552344.19-19386-201872757872573/AnsiballZ_mail.py",
>>>>  
>>>> line 94, in _ansiballz_main
>>>>     invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
>>>>   File 
>>>> "/home/kundan/.ansible/tmp/ansible-tmp-1599552344.19-19386-201872757872573/AnsiballZ_mail.py",
>>>>  
>>>> line 40, in invoke_module
>>>>     runpy.run_module(mod_name='ansible.modules.notification.mail', 
>>>> init_globals=None, run_name='__main__', alter_sys=True)
>>>>   File "/usr/lib64/python2.7/runpy.py", line 176, in run_module
>>>>     fname, loader, pkg_name)
>>>>   File "/usr/lib64/python2.7/runpy.py", line 82, in _run_module_code
>>>>     mod_name, mod_fname, mod_loader, pkg_name)
>>>>   File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
>>>>     exec code in run_globals
>>>>   File 
>>>> "/tmp/ansible_mail_payload_mBlILo/ansible_mail_payload.zip/ansible/modules/notification/mail.py",
>>>>  
>>>> line 398, in <module>
>>>>   File 
>>>> "/tmp/ansible_mail_payload_mBlILo/ansible_mail_payload.zip/ansible/modules/notification/mail.py",
>>>>  
>>>> line 286, in main
>>>>   File "/usr/lib64/python2.7/smtplib.py", line 315, in connect
>>>>     self.sock = self._get_socket(host, port, self.timeout)
>>>>   File "/usr/lib64/python2.7/smtplib.py", line 290, in _get_socket
>>>>     return socket.create_connection((host, port), timeout)
>>>>   File "/usr/lib64/python2.7/socket.py", line 553, in create_connection
>>>>     for res in getaddrinfo(host, port, 0, SOCK_STREAM):
>>>> socket.gaierror: [Errno -2] Name or service not known
>>>> fatal: [localhost]: FAILED! => {
>>>>     "changed": false,
>>>>     "module_stderr": "Traceback (most recent call last):\n  File 
>>>> \"/home/kundan/.ansible/tmp/ansible-tmp-1599552344.19-19386-201872757872573/AnsiballZ_mail.py\",
>>>>  
>>>> line 102, in <module>\n    _ansiballz_main()\n  File 
>>>> \"/home/kundan/.ansible/tmp/ansible-tmp-1599552344.19-19386-201872757872573/AnsiballZ_mail.py\",
>>>>  
>>>> line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, 
>>>> ANSIBALLZ_PARAMS)\n  File 
>>>> \"/home/kundan/.ansible/tmp/ansible-tmp-1599552344.19-19386-201872757872573/AnsiballZ_mail.py\",
>>>>  
>>>> line 40, in invoke_module\n    
>>>> runpy.run_module(mod_name='ansible.modules.notification.mail', 
>>>> init_globals=None, run_name='__main__', alter_sys=True)\n  File 
>>>> \"/usr/lib64/python2.7/runpy.py\", line 176, in run_module\n    fname, 
>>>> loader, pkg_name)\n  File \"/usr/lib64/python2.7/runpy.py\", line 82, in 
>>>> _run_module_code\n    mod_name, mod_fname, mod_loader, pkg_name)\n  File 
>>>> \"/usr/lib64/python2.7/runpy.py\", line 72, in _run_code\n    exec code in 
>>>> run_globals\n  File 
>>>> \"/tmp/ansible_mail_payload_mBlILo/ansible_mail_payload.zip/ansible/modules/notification/mail.py\",
>>>>  
>>>> line 398, in <module>\n  File 
>>>> \"/tmp/ansible_mail_payload_mBlILo/ansible_mail_payload.zip/ansible/modules/notification/mail.py\",
>>>>  
>>>> line 286, in main\n  File \"/usr/lib64/python2.7/smtplib.py\", line 315, 
>>>> in 
>>>> connect\n    self.sock = self._get_socket(host, port, self.timeout)\n  
>>>> File 
>>>> \"/usr/lib64/python2.7/smtplib.py\", line 290, in _get_socket\n    return 
>>>> socket.create_connection((host, port), timeout)\n  File 
>>>> \"/usr/lib64/python2.7/socket.py\", line 553, in create_connection\n    
>>>> for 
>>>> res in getaddrinfo(host, port, 0, SOCK_STREAM):\nsocket.gaierror: [Errno 
>>>> -2] Name or service not known\n",
>>>>     "module_stdout": "",
>>>>     "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
>>>>     "rc": 1
>>>>
>>>>
>>>> Please help!!!!!
>>>>
>>>> Regards
>>>> Kundan SIngh
>>>>
>>>> -- 
>>>> 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/2e1d3818-041a-4e20-a16e-d1b368f89990o%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/ansible-project/2e1d3818-041a-4e20-a16e-d1b368f89990o%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/CAFwWkHqZ0sLDKLpo9HofFoBQKVDzRjkwrMJa8f749dDxi-pajg%40mail.gmail.com
>>>  
>>> <https://groups.google.com/d/msgid/ansible-project/CAFwWkHqZ0sLDKLpo9HofFoBQKVDzRjkwrMJa8f749dDxi-pajg%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/CADGcVU3wRSMKm3XfZ%3D4GscvUFkA-iQtoVA3By46SbjX_szLv_Q%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/CADGcVU3wRSMKm3XfZ%3D4GscvUFkA-iQtoVA3By46SbjX_szLv_Q%40mail.gmail.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/b1eb2345-0e55-41c0-8f64-732e8b01f923n%40googlegroups.com.

Reply via email to