-1

I am using puppet to provision an AWS AMI using packer and then launch the AMI. Puppet does all the configuration and package installations upon baking the AMI which includes installing and configuring apache and wsgi. By the time I launch the AMI my application (a Flask application) would have already been downloaded and configured by Puppet as well as my apache configuration file at /etc/apache2/sites-available/xxxx.conf . I make use of the Puppet template to configure the apache configuration file and as such it is a Ruby template (xxxx.conf.erb) ,the apache configuration template file looks like this :

    <VirtualHost *:<%= @port -%>>
        ServerName <%= @servername %>

        ServerAdmin admin@example.com   WSGIScriptAlias / /var/www/Porfolio/xxxxx.wsgi

        <Directory /var/www/Porfolio/>    Order allow,deny    Allow from all    </Directory>    Alias /static /var/www/Porfolio/static  <Directory /var/www/Porfolio/static/>     Order allow,deny    Allow from all    </Directory>     

        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined 
</VirtualHost>

I have set the variable servername = $::hostname (using facter) and port = 80 When i launch the AMI and I access the public IP address of the server of the ec2 instance, it takes me to the default ubuntu webpage instead of my web Flask application. I will have to ssh into my server and change the apache configuration file at /etc/apache2/sites-available/xxxx.conf to become :

<VirtualHost *:<%= @port -%>>
    ServerName 52.91.143.90

    ServerAdmin admin@example.com
    WSGIScriptAlias / /var/www/Porfolio/culturely.wsgi

    <Directory /var/www/Porfolio/>
      Order allow,deny
      Allow from all
    </Directory>
    Alias /static /var/www/Porfolio/static
    <Directory /var/www/Porfolio/static/>
      Order allow,deny
      Allow from all
    </Directory>     

    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

This means i have to manually type in the public IP address of the ec2instance in order to get my Flask web page to display when the public Ip address is accessed on a browser. This ofcourse defeats the level of automation I am trying to achieve. The public IP address only becomes available after I launch the AMI, is there a way i can re-configure my apache configuration file to make it automatically goto my web application instead of the default ubuntu web page ? without having me to ssh into the server and manually change it after it is launched

Hamza
  • 2,180
  • 3
  • 14
  • 18

2 Answers2

1

There is a fact ec2_public_ipv4, use this to set the address

Vorsprung
  • 32,923
  • 5
  • 39
  • 63
  • hi @Vorsprung i tired that by assigning the variable **servername** = $::ec2_public_ipv4 . After launching the AMI though, the public Ip address of the ec2 instance on AWS is different from the one assigned by puppet in the apache configuration file and as such still shows the default ubuntu webpage when the public IP address is accessed. – Hamza Jan 28 '16 at 13:45
  • Maybe I am not understanding how you are doing this. Are you using puppet at "packer time" to make the AMI? In this case the fact will of course be wrong. The fact needs to be used to make the template after the instance comes up. – Vorsprung Jan 28 '16 at 14:24
  • Hi @Vorsprung yes I am using puppet at "packer time" to make the AMI. How do i ensure the fact is used after the instance comes up ? – Hamza Jan 28 '16 at 20:27
0

I have found a solution to my problem. I was creating a new apache configuration file with puppet at packer time, a point at which the public IP address that will be assigned to ec2 instance is unavailable. So instead of creating a new apache configuration file, I modified the default one at /etc/apache2/sites-available/000-default.conf . I left the variable servername = $::fqdn . Now whenever I launch the AMI and visit the assigned public IP address of the ec2-instance, it navigates to my Flask application and not the default ubuntu web page anymore.

Hamza
  • 2,180
  • 3
  • 14
  • 18