-1

I am facing issue with by below playbook on 2 scenarios

1) How to send mails using ansible without defining the password of the account. using SMTP username and password now in the play to send mail. but is there any alternate way to avoid specifying password or using the encryption for password.

 - name: Send email
     mail:
        host: smtpserver.com
        port: 25
        username: mydomainID
        password: mypass
        subject: "Ansible test mail"
        attach: /opt/IBM/605CLM/JazzTeamserver/server/liberty/servers/clm/logs/jts.log
        body: "Testing email"
        from: mymailid.com
        to:
          - mymailid.com
        charset: utf8
        secure: never

2) Lokking for a way to attach the log file in the mail after starting the application. but it failing.. any advise please.

Getting error as below

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: IOError: [Errno 2] No such file or directory: '/opt/IBM/605CLM/JazzTeamserver/server/liberty/servers/clm/logs/jts.log' [WARNING]: Username and Password was sent without encryption

fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to send mail: can't attach file /opt/IBM/605CLM/JazzTeamserver/server/liberty/servers/clm/logs/jts.log: [Errno 2] No such file or directory: '/opt/IBM/605CLM/JazzTeamserver/server/liberty/servers/clm/logs/jts.log'", "rc": 1} to retry, use: --limit @/etc/ansible/roles/IBM2/tasks/pingmail.retry

PLAY RECAP ************************************************************************************************************************************************** localhost : ok=2 changed=0 unreachable=0 failed=1

saran
  • 139
  • 1
  • 2
  • 12

1 Answers1

1
  1. You can use vault encrypted variable file which will contain variable with the password for the SMTP user
  2. What problem are you facing? Any errors?
user3499202
  • 71
  • 1
  • 6
  • Thanks for your quick response. for the point (1) can you please guide me with some more details pls, and for point ( 2 ) i had added the error details to my above question session – saran Nov 30 '18 at 10:50
  • 1
    1. The user guide for the vault i playbooks: https://docs.ansible.com/ansible/latest/user_guide/playbooks_vault.html#single-encrypted-variable https://docs.ansible.com/ansible/latest/user_guide/playbooks_best_practices.html#best-practices-for-variables-and-vaults You can set variables in file and then encrypt the file with ansible-vault. Use the variable within the play, and then when you run the playbook use --ask-vault-pass command which will ask you to give the password for the encrypted file to decrypted. 2. "No such file or directory:" are you sure the file exists? Check the path – user3499202 Nov 30 '18 at 11:01
  • I am sorry that, the application was keep running and hence it was not able to attach to the mail. now its fixed. I am working on point (1) and will let you know if i could succeeded – saran Nov 30 '18 at 12:22