| 1 |
- name: Test failure without pika installed |
| 2 |
set_fact: |
| 3 |
rabbit_missing_pika: "{{ lookup('community.rabbitmq.rabbitmq', url='amqp://guest:guest@localhost:5672/%2F', queue='hello', count=3) }}" |
| 4 |
ignore_errors: yes |
| 5 |
register: rabbitmq_missing_pika_error |
| 6 |
delegate_to: localhost |
| 7 |
|
| 8 |
- assert: |
| 9 |
that: |
| 10 |
- "'pika python package is required' in rabbitmq_missing_pika_error.msg" |
| 11 |
|
| 12 |
- name: Install pika and requests |
| 13 |
pip: |
| 14 |
name: pika==1.3.0,requests |
| 15 |
state: latest |
| 16 |
delegate_to: localhost |
| 17 |
|
| 18 |
- name: Test that giving an incorrect amqp protocol in URL will error |
| 19 |
set_fact: |
| 20 |
rabbitmq_test_protocol: "{{ lookup('community.rabbitmq.rabbitmq', url='zzzamqp://guest:guest@localhost:5672/%2F', queue='hello', count=3) }}" |
| 21 |
ignore_errors: yes |
| 22 |
register: rabbitmq_protocol_error |
| 23 |
delegate_to: localhost |
| 24 |
|
| 25 |
- assert: |
| 26 |
that: |
| 27 |
- "rabbitmq_protocol_error is failed" |
| 28 |
- "'URL malformed' in rabbitmq_protocol_error.msg" |
| 29 |
|
| 30 |
- name: Test that giving an incorrect IP address in URL will error |
| 31 |
set_fact: |
| 32 |
rabbitmq_test_protocol: "{{ lookup('community.rabbitmq.rabbitmq', url='amqp://guest:[email protected]:5672/%2F', queue='hello', count=3) }}" |
| 33 |
ignore_errors: yes |
| 34 |
register: rabbitmq_ip_error |
| 35 |
delegate_to: localhost |
| 36 |
|
| 37 |
- assert: |
| 38 |
that: |
| 39 |
- "rabbitmq_ip_error is failed" |
| 40 |
- "'Connection issue' in rabbitmq_ip_error.msg" |
| 41 |
|
| 42 |
- name: Test missing parameters will error |
| 43 |
set_fact: |
| 44 |
rabbitmq_test_protocol: "{{ lookup('community.rabbitmq.rabbitmq') }}" |
| 45 |
ignore_errors: yes |
| 46 |
register: rabbitmq_params_error |
| 47 |
delegate_to: localhost |
| 48 |
|
| 49 |
- assert: |
| 50 |
that: |
| 51 |
- "rabbitmq_params_error is failed" |
| 52 |
- "'URL is required for rabbitmq lookup.' in rabbitmq_params_error.msg" |
| 53 |
|
| 54 |
- name: Test missing queue will error |
| 55 |
set_fact: |
| 56 |
rabbitmq_queue_protocol: "{{ lookup('community.rabbitmq.rabbitmq', url='amqp://guest:guest@localhost:5672/%2F') }}" |
| 57 |
ignore_errors: yes |
| 58 |
register: rabbitmq_queue_error |
| 59 |
delegate_to: localhost |
| 60 |
|
| 61 |
- assert: |
| 62 |
that: |
| 63 |
- "rabbitmq_queue_error is failed" |
| 64 |
- "'Queue is required for rabbitmq lookup' in rabbitmq_queue_error.msg" |
| 65 |
|
| 66 |
- name: Enables the rabbitmq_management plugin |
| 67 |
rabbitmq_plugin: |
| 68 |
names: rabbitmq_management |
| 69 |
state: enabled |
| 70 |
delegate_to: localhost |
| 71 |
|
| 72 |
- name: Setup test queue |
| 73 |
rabbitmq_queue: |
| 74 |
name: hello |
| 75 |
delegate_to: localhost |
| 76 |
|
| 77 |
- name: Post test message to the exchange (string) |
| 78 |
uri: |
| 79 |
url: http://localhost:15672/api/exchanges/%2f/amq.default/publish |
| 80 |
method: POST |
| 81 |
body: '{"properties":{},"routing_key":"hello","payload":"ansible-test","payload_encoding":"string"}' |
| 82 |
user: guest |
| 83 |
password: guest |
| 84 |
force_basic_auth: yes |
| 85 |
return_content: yes |
| 86 |
headers: |
| 87 |
Content-Type: "application/json" |
| 88 |
register: post_data |
| 89 |
delegate_to: localhost |
| 90 |
|
| 91 |
|
| 92 |
- name: Post test message to the exchange (json) |
| 93 |
uri: |
| 94 |
url: http://localhost:15672/api/exchanges/%2f/amq.default/publish |
| 95 |
method: POST |
| 96 |
body: '{"properties":{"content_type": "application/json"},"routing_key":"hello","payload":"{\"key\": \"value\" }","payload_encoding":"string"}' |
| 97 |
user: guest |
| 98 |
password: guest |
| 99 |
force_basic_auth: yes |
| 100 |
return_content: yes |
| 101 |
headers: |
| 102 |
Content-Type: "application/json" |
| 103 |
register: post_data_json |
| 104 |
delegate_to: localhost |
| 105 |
|
| 106 |
- name: Test retrieve messages |
| 107 |
set_fact: |
| 108 |
rabbitmq_msg: "{{ lookup('community.rabbitmq.rabbitmq', url='amqp://guest:guest@localhost:5672/%2f/hello', queue='hello') }}" |
| 109 |
ignore_errors: yes |
| 110 |
register: rabbitmq_msg_error |
| 111 |
delegate_to: localhost |
| 112 |
|
| 113 |
- name: Ensure two messages received |
| 114 |
assert: |
| 115 |
that: |
| 116 |
- "rabbitmq_msg_error is not failed" |
| 117 |
- rabbitmq_msg | length == 2 |
| 118 |
|
| 119 |
- name: Ensure first message is a string |
| 120 |
assert: |
| 121 |
that: |
| 122 |
- rabbitmq_msg[0].msg == "ansible-test" |
| 123 |
|
| 124 |
- name: Ensure second message is json |
| 125 |
assert: |
| 126 |
that: |
| 127 |
- rabbitmq_msg[1].json.key == "value" |
| 128 |
|
| 129 |
- name: Test missing vhost |
| 130 |
set_fact: |
| 131 |
rabbitmq_msg: "{{ lookup('community.rabbitmq.rabbitmq', url='amqp://guest:guest@localhost:5672/missing/', queue='hello') }}" |
| 132 |
ignore_errors: yes |
| 133 |
register: rabbitmq_vhost_error |
| 134 |
delegate_to: localhost |
| 135 |
|
| 136 |
- assert: |
| 137 |
that: |
| 138 |
- "rabbitmq_vhost_error is failed" |
| 139 |
- ("'NOT_ALLOWED' in rabbitmq_vhost_error.msg") or ("'Connection issue' in rabbitmq_vhost_error.msg") |
| 140 |
|
| 141 |
|
| 142 |
- name: Uninstall pika and requests |
| 143 |
pip: |
| 144 |
name: pika,requests |
| 145 |
state: absent |
| 146 |
delegate_to: localhost |
| 147 |
|
| 148 |
- name: Disable the rabbitmq_management plugin |
| 149 |
rabbitmq_plugin: |
| 150 |
names: rabbitmq_management |
| 151 |
state: disabled |
| 152 |
delegate_to: localhost |