<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:og="http://ogp.me/ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:schema="http://schema.org/" xmlns:sioc="http://rdfs.org/sioc/ns#" xmlns:sioct="http://rdfs.org/sioc/types#" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" version="2.0" xml:base="http://badzilla.co.uk/">
  <channel>
    <title>Ansible</title>
    <link>http://badzilla.co.uk/</link>
    <description/>
    <language>en</language>
    
    <item>
  <title>Restoring an accidentally deleted .vagrant directory</title>
  <link>http://badzilla.co.uk/restoring-accidentally-deleted-vagrant-directory</link>
  <description>
&lt;span&gt;Restoring an accidentally deleted .vagrant directory&lt;/span&gt;

&lt;span&gt;&lt;span lang="" about="http://badzilla.co.uk/user/1" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;nigel&lt;/span&gt;&lt;/span&gt;

&lt;span&gt;Sat, 12/02/2022 - 11:30&lt;/span&gt;

      &lt;div class="field field--name-field-heading-image-text field--type-entity-reference-revisions field--label-hidden field--items"&gt;
              &lt;div class="field--item"&gt;  &lt;div class="paragraph paragraph--type--blog-heading-picture-text paragraph--view-mode--default"&gt;
          
            &lt;div class="field field--name-field-heading field--type-string field--label-hidden field--item"&gt;Introduction&lt;/div&gt;
      
      &lt;div class="field field--name-field-blog-image field--type-image field--label-hidden field--items"&gt;
              &lt;div class="field--item"&gt;    &lt;img srcset="https://assets.badzilla.co.uk/styles/max_325x325/s3/2022-02/Screenshot%202022-02-12%20at%2010.30.27-edited.png?itok=mg5i3p8I 325w, https://assets.badzilla.co.uk/styles/max_650x650/s3/2022-02/Screenshot%202022-02-12%20at%2010.30.27-edited.png?itok=z96fRlXO 650w, https://assets.badzilla.co.uk/styles/max_1300x1300/s3/2022-02/Screenshot%202022-02-12%20at%2010.30.27-edited.png?itok=XutDG0Ce 1300w, https://assets.badzilla.co.uk/styles/max_2600x2600/s3/2022-02/Screenshot%202022-02-12%20at%2010.30.27-edited.png?itok=AwdP7q2o 1904w" sizes="(min-width: 1290px) 1290px, 100vw" src="https://assets.badzilla.co.uk/styles/max_325x325/s3/2022-02/Screenshot%202022-02-12%20at%2010.30.27-edited.png?itok=mg5i3p8I" alt="vbox" typeof="foaf:Image" class="img-responsive" /&gt;


&lt;/div&gt;
          &lt;/div&gt;
  
            &lt;div class="field field--name-field-blog-text field--type-text-long field--label-hidden field--item"&gt;&lt;p&gt;I woke up one morning to discover to my horror all my virtual machines had disappeared off my Macbook! This was disconcerting to say the least! Opening VirtualBox UI revealed that it had 'lost' all my VMs - the list of available VMs in the left hand pane was totally empty.&lt;/p&gt;

&lt;p&gt;My VMs are kept on a USB memory stick which may have been a contributory factor, but the drive had not been ejected as far as I could tell. &lt;/p&gt;

&lt;p&gt;It was early morning, I hadn't had a coffee when I started to troubleshoot, and I stupidly decided to see if I could &lt;em&gt;vagrant up&lt;/em&gt; my most precious project - my football statistics website. Disaster! Vagrant immediately tried to download a fresh copy of Ubuntu from the cloud so I hit ctrl-c. I'm unsure what happened next - perhaps I deleted the &lt;em&gt;.vagrant&lt;/em&gt; directory to try and fix things; perhaps Vagrant did. It was probably the former. &lt;/p&gt;

&lt;p&gt;Regardless of blame, I was forced to find a way of regenerating the .&lt;em&gt;vagrant&lt;/em&gt; directory so that my football VM would load correctly. These are the steps I took. &lt;/p&gt;&lt;/div&gt;
      
      &lt;/div&gt;
&lt;/div&gt;
              &lt;div class="field--item"&gt;  &lt;div class="paragraph paragraph--type--blog-heading-picture-text paragraph--view-mode--default"&gt;
          
            &lt;div class="field field--name-field-heading field--type-string field--label-hidden field--item"&gt;Import VMs back into Virtual Box UI&lt;/div&gt;
      
            &lt;div class="field field--name-field-blog-text field--type-text-long field--label-hidden field--item"&gt;&lt;p&gt;The first thing to do is import the VMs back into the Virtual Box UI. This is quite easy - click on the &lt;em&gt;Tools&lt;/em&gt; part of the UI which will expose the large plus sign, which will open a file system dialog box, then navigate to the directory where the VMs are stored. There will be a directory per VM - open up the directory you want according to its name, then select the&lt;em&gt; .vbox&lt;/em&gt; file. That will import the VM. You can see I've already done this for five of my VMs. I will import more of the 30 or so left if I find I need them again!&lt;/p&gt;&lt;/div&gt;
      
      &lt;/div&gt;
&lt;/div&gt;
              &lt;div class="field--item"&gt;  &lt;div class="paragraph paragraph--type--blog-heading-picture-text paragraph--view-mode--default"&gt;
          
            &lt;div class="field field--name-field-heading field--type-string field--label-hidden field--item"&gt;Re-associate VM with Vagrant&lt;/div&gt;
      
            &lt;div class="field field--name-field-blog-text field--type-text-long field--label-hidden field--item"&gt;So importing the VM into VirtualBox won't automatically associate the VM with Vagrant. Any attempt to &lt;em&gt;vagrant up&lt;/em&gt; will result in Vagrant fetching a new instance from the Cloud. The trick is to manually create the starting point of a &lt;em&gt;.vagrant&lt;/em&gt; directory with an &lt;em&gt;id&lt;/em&gt; file which will contain the VM's unique identity. The identifier can be obtained by using the &lt;em&gt;VBoxManage list vms&lt;/em&gt; command. This can be explained better below:
&lt;div class="geshifilter"&gt;&lt;div class="bash geshifilter-bash" style="font-family:monospace;"&gt;&lt;pre style="font-family: monospace; font-weight: normal; font-style: normal"&gt;$ VBoxManage list vms &lt;span style="color: #000000; font-weight: bold;"&gt;|&lt;/span&gt; &lt;span style="color: #c20cb9; font-weight: bold;"&gt;grep&lt;/span&gt; Football
&lt;span style="color: #ff0000;"&gt;"Football VM"&lt;/span&gt; &lt;span style="color: #7a0874; font-weight: bold;"&gt;{&lt;/span&gt;b2f47455-eee0-457c-93a4-4d0f840598e0&lt;span style="color: #7a0874; font-weight: bold;"&gt;}&lt;/span&gt;
$ &lt;span style="color: #c20cb9; font-weight: bold;"&gt;mkdir&lt;/span&gt; &lt;span style="color: #660033;"&gt;-p&lt;/span&gt; .vagrant&lt;span style="color: #000000; font-weight: bold;"&gt;/&lt;/span&gt;machines&lt;span style="color: #000000; font-weight: bold;"&gt;/&lt;/span&gt;default&lt;span style="color: #000000; font-weight: bold;"&gt;/&lt;/span&gt;virtualbox
$ &lt;span style="color: #c20cb9; font-weight: bold;"&gt;touch&lt;/span&gt; .vagrant&lt;span style="color: #000000; font-weight: bold;"&gt;/&lt;/span&gt;machines&lt;span style="color: #000000; font-weight: bold;"&gt;/&lt;/span&gt;default&lt;span style="color: #000000; font-weight: bold;"&gt;/&lt;/span&gt;virtualbox&lt;span style="color: #000000; font-weight: bold;"&gt;/&lt;/span&gt;&lt;span style="color: #c20cb9; font-weight: bold;"&gt;id&lt;/span&gt;
$ &lt;span style="color: #7a0874; font-weight: bold;"&gt;echo&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;"b2f47455-eee0-457c-93a4-4d0f840598e0"&lt;/span&gt; &lt;span style="color: #000000; font-weight: bold;"&gt;&gt;&lt;/span&gt; .vagrant&lt;span style="color: #000000; font-weight: bold;"&gt;/&lt;/span&gt;machines&lt;span style="color: #000000; font-weight: bold;"&gt;/&lt;/span&gt;default&lt;span style="color: #000000; font-weight: bold;"&gt;/&lt;/span&gt;virtualbox&lt;span style="color: #000000; font-weight: bold;"&gt;/&lt;/span&gt;&lt;span style="color: #c20cb9; font-weight: bold;"&gt;id&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

Before I typed those commands I had already moved to the project's directory. I then got the unique identifier of the VM, recreated the directory structure  and the id file, the copied the id into the file.&lt;/div&gt;
      
      &lt;/div&gt;
&lt;/div&gt;
              &lt;div class="field--item"&gt;  &lt;div class="paragraph paragraph--type--blog-heading-picture-text paragraph--view-mode--default"&gt;
          
            &lt;div class="field field--name-field-heading field--type-string field--label-hidden field--item"&gt;SSH Authentication&lt;/div&gt;
      
            &lt;div class="field field--name-field-blog-text field--type-text-long field--label-hidden field--item"&gt;Doing a &lt;em&gt;vagrant up&lt;/em&gt; will get you so far - the box will indeed start up (like if you invoked it in the Virtual Box UI) but the authentication will fail. However it's worth doing this and hitting ctrl-c when the authentication fails because &lt;em&gt;Vagrant&lt;/em&gt; will recreate the remainder of the &lt;em&gt;.vagrant&lt;/em&gt; directory for you and the VM will be running - essential for the next instruction.
&lt;div class="geshifilter"&gt;&lt;div class="bash geshifilter-bash" style="font-family:monospace;"&gt;&lt;pre style="font-family: monospace; font-weight: normal; font-style: normal"&gt;$ vagrant up
Bringing machine &lt;span style="color: #ff0000;"&gt;'default'&lt;/span&gt; up with &lt;span style="color: #ff0000;"&gt;'virtualbox'&lt;/span&gt; provider...
==&lt;span style="color: #000000; font-weight: bold;"&gt;&gt;&lt;/span&gt; default: &lt;span style="color: #7a0874; font-weight: bold;"&gt;[&lt;/span&gt;vagrant-hostsupdater&lt;span style="color: #7a0874; font-weight: bold;"&gt;]&lt;/span&gt; Checking &lt;span style="color: #000000; font-weight: bold;"&gt;for&lt;/span&gt; host entries
==&lt;span style="color: #000000; font-weight: bold;"&gt;&gt;&lt;/span&gt; default: &lt;span style="color: #7a0874; font-weight: bold;"&gt;[&lt;/span&gt;vagrant-hostsupdater&lt;span style="color: #7a0874; font-weight: bold;"&gt;]&lt;/span&gt; Checking &lt;span style="color: #000000; font-weight: bold;"&gt;for&lt;/span&gt; host entries
==&lt;span style="color: #000000; font-weight: bold;"&gt;&gt;&lt;/span&gt; default: Checking &lt;span style="color: #000000; font-weight: bold;"&gt;if&lt;/span&gt; box &lt;span style="color: #ff0000;"&gt;'geerlingguy/ubuntu1804'&lt;/span&gt; version &lt;span style="color: #ff0000;"&gt;'1.1.9'&lt;/span&gt; is up to date...
==&lt;span style="color: #000000; font-weight: bold;"&gt;&gt;&lt;/span&gt; default: &lt;span style="color: #7a0874; font-weight: bold;"&gt;[&lt;/span&gt;vagrant-hostsupdater&lt;span style="color: #7a0874; font-weight: bold;"&gt;]&lt;/span&gt; Checking &lt;span style="color: #000000; font-weight: bold;"&gt;for&lt;/span&gt; host entries
==&lt;span style="color: #000000; font-weight: bold;"&gt;&gt;&lt;/span&gt; default: &lt;span style="color: #7a0874; font-weight: bold;"&gt;[&lt;/span&gt;vagrant-hostsupdater&lt;span style="color: #7a0874; font-weight: bold;"&gt;]&lt;/span&gt; Checking &lt;span style="color: #000000; font-weight: bold;"&gt;for&lt;/span&gt; host entries
==&lt;span style="color: #000000; font-weight: bold;"&gt;&gt;&lt;/span&gt; default: &lt;span style="color: #7a0874; font-weight: bold;"&gt;[&lt;/span&gt;vagrant-hostsupdater&lt;span style="color: #7a0874; font-weight: bold;"&gt;]&lt;/span&gt; Checking &lt;span style="color: #000000; font-weight: bold;"&gt;for&lt;/span&gt; host entries
==&lt;span style="color: #000000; font-weight: bold;"&gt;&gt;&lt;/span&gt; default: Clearing any previously &lt;span style="color: #000000; font-weight: bold;"&gt;set&lt;/span&gt; forwarded ports...
==&lt;span style="color: #000000; font-weight: bold;"&gt;&gt;&lt;/span&gt; default: Fixed port collision &lt;span style="color: #000000; font-weight: bold;"&gt;for&lt;/span&gt; &lt;span style="color: #000000;"&gt;22&lt;/span&gt; =&lt;span style="color: #000000; font-weight: bold;"&gt;&gt;&lt;/span&gt; &lt;span style="color: #000000;"&gt;2222&lt;/span&gt;. Now on port &lt;span style="color: #000000;"&gt;2200&lt;/span&gt;.
==&lt;span style="color: #000000; font-weight: bold;"&gt;&gt;&lt;/span&gt; default: Clearing any previously &lt;span style="color: #000000; font-weight: bold;"&gt;set&lt;/span&gt; network interfaces...
==&lt;span style="color: #000000; font-weight: bold;"&gt;&gt;&lt;/span&gt; default: Preparing network interfaces based on configuration...
    default: Adapter &lt;span style="color: #000000;"&gt;1&lt;/span&gt;: nat
    default: Adapter &lt;span style="color: #000000;"&gt;2&lt;/span&gt;: hostonly
==&lt;span style="color: #000000; font-weight: bold;"&gt;&gt;&lt;/span&gt; default: Forwarding ports...
    default: &lt;span style="color: #000000;"&gt;22&lt;/span&gt; &lt;span style="color: #7a0874; font-weight: bold;"&gt;(&lt;/span&gt;guest&lt;span style="color: #7a0874; font-weight: bold;"&gt;)&lt;/span&gt; =&lt;span style="color: #000000; font-weight: bold;"&gt;&gt;&lt;/span&gt; &lt;span style="color: #000000;"&gt;2200&lt;/span&gt; &lt;span style="color: #7a0874; font-weight: bold;"&gt;(&lt;/span&gt;host&lt;span style="color: #7a0874; font-weight: bold;"&gt;)&lt;/span&gt; &lt;span style="color: #7a0874; font-weight: bold;"&gt;(&lt;/span&gt;adapter &lt;span style="color: #000000;"&gt;1&lt;/span&gt;&lt;span style="color: #7a0874; font-weight: bold;"&gt;)&lt;/span&gt;
==&lt;span style="color: #000000; font-weight: bold;"&gt;&gt;&lt;/span&gt; default: &lt;span style="color: #7a0874; font-weight: bold;"&gt;[&lt;/span&gt;vagrant-hostsupdater&lt;span style="color: #7a0874; font-weight: bold;"&gt;]&lt;/span&gt; Checking &lt;span style="color: #000000; font-weight: bold;"&gt;for&lt;/span&gt; host entries
==&lt;span style="color: #000000; font-weight: bold;"&gt;&gt;&lt;/span&gt; default: Running &lt;span style="color: #ff0000;"&gt;'pre-boot'&lt;/span&gt; VM customizations...
==&lt;span style="color: #000000; font-weight: bold;"&gt;&gt;&lt;/span&gt; default: Booting VM...
==&lt;span style="color: #000000; font-weight: bold;"&gt;&gt;&lt;/span&gt; default: Waiting &lt;span style="color: #000000; font-weight: bold;"&gt;for&lt;/span&gt; machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:&lt;span style="color: #000000;"&gt;2200&lt;/span&gt;
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
^&lt;span style="color: #007800;"&gt;C&lt;/span&gt;==&lt;span style="color: #000000; font-weight: bold;"&gt;&gt;&lt;/span&gt; default: Waiting &lt;span style="color: #000000; font-weight: bold;"&gt;for&lt;/span&gt; cleanup before exiting...&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
The SSH configuration can be determined by:
&lt;div class="geshifilter"&gt;&lt;div class="bash geshifilter-bash" style="font-family:monospace;"&gt;&lt;pre style="font-family: monospace; font-weight: normal; font-style: normal"&gt;$ vagrant ssh-config
Host default
  HostName 127.0.0.1
  User vagrant
  Port &lt;span style="color: #000000;"&gt;2200&lt;/span&gt;
  UserKnownHostsFile &lt;span style="color: #000000; font-weight: bold;"&gt;/&lt;/span&gt;dev&lt;span style="color: #000000; font-weight: bold;"&gt;/&lt;/span&gt;null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile &lt;span style="color: #000000; font-weight: bold;"&gt;/&lt;/span&gt;Users&lt;span style="color: #000000; font-weight: bold;"&gt;/&lt;/span&gt;nigel&lt;span style="color: #000000; font-weight: bold;"&gt;/&lt;/span&gt;.vagrant.d&lt;span style="color: #000000; font-weight: bold;"&gt;/&lt;/span&gt;insecure_private_key
  IdentitiesOnly &lt;span style="color: #c20cb9; font-weight: bold;"&gt;yes&lt;/span&gt;
  LogLevel FATAL&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
The SSH key we need to use must be known to the local ssh-agent. Find out which keys are available with the command below. You will almost certainly have at least one entry - the one you use for &lt;em&gt;git&lt;/em&gt;.
&lt;div class="geshifilter"&gt;&lt;div class="bash geshifilter-bash" style="font-family:monospace;"&gt;&lt;pre style="font-family: monospace; font-weight: normal; font-style: normal"&gt;&lt;span style="color: #666666;"&gt;$ &lt;/span&gt;&lt;span style="color: #c20cb9; font-weight: bold;"&gt;ssh-add&lt;/span&gt; &lt;span style="color: #660033;"&gt;-L&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
Usually the default &lt;em&gt;id_rsa&lt;/em&gt; will be available. Pick one. Whichever is chosen, copy the private part of the key into the &lt;em&gt;IdentityFile&lt;/em&gt; mentioned above in the output of the &lt;em&gt;vagrant ssh-config&lt;/em&gt; command, overwriting the content already in the file. 
Now do:
&lt;div class="geshifilter"&gt;&lt;div class="bash geshifilter-bash" style="font-family:monospace;"&gt;&lt;pre style="font-family: monospace; font-weight: normal; font-style: normal"&gt;$ vagrant halt
$ vagrant up&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
      
      &lt;/div&gt;
&lt;/div&gt;
              &lt;div class="field--item"&gt;  &lt;div class="paragraph paragraph--type--blog-heading-picture-text paragraph--view-mode--default"&gt;
          
            &lt;div class="field field--name-field-heading field--type-string field--label-hidden field--item"&gt;Wrap Up&lt;/div&gt;
      
      &lt;div class="field field--name-field-blog-image field--type-image field--label-hidden field--items"&gt;
              &lt;div class="field--item"&gt;    &lt;img srcset="https://assets.badzilla.co.uk/styles/max_325x325/s3/2022-02/Screenshot%202022-02-12%20at%2015.28.34.png?itok=-J8DWcrD 325w, https://assets.badzilla.co.uk/styles/max_650x650/s3/2022-02/Screenshot%202022-02-12%20at%2015.28.34.png?itok=nGmsaxuu 650w, https://assets.badzilla.co.uk/styles/max_1300x1300/s3/2022-02/Screenshot%202022-02-12%20at%2015.28.34.png?itok=Z1NzSaRp 1300w, https://assets.badzilla.co.uk/styles/max_2600x2600/s3/2022-02/Screenshot%202022-02-12%20at%2015.28.34.png?itok=dBnJ9Moz 1916w" sizes="(min-width: 1290px) 1290px, 100vw" src="https://assets.badzilla.co.uk/styles/max_325x325/s3/2022-02/Screenshot%202022-02-12%20at%2015.28.34.png?itok=-J8DWcrD" alt="Ansible" typeof="foaf:Image" class="img-responsive" /&gt;


&lt;/div&gt;
          &lt;/div&gt;
  
            &lt;div class="field field--name-field-blog-text field--type-text-long field--label-hidden field--item"&gt;&lt;p&gt;Your system shoud now be back! My Vagrantfile runs an Ansible playbook containing my VM config - as can be seen in the screenshot above. Once that completed I could ssh into the VM as normal. All good!!&lt;/p&gt;&lt;/div&gt;
      
      &lt;/div&gt;
&lt;/div&gt;
          &lt;/div&gt;
  
      &lt;div class="field field--name-field-blog-youtube field--type-entity-reference-revisions field--label-hidden field--items"&gt;
              &lt;div class="field--item"&gt;  &lt;div class="paragraph paragraph--type--blog-text-youtube paragraph--view-mode--default"&gt;
          
      &lt;/div&gt;
&lt;/div&gt;
          &lt;/div&gt;
  
  &lt;div class="field field--name-field-blog-terms field--type-entity-reference field--label-inline"&gt;
    &lt;div class="field--label"&gt;blog terms&lt;/div&gt;
          &lt;span class="field__items"&gt;
              &lt;span class="field--item"&gt;&lt;a href="http://badzilla.co.uk/development" hreflang="en"&gt;Development&lt;/a&gt;&lt;/span&gt;
          &lt;span class="field--item"&gt;&lt;a href="http://badzilla.co.uk/virtualbox" hreflang="en"&gt;VirtualBox&lt;/a&gt;&lt;/span&gt;
          &lt;span class="field--item"&gt;&lt;a href="http://badzilla.co.uk/ansible" hreflang="en"&gt;Ansible&lt;/a&gt;&lt;/span&gt;
              &lt;/span&gt;
      &lt;/div&gt;
</description>
  <pubDate>Sat, 12 Feb 2022 11:30:59 +0000</pubDate>
    <dc:creator>nigel</dc:creator>
    <guid isPermaLink="false">183 at http://badzilla.co.uk</guid>
    </item>
<item>
  <title>Ansible Tasks: Create symbolic links for NGINX / Apache sites-enabled directory</title>
  <link>http://badzilla.co.uk/ansible-tasks-create-symbolic-links-nginx-apache-sites-enabled-directory</link>
  <description>
&lt;span&gt;Ansible Tasks: Create symbolic links for NGINX / Apache sites-enabled directory&lt;/span&gt;

&lt;span&gt;&lt;span lang="" about="http://badzilla.co.uk/user/1" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;nigel&lt;/span&gt;&lt;/span&gt;

&lt;span&gt;Sun, 01/07/2018 - 11:25&lt;/span&gt;

      &lt;div class="field field--name-field-heading-image-text field--type-entity-reference-revisions field--label-hidden field--items"&gt;
              &lt;div class="field--item"&gt;  &lt;div class="paragraph paragraph--type--blog-heading-picture-text paragraph--view-mode--default"&gt;
          
            &lt;div class="field field--name-field-heading field--type-string field--label-hidden field--item"&gt;Introduction&lt;/div&gt;
      
            &lt;div class="field field--name-field-blog-text field--type-text-long field--label-hidden field--item"&gt;&lt;p&gt;My first blog on Ansible, and it's here because it took me so long to figure it out. Ansible documentation is excellent - but of course like everything in life, if you aren't aware of all the concepts, it's difficult to know where to look first. &lt;/p&gt;
&lt;p&gt;My requirement was to create symbolic links to the &lt;strong&gt;&lt;em&gt;/etc/nginx/sites-enabled&lt;/em&gt;&lt;/strong&gt; directory by looping through all the &lt;strong&gt;&lt;em&gt;conf&lt;/em&gt;&lt;/strong&gt; files in &lt;strong&gt;&lt;em&gt;/etc/nginx/sites-available&lt;/em&gt;&lt;/strong&gt;. This is equally valid for Apache servers which support the same mechanism for defining virtual hosts. I am currently building a VM for Drupal development and I am using Ansible for the configuration. &lt;/p&gt;
&lt;p&gt;So my solution uses the find module to capture a list of &lt;em&gt;&lt;strong&gt;conf&lt;/strong&gt;&lt;/em&gt; files in &lt;em&gt;&lt;strong&gt;/etc/nginx/sites-available&lt;/strong&gt;&lt;/em&gt; and those are then saved in &lt;strong&gt;&lt;em&gt;register&lt;/em&gt;&lt;/strong&gt; for future usage. The file &lt;em&gt;&lt;strong&gt;module&lt;/strong&gt;&lt;/em&gt; is then invoked which will use the registered &lt;strong&gt;&lt;em&gt;conf&lt;/em&gt;&lt;/strong&gt; files. Note the placeholder on the destination directory - I need to access the item path but then filter it through &lt;em&gt;&lt;strong&gt;basename&lt;/strong&gt;&lt;/em&gt; to get the value I need. The &lt;em&gt;&lt;strong&gt;force&lt;/strong&gt;&lt;/em&gt; option is required because the nginx role I use already to build out the nginx configuration creates a &lt;em&gt;&lt;strong&gt;default&lt;/strong&gt;&lt;/em&gt; link which already exists and could choke my attempt to create a link for everything in &lt;strong&gt;&lt;em&gt;/etc/nginx/sites-available.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/div&gt;
      
      &lt;/div&gt;
&lt;/div&gt;
              &lt;div class="field--item"&gt;  &lt;div class="paragraph paragraph--type--blog-heading-picture-text paragraph--view-mode--default"&gt;
          
            &lt;div class="field field--name-field-heading field--type-string field--label-hidden field--item"&gt;Code Snippet&lt;/div&gt;
      
            &lt;div class="field field--name-field-blog-text field--type-text-long field--label-hidden field--item"&gt;&lt;div class="geshifilter"&gt;&lt;div class="yaml geshifilter-yaml" style="font-family:monospace;"&gt;&lt;pre style="font-family: monospace; font-weight: normal; font-style: normal"&gt;&lt;span style="color: green;"&gt;  tasks&lt;/span&gt;&lt;span style="font-weight: bold; color: brown;"&gt;: &lt;/span&gt;
 
    &lt;span style="color: blue;"&gt;# Set symlinks to nginx sites-available directory&lt;/span&gt;&lt;span style="color: green;"&gt;
    - name&lt;/span&gt;&lt;span style="font-weight: bold; color: brown;"&gt;: &lt;/span&gt;Get a list of &lt;span style="font-weight: bold;"&gt;all&lt;/span&gt; vhosts&lt;span style="color: #007F45;"&gt;
      find&lt;/span&gt;:&lt;span style="color: green;"&gt;
        paths&lt;/span&gt;&lt;span style="font-weight: bold; color: brown;"&gt;: &lt;/span&gt;/etc/nginx/sites-available&lt;span style="color: green;"&gt;
        patterns&lt;/span&gt;&lt;span style="font-weight: bold; color: brown;"&gt;: &lt;/span&gt;&lt;span style="color: #CF00CF;"&gt;"*.conf"&lt;/span&gt;&lt;span style="color: green;"&gt;
        file_type&lt;/span&gt;&lt;span style="font-weight: bold; color: brown;"&gt;: &lt;/span&gt;file&lt;span style="color: green;"&gt;
      register&lt;/span&gt;&lt;span style="font-weight: bold; color: brown;"&gt;: &lt;/span&gt;find
&lt;span style="color: green;"&gt;
    - name&lt;/span&gt;&lt;span style="font-weight: bold; color: brown;"&gt;: &lt;/span&gt;Apply symlinks in sites-enabled&lt;span style="color: #007F45;"&gt;
      file&lt;/span&gt;:&lt;span style="color: green;"&gt;
        dest&lt;/span&gt;&lt;span style="font-weight: bold; color: brown;"&gt;: &lt;/span&gt;/etc/nginx/sites-enabled/&lt;span class="br0"&gt;{&lt;/span&gt;&lt;span class="br0"&gt;{&lt;/span&gt; item.path | basename &lt;span class="br0"&gt;}&lt;/span&gt;&lt;span class="br0"&gt;}&lt;/span&gt;&lt;span style="color: green;"&gt;
        src&lt;/span&gt;&lt;span style="font-weight: bold; color: brown;"&gt;: &lt;/span&gt;&lt;span style="color: #CF00CF;"&gt;"{{ item.path }}"&lt;/span&gt;&lt;span style="color: green;"&gt;
        state&lt;/span&gt;&lt;span style="font-weight: bold; color: brown;"&gt;: &lt;/span&gt;link&lt;span style="color: green;"&gt;
        force&lt;/span&gt;&lt;span style="font-weight: bold; color: brown;"&gt;: &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;yes&lt;/span&gt;&lt;span style="color: green;"&gt;
      with_items&lt;/span&gt;&lt;span style="font-weight: bold; color: brown;"&gt;: &lt;/span&gt;&lt;span style="color: #CF00CF;"&gt;"{{ find.files }}"&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
      
      &lt;/div&gt;
&lt;/div&gt;
          &lt;/div&gt;
  
      &lt;div class="field field--name-field-blog-youtube field--type-entity-reference-revisions field--label-hidden field--items"&gt;
              &lt;div class="field--item"&gt;  &lt;div class="paragraph paragraph--type--blog-text-youtube paragraph--view-mode--default"&gt;
          
      &lt;/div&gt;
&lt;/div&gt;
          &lt;/div&gt;
  
  &lt;div class="field field--name-field-blog-terms field--type-entity-reference field--label-inline"&gt;
    &lt;div class="field--label"&gt;blog terms&lt;/div&gt;
          &lt;span class="field__items"&gt;
              &lt;span class="field--item"&gt;&lt;a href="http://badzilla.co.uk/ansible" hreflang="en"&gt;Ansible&lt;/a&gt;&lt;/span&gt;
          &lt;span class="field--item"&gt;&lt;a href="http://badzilla.co.uk/devops" hreflang="en"&gt;devops&lt;/a&gt;&lt;/span&gt;
          &lt;span class="field--item"&gt;&lt;a href="http://badzilla.co.uk/nginx" hreflang="en"&gt;nginx&lt;/a&gt;&lt;/span&gt;
          &lt;span class="field--item"&gt;&lt;a href="http://badzilla.co.uk/apache" hreflang="en"&gt;Apache&lt;/a&gt;&lt;/span&gt;
              &lt;/span&gt;
      &lt;/div&gt;
</description>
  <pubDate>Sun, 01 Jul 2018 10:25:47 +0000</pubDate>
    <dc:creator>nigel</dc:creator>
    <guid isPermaLink="false">146 at http://badzilla.co.uk</guid>
    </item>

  </channel>
</rss>
