Skip to content

Instantly share code, notes, and snippets.

@EyePulp
Created November 8, 2013 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EyePulp/7378732 to your computer and use it in GitHub Desktop.
Save EyePulp/7378732 to your computer and use it in GitHub Desktop.
Wondering about variable scopes -- If I include the same playbook (autossh.yaml, as seen below) twice, what is the scope of the variables defined with each call? Would the second include call continue to have all the values defined from the first call? e.g. would the second include in playbook.yaml have a defined or undefined value for AUTOSSH_P…
---
# set up an ssh tunnel
# using the following variables
# {{AUTOSSH_PUBLIC_KEY_SRC}}
# {{AUTOSSH_PUBLIC_KEY_DEST}}
# {{AUTOSSH_PRIVATE_KEY_SRC}}
# {{AUTOSSH_PRIVATE_KEY_DEST}}
# {{AUTOSSH_UPSTART_SRC}}
# {{AUTOSSH_UPSTART_DEST}}
# {{AUTOSSH_UPSTART_SERVICE}}
- name: AUTOSSH | Install autossh
apt: pkg={{item}} state=present
with_items:
- autossh
sudo: true
tags:
- autossh
- name: AUTOSSH | Upload autossh private key
copy: "src={{AUTOSSH_PRIVATE_KEY_SRC}} dest={{AUTOSSH_PRIVATE_KEY_DEST}} group={{PROJECT_NAME}} owner={{PROJECT_NAME}} mode=0600"
sudo: true
when: AUTOSSH_PRIVATE_KEY_SRC is defined
tags:
- autossh
- name: AUTOSSH | Upload autossh public key
copy: "src={{AUTOSSH_PUBLIC_KEY_SRC}} dest={{AUTOSSH_PUBLIC_KEY_DEST}} group={{PROJECT_NAME}} owner={{PROJECT_NAME}} mode=0600"
sudo: true
when: AUTOSSH_PUBLIC_KEY_SRC is defined
tags:
- autossh
- name: AUTOSSH | Setup upstart file
# template: src=web/autossh.upstart.conf dest=/etc/init/{{PROJECT_NAME}}_autossh.conf owner=root group=root mode=0644
template: "src={{AUTOSSH_UPSTART_SRC}} dest={{AUTOSSH_UPSTART_DEST}} owner=root group=root mode=0644"
sudo: true
sudo_user: root
tags:
- autossh
- name: "AUTOSSH | restart the {{AUTOSSH_UPSTART_SERVICE}} service"
service: "name={{AUTOSSH_UPSTART_SERVICE}} state=restarted"
sudo: true
sudo_user: root
tags:
- autossh
tasks:
- include: "{{TASKS}}/project/autossh.yaml"
vars:
AUTOSSH_PUBLIC_KEY_SRC : "ssh/id_rsa.autossh.pub"
AUTOSSH_PUBLIC_KEY_DEST : "{{PROJECT_ROOT}}/.ssh/id_rsa.autossh.pub"
AUTOSSH_PRIVATE_KEY_SRC : "ssh/id_rsa.autossh"
AUTOSSH_PRIVATE_KEY_DEST : "{{PROJECT_ROOT}}/.ssh/id_rsa.autossh"
AUTOSSH_UPSTART_SRC : "ssh/autossh.redis.upstart.conf"
AUTOSSH_UPSTART_DEST : "/etc/init/{{PROJECT_NAME}}_autossh_redis.conf"
AUTOSSH_UPSTART_SERVICE : "{{PROJECT_NAME}}_autossh_redis"
- include: "{{TASKS}}/project/autossh.yaml"
vars:
AUTOSSH_UPSTART_SRC : "ssh/autossh.cuspidor.upstart.conf"
AUTOSSH_UPSTART_DEST : "/etc/init/{{PROJECT_NAME}}_autossh_cuspidor.conf"
AUTOSSH_UPSTART_SERVICE : "{{PROJECT_NAME}}_autossh_cuspidor"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment