Skip to content

Instantly share code, notes, and snippets.

@afrazkhan
Last active March 8, 2016 15:30
Show Gist options
  • Save afrazkhan/21ce899d4a90d7d5ce83 to your computer and use it in GitHub Desktop.
Save afrazkhan/21ce899d4a90d7d5ce83 to your computer and use it in GitHub Desktop.
diff --git a/ansible/roles/slack-create-channel/tasks/main.yml b/ansible/roles/slack-create-channel/tasks/main.yml
index 581f8ab..1bf9927 100644
--- a/ansible/roles/slack-create-channel/tasks/main.yml
+++ b/ansible/roles/slack-create-channel/tasks/main.yml
@@ -20,5 +20,5 @@
 
   -
     include: create-channel.yml
-    svc_token: "{{ token }}"
+    svc_token: "{{ slack_token }}"
     svc_channelname: "{{ name }}"
diff --git a/ansible/roles/slack-create-channel/tasks/create-channel.yml b/ansible/roles/slack-create-channel/tasks/create-channel.yml
index 4e6fae3..c6dc9fc 100644
--- a/ansible/roles/slack-create-channel/tasks/create-channel.yml
+++ b/ansible/roles/slack-create-channel/tasks/create-channel.yml
@@ -1,4 +1,7 @@
 ---
+  # Install dependencies
+  - pip:
+      name: httplib2
 
   # catch missing variable `svc_token`
   - fail:
@@ -12,11 +15,11 @@
 
   - debug:
       var: svc_token
-    when: debug == true
+    when: debug is defined and debug == true
 
   - debug:
       var: svc_channelname
-    when: debug == true
+    when: debug is defined and debug == true
 
   # attempt to create Channel
   - uri:
@@ -29,19 +32,19 @@
 
   - debug:
       var: response
-    when: debug == true
+    when: debug is defined and debug == true
 
-  # Channel created successfully!
+  # # Channel created successfully!
   - debug:
-      msg: "Channel {{ name }} was created successfully"
-    when: response.json
+      msg: "Channel {{ svc_channelname }} was created successfully"
+    when: response is defined and response.json is defined and response.json.ok == true
 
   # catch "Channel created previously" type of errors
   - debug:
-      msg: "Channel {{ name }} was previously created"
-    when: response.json.error and response.json.error == "name_taken"
+      msg: "Channel {{ svc_channelname }} was previously created"
+    when: response is defined and response.json.error and response.json.error == "name_taken"
 
   # catch all other errors
   - fail:
       msg: "{{ response.json.error }}"
-    when: response.json.error and response.json.error != "name_taken"
+    when: response is defined and response.json.error and response.json.error != "name_taken"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment