Last active
April 10, 2018 08:33
-
-
Save dmc-at-work/7dddb363d0890c9baab9d85628a4a369 to your computer and use it in GitHub Desktop.
GovTech - SGCore - Experiments - Request: Internal Playbook Scheduling - v1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# govtech-sgcore-experiments-internal-playbook-scheduling-v1-1.yml | |
# 2018 04 04 | |
# 2018 04 05 | |
# 2018 04 06 | |
# 2018 04 10 | |
# DMC | |
# To Run: | |
# $ ansible-playbook govtech-sgcore-experiments-internal-playbook-scheduling-v1-1.yml | |
--- | |
- name: govtech-sgcore-experiments-internal-playbook-scheduling-v1 | |
hosts: localhost | |
vars: | |
time_am_min: 0 | |
time_am_max: 600 | |
time_pm_min: 2000 | |
time_pm_max: 2359 | |
# Use this if timing list iteration needed | |
time_run_cycle: | |
- 2030 | |
- 2100 | |
- 2130 | |
- 2200 | |
- 2230 | |
- 2300 | |
- 2330 | |
- 0 | |
- 30 | |
- 100 | |
- 130 | |
- 200 | |
- 230 | |
- 300 | |
- 330 | |
- 400 | |
- 430 | |
- 500 | |
- 530 | |
- 600 | |
##### For discussed logic | |
# from time_pm_min to time_pm_max | |
# and | |
# from time_am_min to time_am_max | |
# implem_retries: 20 | |
# implem_delay: 1800 | |
##### For Dev/Testing | |
implem_retries: 10 | |
implem_delay: 3 | |
tasks: | |
- name: | |
Get timestamp from the system - Format - HHMM | |
shell: | |
"date +%H%M" | |
register: | |
tstamp_HHMM | |
- name: | |
Set variables | |
set_fact: | |
##### For discussed production logic | |
# from time_pm_min to time_pm_max | |
# and | |
# from time_am_min to time_am_max | |
cur_time_HHMM: "{{ tstamp_HHMM.stdout }}" | |
##### For Dev/Testing | |
# cur_time_HHMM: 1900 | |
# cur_time_HHMM: 2000 | |
# cur_time_HHMM: 2100 | |
# cur_time_HHMM: 0 | |
# cur_time_HHMM: 100 | |
# cur_time_HHMM: 600 | |
# cur_time_HHMM: 601 | |
- name: System timestamp - HHMM | |
debug: | |
msg: "Current HHMM: {{ cur_time_HHMM }}" | |
#################### | |
##### Variation #1 | |
#################### | |
- name: | |
"Hello With Condition" | |
shell: | |
# do something | |
# command: /sbin/shutdown -t now | |
# Check defer run to later | |
echo "HELLO!!!!!!!!!!!!!!!!!!!!" | |
register: | |
shell_echo_result | |
when: | |
# If outside conditions | |
# "shell_echo_result.stdout": "VARIABLE IS NOT DEFINED!" | |
# Or further handling | |
(cur_time_HHMM >= time_pm_min and cur_time_HHMM <= time_pm_max) | |
or | |
(cur_time_HHMM >= time_am_min and cur_time_HHMM <= time_am_max) | |
- name: Variation \#1 Test Echo Result | |
debug: | |
# var: shell_echo_result.stdout_lines | |
var: shell_echo_result.stdout | |
- name: Test Echo End | |
debug: | |
msg: "END OF THE LINE. THANK YOU." | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# govtech-sgcore-experiments-internal-playbook-scheduling-v1-2.yml | |
# 2018 04 04 | |
# 2018 04 05 | |
# 2018 04 06 | |
# 2018 04 10 | |
# DMC | |
# To Run: | |
# $ ansible-playbook govtech-sgcore-experiments-internal-playbook-scheduling-v1-2.yml | |
--- | |
- name: govtech-sgcore-experiments-internal-playbook-scheduling-v1 | |
hosts: localhost | |
vars: | |
time_am_min: 0 | |
time_am_max: 600 | |
time_pm_min: 2000 | |
time_pm_max: 2359 | |
# Use this if timing list iteration needed | |
time_run_cycle: | |
- 2030 | |
- 2100 | |
- 2130 | |
- 2200 | |
- 2230 | |
- 2300 | |
- 2330 | |
- 0 | |
- 30 | |
- 100 | |
- 130 | |
- 200 | |
- 230 | |
- 300 | |
- 350 | |
- 400 | |
- 430 | |
- 500 | |
- 530 | |
- 600 | |
##### For discussed logic | |
# from time_pm_min to time_pm_max | |
# and | |
# from time_am_min to time_am_max | |
# implem_retries: 20 | |
# implem_delay: 1800 | |
##### For Dev/Testing | |
implem_retries: 10 | |
implem_delay: 3 | |
tasks: | |
- name: | |
Get timestamp from the system - Format - HHMM | |
shell: | |
"date +%H%M" | |
register: | |
tstamp_HHMM | |
- name: | |
Set variables | |
set_fact: | |
##### For discussed production logic | |
# from time_pm_min to time_pm_max | |
# and | |
# from time_am_min to time_am_max | |
cur_time_HHMM: "{{ tstamp_HHMM.stdout }}" | |
##### For Dev/Testing | |
# cur_time_HHMM: 1900 | |
# cur_time_HHMM: 2000 | |
# cur_time_HHMM: 2100 | |
# cur_time_HHMM: 0 | |
# cur_time_HHMM: 100 | |
# cur_time_HHMM: 600 | |
# cur_time_HHMM: 601 | |
- name: System timestamp - HHMM | |
debug: | |
msg: "Current HHMM: {{ cur_time_HHMM }}" | |
#################### | |
##### Variation #2 | |
#################### | |
- name: | |
"Hello Retries" | |
shell: | |
# do something | |
# command: /sbin/shutdown -t now | |
# Check defer run to later | |
echo "Again And Again" | |
# create/update some boolean to use as exit flag, if needed. | |
register: | |
shell_echo_result | |
until: | |
# replace below with a boolean variable that | |
# is updated after successful run | |
# - shell_echo_result.stdout == "blahblahblah" | |
- (cur_time_HHMM >= time_pm_min and cur_time_HHMM <= time_pm_max) | |
or | |
(cur_time_HHMM >= time_am_min and cur_time_HHMM <= time_am_max) | |
retries: "{{ implem_retries }}" | |
delay: "{{ implem_delay }}" # seconds | |
ignore_errors: yes | |
# Uncomment below if you need | |
# to end playbook run here. | |
# Tasks below, not executed | |
# - meta: end_play | |
# when: (optional condition) | |
- name: Variation \#2 Test Echo Result | |
debug: | |
# var: shell_echo_result.stdout_lines | |
var: shell_echo_result.stdout | |
- name: Test Echo End | |
debug: | |
msg: "END OF THE LINE. THANK YOU." | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# govtech-sgcore-experiments-internal-playbook-scheduling-v1-3.yml | |
# 2018 04 04 | |
# 2018 04 05 | |
# 2018 04 06 | |
# 2018 04 10 | |
# DMC | |
# To Run: | |
# $ ansible-playbook govtech-sgcore-experiments-internal-playbook-scheduling-v1-3.yml | |
--- | |
- name: govtech-sgcore-experiments-internal-playbook-scheduling-v1 | |
hosts: localhost | |
vars: | |
time_am_min: 0 | |
time_am_max: 600 | |
time_pm_min: 2000 | |
time_pm_max: 2359 | |
# Use this if timing list iteration needed | |
time_run_cycle: | |
- 2030 | |
- 2100 | |
- 2130 | |
- 2200 | |
- 2230 | |
- 2300 | |
- 2330 | |
- 0 | |
- 30 | |
- 100 | |
- 130 | |
- 200 | |
- 230 | |
- 300 | |
- 330 | |
- 400 | |
- 430 | |
- 500 | |
- 530 | |
- 600 | |
##### For discussed logic | |
# from time_pm_min to time_pm_max | |
# and | |
# from time_am_min to time_am_max | |
# implem_retries: 20 | |
# implem_delay: 1800 | |
##### For Dev/Testing | |
implem_retries: 10 | |
implem_delay: 3 | |
tasks: | |
- name: | |
Get timestamp from the system - Format - HHMM | |
shell: | |
"date +%H%M" | |
register: | |
tstamp_HHMM | |
- name: | |
Set variables | |
set_fact: | |
##### For discussed production logic | |
# from time_pm_min to time_pm_max | |
# and | |
# from time_am_min to time_am_max | |
cur_time_HHMM: "{{ tstamp_HHMM.stdout }}" | |
##### For Dev/Testing | |
# cur_time_HHMM: 1900 | |
# cur_time_HHMM: 2000 | |
# cur_time_HHMM: 2100 | |
# cur_time_HHMM: 0 | |
# cur_time_HHMM: 100 | |
# cur_time_HHMM: 600 | |
# cur_time_HHMM: 601 | |
- name: System timestamp - HHMM | |
debug: | |
msg: "Current HHMM: {{ cur_time_HHMM }}" | |
#################### | |
##### Variation #3 | |
#################### | |
- block: | |
- name: | |
"Hello Retries In Block" | |
shell: | |
# do something | |
# command: /sbin/shutdown -t now | |
# Check defer run to later | |
echo "Again And Again And Again And Again In Block" | |
# create some boolean to use as exit flag | |
register: | |
shell_echo_result | |
until: | |
# replace below with a boolean variable that | |
# is updated after successful run | |
# - shell_echo_result.stdout == "blahblahblah" | |
- (cur_time_HHMM >= time_pm_min and cur_time_HHMM <= time_pm_max) | |
or | |
(cur_time_HHMM >= time_am_min and cur_time_HHMM <= time_am_max) | |
retries: "{{ implem_retries }}" | |
delay: "{{ implem_delay }}" # seconds | |
ignore_errors: yes | |
# Uncomment below if you need | |
# to end playbook run here. | |
# Tasks below, not executed | |
# - meta: end_play | |
# when: | |
# (cur_time_HHMM >= time_pm_min and cur_time_HHMM <= time_pm_max) | |
# or | |
# (cur_time_HHMM >= time_am_min and cur_time_HHMM <= time_am_max) | |
- name: Variation \#3 Test Echo Result | |
debug: | |
# var: shell_echo_result.stdout_lines | |
var: shell_echo_result.stdout | |
- name: Test Echo End | |
debug: | |
msg: "END OF THE LINE. THANK YOU." | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# govtech-sgcore-experiments-internal-playbook-scheduling-v1.yml | |
# 2018 04 04 | |
# 2018 04 05 | |
# 2018 04 06 | |
# 2018 04 10 | |
# DMC | |
# To Run: | |
# $ ansible-playbook govtech-sgcore-experiments-internal-playbook-scheduling-v1.yml | |
--- | |
- name: govtech-sgcore-experiments-interal-playbook-scheduling-v1 | |
hosts: localhost | |
vars: | |
time_am_min: 0 | |
time_am_max: 600 | |
time_pm_min: 2000 | |
time_pm_max: 2359 | |
# Use this if timing list iteration needed | |
time_run_cycle: | |
- 2030 | |
- 2100 | |
- 2130 | |
- 2200 | |
- 2230 | |
- 2300 | |
- 2330 | |
- 0 | |
- 30 | |
- 100 | |
- 130 | |
- 200 | |
- 230 | |
- 300 | |
- 350 | |
- 400 | |
- 430 | |
- 500 | |
- 530 | |
- 600 | |
##### For discussed logic | |
# from time_pm_min to time_pm_max | |
# and | |
# from time_am_min to time_am_max | |
# implem_retries: 20 | |
# implem_delay: 1800 | |
##### For Dev/Testing | |
implem_retries: 10 | |
implem_delay: 3 | |
tasks: | |
- name: | |
Get timestamp from the system - Format - HHMM | |
shell: | |
"date +%H%M" | |
register: | |
tstamp_HHMM | |
- name: | |
Set variables | |
set_fact: | |
##### For discussed production logic | |
# from time_pm_min to time_pm_max | |
# and | |
# from time_am_min to time_am_max | |
cur_time_HHMM: "{{ tstamp_HHMM.stdout }}" | |
##### For Dev/Testing | |
# cur_time_HHMM: 1900 | |
# cur_time_HHMM: 2000 | |
# cur_time_HHMM: 2100 | |
# cur_time_HHMM: 0 | |
# cur_time_HHMM: 100 | |
# cur_time_HHMM: 600 | |
# cur_time_HHMM: 601 | |
- name: System timestamp - HHMM | |
debug: | |
msg: "Current HHMM: {{ cur_time_HHMM }}" | |
#################### | |
##### Variation #1 | |
#################### | |
- name: | |
"Hello With Condition" | |
shell: | |
# do something | |
# command: /sbin/shutdown -t now | |
# Check defer run to later | |
echo "HELLO!!!!!!!!!!!!!!!!!!!!" | |
register: | |
shell_echo_result | |
when: | |
# If outside conditions | |
# "shell_echo_result.stdout": "VARIABLE IS NOT DEFINED!" | |
# Or further handling | |
(cur_time_HHMM >= time_pm_min and cur_time_HHMM <= time_pm_max) | |
or | |
(cur_time_HHMM >= time_am_min and cur_time_HHMM <= time_am_max) | |
- name: Variation \#1 Test Echo Result | |
debug: | |
# var: shell_echo_result.stdout_lines | |
var: shell_echo_result.stdout | |
#################### | |
##### Variation #2 | |
#################### | |
- name: | |
"Hello Retries" | |
shell: | |
# do something | |
# command: /sbin/shutdown -t now | |
# Check defer run to later | |
echo "Again And Again" | |
# create/update some boolean to use as exit flag, if needed. | |
register: | |
shell_echo_result | |
until: | |
# replace below with a boolean variable that | |
# is updated after successful run | |
# - shell_echo_result.stdout == "blahblahblah" | |
- (cur_time_HHMM >= time_pm_min and cur_time_HHMM <= time_pm_max) | |
or | |
(cur_time_HHMM >= time_am_min and cur_time_HHMM <= time_am_max) | |
retries: "{{ implem_retries }}" | |
delay: "{{ implem_delay }}" # seconds | |
ignore_errors: yes | |
# Uncomment below if you need | |
# to end playbook run here. | |
# Tasks below, not executed | |
# - meta: end_play | |
# when: (optional condition) | |
- name: Variation \#2 Test Echo Result | |
debug: | |
# var: shell_echo_result.stdout_lines | |
var: shell_echo_result.stdout | |
#################### | |
##### Variation #3 | |
#################### | |
- block: | |
- name: | |
"Hello Retries In Block" | |
shell: | |
# do something | |
# command: /sbin/shutdown -t now | |
# Check defer run to later | |
echo "Again And Again And Again And Again In Block" | |
# create some boolean to use as exit flag | |
register: | |
shell_echo_result | |
until: | |
# replace below with a boolean variable that | |
# is updated after successful run | |
# - shell_echo_result.stdout == "blahblahblah" | |
- (cur_time_HHMM >= time_pm_min and cur_time_HHMM <= time_pm_max) | |
or | |
(cur_time_HHMM >= time_am_min and cur_time_HHMM <= time_am_max) | |
retries: "{{ implem_retries }}" | |
delay: "{{ implem_delay }}" # seconds | |
ignore_errors: yes | |
# Uncomment below if you need | |
# to end playbook run here. | |
# Tasks below, not executed | |
# - meta: end_play | |
# when: | |
# (cur_time_HHMM >= time_pm_min and cur_time_HHMM <= time_pm_max) | |
# or | |
# (cur_time_HHMM >= time_am_min and cur_time_HHMM <= time_am_max) | |
- name: Variation \#3 Test Echo Result | |
debug: | |
# var: shell_echo_result.stdout_lines | |
var: shell_echo_result.stdout | |
- name: Test Echo End | |
debug: | |
msg: "END OF THE LINE. THANK YOU." | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment