ansible-taler-exchange

Ansible playbook to deploy a production Taler Exchange
Log | Files | Refs | Submodules | README | LICENSE

ansible-pull.sh (1498B)


      1 #!/bin/bash
      2 
      3 {% macro run_playbook(url, name, branch=none) %}
      4   start=$(date +%s)
      5   ansible-pull -U {{ url }} {% if branch is not none %}-C {{ branch}} {% endif %} -d /var/run/ansible/{{ name }}&> /var/log/ansible-{{ name }}.log
      6   code=$?
      7 
      8   if [ -d /var/lib/prometheus/node-exporter ]; then
      9     prom_file="/var/lib/prometheus/node-exporter/ansible-playbook-{{ name }}.prom"
     10     labels="playbook=\"{{ name }}\", playbook_url=\"{{ url }}\", playbook_branch=\"{{ branch }}\""
     11     echo "# HELP ansible_playbook_exit_code The exit code of ansible-pull" > ${prom_file}
     12     echo "# TYPE ansible_playbook_exit_code gauge" >> ${prom_file}
     13     echo "ansible_playbook_exit_code{${labels}} ${code}" >> ${prom_file}
     14 
     15     echo "# HELP ansible_playbook_time The time a playbook took to run, in seconds" >> ${prom_file}
     16     echo "# TYPE ansible_playbook_time gauge" >> ${prom_file}
     17     echo "ansible_playbook_time{${labels}} $(expr $(date +%s) - ${start})" >> ${prom_file}
     18   fi
     19 {%- endmacro %}
     20 
     21 if [ "$1" == "nodisown" ]; then
     22   # Sometimes the $PATH gets messed up in cron, so lets start by setting the record straight
     23   PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
     24 
     25 {{ run_playbook(ansible_local.pull.repo, "ansible-taler-exchange", ansible_local.pull.branch) }}
     26 {% if "additional_playbooks" in ansible_local %}
     27 {% for playbook in ansible_local.additional_playbooks %}
     28 {{ run_playbook(playbook.url, playbook.name, playbook.branch) }}
     29 {% endfor %}
     30 {% endif %}
     31 else
     32   $0 nodisown & disown
     33 fi