Skip to content

Instantly share code, notes, and snippets.

@droopy4096
Last active July 14, 2016 16:51
Show Gist options
  • Save droopy4096/72cabebf90ba76b009d128d7dd82eef2 to your computer and use it in GitHub Desktop.
Save droopy4096/72cabebf90ba76b009d128d7dd82eef2 to your computer and use it in GitHub Desktop.
[pakiti]
mypakiti.stanford.edu
[report]
localhost ansible_connection=local ansible_become=False patch_priority=0
[blacklist]
failedhost1.stanford.edu # Incorrect sudo password
failedhost2.stanford.edu # SyntaxError: probably due to installed simplejson being for a different python version; easy_install'ed simplejson which breaks things
- name: collect ansible facts
setup:
ignore_errors: True
register: setup_run
- name: set priority for broken_hosts
set_fact: patch_priority=0
when: setup_run|failed
- name: collect facter facts
facter:
- name: collect pakiti hosts information
pakiti_list_servers:
register: pakiti_hostlist
- name: Add pakiti-provided hosts
add_host: name={{ item }} groups=pakiti_hosts
when: pakiti_hostlist.ansible_facts.hosts[item].age == 0 and not item in groups.blacklist
with_items: '{{ pakiti_hostlist.ansible_facts.hosts }}'
- name: Add pakiti-provided dead hosts
add_host: name={{ item }} groups=pakiti_dead_hosts
when: pakiti_hostlist.ansible_facts.hosts[item].age > 0
with_items: '{{ pakiti_hostlist.ansible_facts.hosts }}'
- name: generate the report
template: src=priority_report.j2 dest=reports/priority_report.txt
Alive hosts
===========
{%+ for host in groups['pakiti_hosts'] %}
{%+ if hostvars[host] is defined %}
{%+ if hostvars[host].facter_patch_priority is defined %}
{{ host }} {{ hostvars[host].facter_patch_priority }}
{% else %}
{{ host }} NA
{% endif %}
{% endif %}
{% endfor %}
Dead hosts
==========
According to Pakiti those hosts are dead:
{%+ for host in groups['pakiti_dead_hosts'] %}
{{ host }}
{% endfor %}
Blacklisted hosts
=================
{%+ for host in groups['blacklist'] %}
{{ host }}
{% endfor %}
- hosts: pakiti
gather_facts: False
roles:
- role: pakiti_db
- hosts: pakiti_hosts,!report
gather_facts: False
roles:
- role: common
- hosts: pakiti_hosts,!report
gather_facts: False
tasks:
- name: check facts
debug: msg={{ facter_patch_priority }}
ignore_errors: yes
when: facter_patch_priority is defined
- hosts: report
gather_facts: False
roles:
- role: priority_report
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment