Skip to content

Instantly share code, notes, and snippets.

@lmayorga1980
Last active July 5, 2024 20:56
Show Gist options
  • Save lmayorga1980/55c0e479bf65273be862b81371e46316 to your computer and use it in GitHub Desktop.
Save lmayorga1980/55c0e479bf65273be862b81371e46316 to your computer and use it in GitHub Desktop.
Fault Tolerance Ansible

Instructions

  • Launch 2 minimal local webservers
#.gitconfig file exists on 8081
python3 -m http.server --bind 127.0.0.1 8081
#.gitconfig file does not exist on 8080
python3 -m http.server --bind 127.0.0.1 8080

---
- name: Fault Tolerance
hosts: all
connection: local
gather_facts: true
vars:
filename: ".gitconfig"
tasks:
- name: Download .gitconfig from unreliable source
ansible.builtin.get_url:
url: http://localhost:8080/{{filename}}
dest: /tmp/{{filename}}
mode: '0644'
retries: 3
delay: 3
register: result
until: result.status_code == 200
ignore_errors: true
- name: Print results
ansible.builtin.debug:
msg: "{{ result }}"
- name: Download .gitconfig from reliable source
ansible.builtin.get_url:
url: http://localhost:8081/{{filename}}
dest: /Users/User1/repos/ansible/fault-tol/{{filename}}
mode: '0644'
force: true
when: result.status_code != 200
retries: 3
delay: 3
register: retry_url
until: retry_url.status_code == 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment