ansible / ansible-modules-extras

Ansible extra modules - these modules ship with ansible
947 stars 1.47k forks source link

Ansible Reports Twilio Failure Yet SMS Sent Successfullly #3029

Closed ifelsefi closed 7 years ago

ifelsefi commented 7 years ago
ISSUE TYPE

Twilio

ANSIBLE VERSION
ansible 2.1.1.0
  config file = /home/douglas/repos/ansible/ansible.cfg
  configured module search path = Default w/o overrides
CONFIGURATION
Pipelining and threads but nothing else
OS / ENVIRONMENT
Linux Mint
SUMMARY

TASK [accounts : send sms challenge] *******************************************
fatal: [pascal -> localhost]: FAILED! => {"changed": false, "failed": true, "msg": "unable to send message to +15163205079"}
...ignoring

Yet Twilio console shows SMS delivered while recipient confirms SMS 
STEPS TO REPRODUCE
ansible-playbook accounts.yml "-e hosts=server -e csms=[] -e number=+blah -e user=blah" -t csms --sudo -K --ask-vault-pass

cat accounts.yml 

---
- hosts: "{{ hosts }}"
  roles: 
    - accounts
  gather_facts: True

cat roles/accounts/tasks/main.yml 

- include: create_user.yml
  when: create is defined

- include: remove_user.yml
  when: remove is defined

- include: xfs.yml
  when: ansible_hostname == "blah" or "blah"

- include: lab_email.yml
  when: lab is defined

- include: challenge.yml
  when: csms is defined

cat roles/accounts/tasks/challenge.yml 

- name: send sms challenge
  tags: csms 
  twilio:
   msg: "{{ challenge }}"
   account_sid: "SID"
   auth_token: "TOKEN"
   from_number: "+BLAH"
   to_number: "{{ number }}"
  delegate_to: localhost    
  ignore_errors: True
EXPECTED RESULTS

SMS works without reported error

ACTUAL RESULTS

SMS works but module reports error


 ansible-playbook accounts.yml "-e hosts=host -e csms=[] -e number=+blah -e user=blah" -t csms --sudo -K --ask-vault-pass -vvv
Using /home/user/repos/ansible/ansible.cfg as config file
SUDO password: 
Vault password: 

PLAYBOOK: accounts.yml *********************************************************
1 plays in accounts.yml

PLAY [pascal] ******************************************************************

TASK [setup] *******************************************************************
<pascal> ESTABLISH SSH CONNECTION FOR USER: None
<pascal> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=20 -o ControlPath=/home/user/.ansible/cp/ansible-ssh-%h-%p-%r host '/bin/sh -c '"'"'sudo -H -S  -p "[sudo via ansible, key=dovdppgsmmkpysizwmmmanqpnsnbhkbn] password: " -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-dovdppgsmmkpysizwmmmanqpnsnbhkbn; LANG=C LC_ALL=C LC_MESSAGES=C /usr/bin/python'"'"'"'"'"'"'"'"' && sleep 0'"'"''
ok: [pascal]

TASK [accounts : send sms challenge] *******************************************
task path: /home/user/repos/ansible/playbooks/roles/accounts/tasks/challenge.yml:11
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: user
<localhost> EXEC /bin/sh -c 'sudo -H -S  -p "[sudo via ansible, key=pgyfxtpxffqiposwtecseosepacqessa] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-pgyfxtpxffqiposwtecseosepacqessa; LANG=C LC_ALL=C LC_MESSAGES=C /usr/bin/python'"'"' && sleep 0'
fatal: [user -> localhost]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_args": {"account_sid": "blah", "auth_token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "from_number": "+blah", "media_url": null, "msg": "challenge", "to_number": "+blahblah", "url_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "url_username": "blah"}, "module_name": "twilio"}, "msg": "unable to send message to +blah"}
...ignoring

PLAY RECAP *********************************************************************
host                     : ok=2    changed=0    unreachable=0    failed=0   
ansibot commented 7 years ago

@makaimc ping, this issue is waiting for your response. click here for bot help

mattmakai commented 7 years ago

I am able to reproduce this - looks like it was introduced in 1.9.6 after 1.9.4 (works in 1.9.4). With this commit. Doesn't look like the module was tested when the change was made because it's clear the ['status'] == 200 on line 164 will never be true. What's next step here?

mattmakai commented 7 years ago

I'm not familiar with this fetch_url function that broke the module, do I need to submit a fix for this? If I am specified as a maintainer on the module it would be good to get a heads up when changes are made and merged but not tested :/

resmo commented 7 years ago

IMHO the problem is, the module looks for 200 response code but it should (also) look for 201. Could you change https://github.com/ansible/ansible-modules-extras/blob/devel/notification/twilio.py#L164 to

if info['status'] not in [200, 201]:

and test it again?

mattmakai commented 7 years ago

sure, i got my test environment set up again. will make some modifications and submit a PR tonight or tmrw AM

resmo commented 7 years ago

I was able to reproduce and created a PR #3033 which also improves error message output.

ifelsefi commented 7 years ago

Thanks! Y'all rock.

Now fixed in new release of Ansible 2.1.2.0.

resmo commented 7 years ago

@JusticeForMikeBrown thx!

mattmakai commented 7 years ago

:+1: Development crew on Ansible are awesome. thanks ya'll