Ansible for derps

Since my level of retardation varies depending on the day, I need to put this somewhere.
Loop_vars causes a segmentation fault in my brain, so hopefully, this example won’t cause me to loose a shit ton time again.

vars.yml


    vhosts:
      - name: clusterfuck
        production: "clusterfuck.community"
        staging: "clusterfuck.community"
        sandbox1: "clusterfuck.community"

      - name: dirtyinode
        production: "dirtyinode.me"
        staging: "dirtyinode.me"
        sandbox1: "dirtyinode.me"

The main task that allows loop control (configure_sites.yml):


- include_tasks: configure_sites_chilf.yml
  with_items: "{{ vhosts }}"
  loop_control:
    loop_var: website


- include_tasks: configure_sites_child.yml
  with_items: "{{ vhosts }}"
  loop_control:
    loop_var: website

The child task that receives the parced vars (var name changed from item to website)
configure_sites_child.yml

# env_name comes from another ansible var, created somewhere else in the playbook
# basically, it's prod, stage, dev, etc.
# can use ec2_tag instead
- set_fact:
    website_url: "website.{{ env_name }}"
- name: Generate https sites conf files
  template:
    src: sites/generic.conf.j2
    dest: /etc/nginx/sites-available/{{ item.name }}.conf
  with_items:
    - "{{ website }}"


There you go, future self, hope you fucking derped less this time.

Leave a Reply

Your email address will not be published. Required fields are marked *