<!DOCTYPE html><html><head><title></title><style type="text/css">
p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div>## Step 5 of ?: install_service.yml<br></div><div><br></div><div>Ansible by default uses the Jinja2 templating system<br></div><div>(pretty similar to Mustache and Handlebars). In your instructions<br></div><div>you have SITENAME that is a per-host variable, so I'll go back to my<br></div><div>inventory file and augment the host configs with it:<br></div><div><br></div><div>```<br></div><div>all:<br></div><div>  hosts:<br></div><div>    'william.charlotte.us':<br></div><div>      ansible_ssh_host: 192.168.0.103<br></div><div>      sitename: william<br></div><div>   children:<br></div><div>    onboarding:<br></div><div>      hosts:<br></div><div>        'yanick.ottawa.ca':<br></div><div>          sitename: yanick<br></div><div>          ansible_ssh_host: 192.168.0.101<br></div><div>          ansible_ssh_user: yanick<br></div><div>```<br></div><div><br></div><div>I'll assume that `cv.service` is a template (that I'll rename<br></div><div>`cv.service.jinja2`) that might have some tweaks for the<br></div><div>different installs.<br></div><div><br></div><div>So let's do this:<br></div><div><br></div><div>```<br></div><div># in roles/onboard/tasks/install_service.yml<br></div><div><br></div><div>- name: install service script<br></div><div>  # become means "become the super-user"<br></div><div>  become: yes<br></div><div>  template:<br></div><div>    src: ../files/cv.service.jinja2<br></div><div>    dest: /etc/systemd/system/cv.service<br></div><div>    mode: '644'<br></div><div>   <br></div><div><br></div><div>- name: ensure the service is running<br></div><div>  service:<br></div><div>    name: cv<br></div><div>    enabled: yes<br></div><div>    state: started<br></div><div><br></div><div>```<br></div><div><br></div><div><br></div><div>More to come,<br></div><div>`/anick`<br></div><div><br></div></body></html>