Up till version 4.9.1, the Puppet client does not support context path for remote Puppet Forge repositories. Therefore, we recommend using Artifactory with Puppet 4.9.2 and above.
If you need to use Puppet 4.9.1 and below you can use a workaround that uses NGINX or Apache to rewrite all requests from /v3/*
to /artifactory/api/puppet/<repo-name>/v3/*.
For example, if you have a repository called puppet-virtual
, and you are using Puppet 3.0, you would configure your proxy server to rewrite /v3/*
to /artifactory/api/puppet/puppet-virtual/v3/*
.
The following sections show sample configurations for NGINX and Apache for both the ports method and the sub-domain method to use a virtual repository named puppet-virtual
.
## server configuration server { listen 8001 ; location ^~/v3 { rewrite ^/v3/(.*) /artifactory/api/puppet/puppet-virtual/v3/$1 break; proxy_redirect off; proxy_pass http://localhost:8080/artifactory/; } }
## server configuration server { listen 443 ssl; listen 80 ; server_name ~(?<repo>.+)\.artifactory-cluster artifactory-cluster; if ($http_x_forwarded_proto = '') { set $http_x_forwarded_proto $scheme; } ## Application specific logs ## access_log /var/log/nginx/artifactory-cluster-access.log timing; ## error_log /var/log/nginx/artifactory-cluster-error.log; rewrite ^/$ /artifactory/webapp/ redirect; rewrite ^/artifactory/?(/webapp)?$ /artifactory/webapp/ redirect; rewrite ^/(v1|v2)/(.*) /artifactory/api/docker/$repo/$1/$2; rewrite ^/v3/(.*) /artifactory/api/puppet/$repo/v3/$1; chunked_transfer_encoding on; client_max_body_size 0; location /artifactory/ { proxy_read_timeout 900; proxy_pass_header Server; proxy_cookie_path ~*^/.* /; if ( $request_uri ~ ^/artifactory/(.*)$ ) { proxy_pass http://artifactory/artifactory/$1; } proxy_pass http://artifactory/artifactory/; proxy_next_upstream http_503 non_idempotent; proxy_set_header X-Artifactory-Override-Base-Url $http_x_forwarded_proto://$host:$server_port/artifactory; proxy_set_header X-Forwarded-Port $server_port; proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
########################################################### ## this configuration was generated by JFrog Artifactory ## ########################################################### ## add HA entries when ha is configured <Proxy balancer://artifactory> BalancerMember http://10.6.16.125:8080 route=14901314097097 ProxySet lbmethod=byrequests ProxySet stickysession=ROUTEID </Proxy> <VirtualHost *:80> ProxyPreserveHost On ServerName artifactory-cluster ServerAlias *.artifactory-cluster ServerAdmin server@admin ## Application specific logs ## ErrorLog ${APACHE_LOG_DIR}/artifactory-cluster-error.log ## CustomLog ${APACHE_LOG_DIR}/artifactory-cluster-access.log combined AllowEncodedSlashes On RewriteEngine on RewriteCond %{SERVER_PORT} (.*) RewriteRule (.*) - [E=my_server_port:%1] ## NOTE: The 'REQUEST_SCHEME' Header is supported only from apache version 2.4 and above RewriteCond %{REQUEST_SCHEME} (.*) RewriteRule (.*) - [E=my_scheme:%1] RewriteCond %{HTTP_HOST} (.*) RewriteRule (.*) - [E=my_custom_host:%1] RewriteRule ^/$ /artifactory/webapp/ [R,L] RewriteRule ^/artifactory(/)?$ /artifactory/webapp/ [R,L] RewriteRule ^/artifactory/webapp$ /artifactory/webapp/ [R,L] RequestHeader set Host %{my_custom_host}e RequestHeader set X-Forwarded-Port %{my_server_port}e ## NOTE: {my_scheme} requires a module which is supported only from apache version 2.4 and above RequestHeader set X-Forwarded-Proto %{my_scheme}e RequestHeader set X-Artifactory-Override-Base-Url %{my_scheme}e://artifactory-cluster:%{my_server_port}e/artifactory ProxyPassReverseCookiePath /artifactory /artifactory ProxyRequests off ProxyPreserveHost on ProxyPass /artifactory/ balancer://artifactory/artifactory/ ProxyPassReverse /artifactory/ balancer://artifactory/artifactory/ Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/artifactory/" env=BALANCER_ROUTE_CHANGED </VirtualHost> Listen 8001 <VirtualHost *:8001> ProxyPreserveHost On ServerName artifactory-cluster ServerAlias *.artifactory-cluster ServerAdmin server@admin ## Application specific logs ## ErrorLog ${APACHE_LOG_DIR}/artifactory-cluster-error.log ## CustomLog ${APACHE_LOG_DIR}/artifactory-cluster-access.log combined AllowEncodedSlashes On RewriteEngine on RewriteCond %{SERVER_PORT} (.*) RewriteRule (.*) - [E=my_server_port:%1] ## NOTE: The 'REQUEST_SCHEME' Header is supported only from apache version 2.4 and above RewriteCond %{REQUEST_SCHEME} (.*) RewriteRule (.*) - [E=my_scheme:%1] RewriteCond %{HTTP_HOST} (.*) RewriteRule (.*) - [E=my_custom_host:%1] RewriteRule "^/v3/(.*)$" "/artifactory/api/puppet/puppet-virtual/v3/$1" [P] RewriteRule ^/$ /artifactory/webapp/ [R,L] RewriteRule ^/artifactory(/)?$ /artifactory/webapp/ [R,L] RewriteRule ^/artifactory/webapp$ /artifactory/webapp/ [R,L] RequestHeader set Host %{my_custom_host}e RequestHeader set X-Forwarded-Port %{my_server_port}e ## NOTE: {my_scheme} requires a module which is supported only from apache version 2.4 and above RequestHeader set X-Forwarded-Proto %{my_scheme}e RequestHeader set X-Artifactory-Override-Base-Url %{my_scheme}e://artifactory-cluster:%{my_server_port}e/artifactory ProxyPassReverseCookiePath /artifactory /artifactory ProxyPass /artifactory/ balancer://artifactory/artifactory/ ProxyPassReverse /artifactory/ balancer://artifactory/artifactory/ Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/artifactory/" env=BALANCER_ROUTE_CHANGED </VirtualHost>
########################################################### ## this configuration was generated by JFrog Artifactory ## ########################################################### ## add HA entries when ha is configured <Proxy balancer://artifactory> BalancerMember http://10.6.16.125:8080 route=14901314097097 ProxySet lbmethod=byrequests ProxySet stickysession=ROUTEID </Proxy> <VirtualHost *:80> ProxyPreserveHost On ServerName artifactory-cluster ServerAlias *.artifactory-cluster ServerAdmin server@admin ## Application specific logs ## ErrorLog ${APACHE_LOG_DIR}/artifactory-cluster-error.log ## CustomLog ${APACHE_LOG_DIR}/artifactory-cluster-access.log combined AllowEncodedSlashes On RewriteEngine on RewriteCond %{SERVER_PORT} (.*) RewriteRule (.*) - [E=my_server_port:%1] ## NOTE: The 'REQUEST_SCHEME' Header is supported only from apache version 2.4 and above RewriteCond %{REQUEST_SCHEME} (.*) RewriteRule (.*) - [E=my_scheme:%1] RewriteCond %{HTTP_HOST} (.*) RewriteRule (.*) - [E=my_custom_host:%1] RewriteCond "%{REQUEST_URI}" "^/(v1|v2| )/" RewriteCond "%{HTTP_HOST}" "^(.*)\.artifactory-cluster$" RewriteRule "^/v3/(.*)$" "/artifactory/api/puppet/%1/v3/$1" [PT] RewriteRule "^/(v1|v2)/(.*)$" "/artifactory/api/docker/%1/$1/$2" [PT] RewriteRule ^/$ /artifactory/webapp/ [R,L] RewriteRule ^/artifactory(/)?$ /artifactory/webapp/ [R,L] RewriteRule ^/artifactory/webapp$ /artifactory/webapp/ [R,L] RequestHeader set Host %{my_custom_host}e RequestHeader set X-Forwarded-Port %{my_server_port}e ## NOTE: {my_scheme} requires a module which is supported only from apache version 2.4 and above RequestHeader set X-Forwarded-Proto %{my_scheme}e RequestHeader set X-Artifactory-Override-Base-Url %{my_scheme}e://artifactory-cluster:%{my_server_port}e/artifactory ProxyPassReverseCookiePath /artifactory /artifactory ProxyRequests off ProxyPreserveHost on ProxyPass /artifactory/ balancer://artifactory/artifactory/ ProxyPassReverse /artifactory/ balancer://artifactory/artifactory/ Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/artifactory/" env=BALANCER_ROUTE_CHANGED </VirtualHost>
Once you have your reverse proxy configured, you can install modules from Artifactory using the following commands:
Ports Method
puppet module install --module_repository http://localhost:8001 puppetlabs-apache
Subdomain Method
puppet module install --module_repository http://puppet-virtual.artifactory-cluster puppetlabs-apache