Welcome to mirror list, hosted at ThFree Co, Russian Federation.

on_off.yml « phillips_hue - github.com/ansible/ansible-examples.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c3c807df616223f1c01d2b65ab25093414ec711c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
- hosts: localhost
  gather_facts: no
  connection: local

  vars:
    off_state:
      "on": false
    on_state:
      "on": true

  tasks:
  - name: INCLUDE UNIQUE USERNAME FROM REGISTER.YML
    include_vars:
      file: username_info.yml

  - name: GRAB HUE LIGHT INFORMATION
    uri:
      url: "http://{{ip_address}}/api/{{username}}"
      method: GET
      body: '{{body_info|to_json}}'
    register: light_info

  - name: PRINT DATA TO TERMINAL WINDOW
    debug:
      var: light_info.json.lights

  - name: PRINT AMOUNT OF LIGHTS TO TERMINAL WINDOW
    debug:
      msg: "THERE ARE {{light_info.json.lights | length}} HUE LIGHTS PRESENT"

  # - name: PRINT OUT LOOP VARS
  #   debug:
  #     msg: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
  #   loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"

  - name: TURN LIGHTS OFF
    uri:
      url: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
      method: PUT
      body: '{{off_state|to_json}}'
    loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"

  - name: PROMPT USER TO TURN BACK ON
    pause:
      prompt: "Turn them back on?"

  - name: TURN LIGHTS ON
    uri:
      url: "http://{{ip_address}}/api/{{username}}/lights/{{item}}/state"
      method: PUT
      body: '{{on_state|to_json}}'
    loop: "{{ range(1, light_info.json.lights | length + 1)|list }}"