Vagrant Puppet Provisioning failure due declarative structure - webserver

As the title describes I am having an issue provisioning a box successfully. I am trying to install a development box (Apache, PHP and XDebug)
Everything works fine except for the point where I have to include the XDebug functionality, since it is not supplied in the original REPO I am installing it through the Example42/puppet-yum REPO manager.
In this part there is a mistake, since when I try to build the box from scratch I get the the error that package php-perl-xdebug is not available. This is because the repo's are not yet initialized. I have tried several ways to make sure that it would update the repo's before doing any other action. Referencing the classes by -> but this would yield in a looped block. Going through Google did not yield any practical results that would make sure that some commands are ran before others.
I believe it is possible to do this wit the "Required" command, but I could't find a way to use it.
Side note: We're mostly using example42 modules for our building.
Thanks in advance:
The following is the default.pp manifest for the application service.
default.pp
Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ] }
class system-setup {
service { "iptables":
ensure => stopped,
}
}
class php-setup{
php::module { "pdo": }
php::module { "gd": }
# php::module { "fpm": }
php::module { "mysql": }
php::module { "soap": }
# php::module { "zts": }
# php::module { "pecl-apc": }
php::module { "pecl-memcache": }
php::module { "xml": }
php::module{ "pecl-xdebug": }
}
class apache-vhost {
apache::vhost { 'trunk.project.dev':
docroot => '/var/www/html/',
port => '80',
}
}
class { 'yum':
extrarepo => [ 'epel' ],
}
class { 'apache':
source => [ "puppet:///modules/apache/httpd.conf-project" , "puppet:///modules/apache/httpd.conf" ],
}
class { 'php' :
source => ["/vagrant/files/php.ini", "puppet:///modules/php/php.ini"],
}
include php-setup
include apache-vhost

You can put this somewhere:
Class['yum'] -> Package <||>
This is using a resource collector to make sure Class yum is done before any package is installed.

Related

Jenkins dynamic choice parameter to read a ansible host file in github

I have an ansible host file that is stored in GitHub and was wondering if there is a way to list out all the host in jenkins with choice parameters? Right now every time I update the host file in Github I would have to manually go into each Jenkins job and update the choice parameter manually. Thanks!
I'm assuming your host file has content something similar to below.
[client-app]
client-app-preprod-01.aws-xxxx
client-app-preprod-02.aws
client-app-preprod-03.aws
client-app-preprod-04.aws
[server-app]
server-app-preprod-01.aws
server-app-preprod-02.aws
server-app-preprod-03.aws
server-app-preprod-04.aws
Option 01
You can do something like the one below. Here you can first checkout the repo and then ask for the user input. I have implemented the function getHostList() to parse the host file to filter the host entries.
pipeline {
agent any
stages {
stage('Build') {
steps {
git 'https://github.com/jglick/simple-maven-project-with-tests.git'
script {
def selectedHost = input message: 'Please select the host', ok: 'Next',
parameters: [
choice(name: 'PRODUCT', choices: getHostList("client-app","ansible/host/location"), description: 'Please select the host')]
echo "Host:::: $selectedHost"
}
}
}
}
}
def getHostList(def appName, def filePath) {
def hosts = []
def content = readFile(file: filePath)
def startCollect = false
for(def line : content.split('\n')) {
if(line.contains("["+ appName +"]")){ // This is a starting point of host entries
startCollect = true
continue
} else if(startCollect) {
if(!line.allWhitespace && !line.contains('[')){
hosts.add(line.trim())
} else {
break
}
}
}
return hosts
}
Option 2
If you want to do this without checking out the source and with Job Parameters. You can do something like the one below using the Active Choice Parameter plugin. If your repository is private, you need to figure out a way to generate an access token to access the Raw GitHub link.
properties([
parameters([
[$class: 'ChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select the Host',
name: 'Host',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return [\'Could not get Host\']'
],
script: [
classpath: [],
sandbox: false,
script:
'''
def appName = "client-app"
def content = new URL ("https://raw.githubusercontent.com/xxx/sample/main/testdir/hosts").getText()
def hosts = []
def startCollect = false
for(def line : content.split("\\n")) {
if(line.contains("["+ appName +"]")){ // This is a starting point of host entries
startCollect = true
continue
} else if(startCollect) {
if(!line.allWhitespace && !line.contains("[")){
hosts.add(line.trim())
} else {
break
}
}
}
return hosts
'''
]
]
]
])
])
pipeline {
agent any
stages {
stage('Build') {
steps {
script {
echo "Host:::: ${params.Host}"
}
}
}
}
}
Update
When you are calling a private repo, you need to send a Basic Auth header with the access token. So use the following groovy script instead.
def accessToken = "ACCESS_TOKEN".bytes.encodeBase64().toString()
def get = new URL("https://raw.githubusercontent.com/xxxx/something/hosts").openConnection();
get.setRequestProperty("authorization", "Basic " + accessToken)
def content = get.getInputStream().getText()

Unable to publish on Jitpack: Execution failed for task ':install'

Well, I'm since about 4 hours trying to publish my project on JitPack, but I always get the same error:
Execution failed for task ':install'.
I searched a lot, but nothing was found about it.
Log: https://jitpack.io/com/github/NathanPB/DogoAPI/master-63f1267b6d-1/build.log
Repo: https://github.com/NathanPB/DogoAPI
What am I doing wrong?
Looking on the log, luX told me that the jar task was skipped:
:jar SKIPPED
Then, I modified my build.gradle from
jar {
manifest {
attributes 'Main-Class': 'cf.dogo.api.DogoAPIKt'
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
To
jar {
enabled = true
manifest {
attributes 'Main-Class': 'cf.dogo.api.DogoAPIKt'
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
Adding enabled = true for jar task. Everything worked very well after that.

how to setstorageclass for the latest gcloud storage

we use to follow instruction here! to set the bucket lifecycle policy, but with the latest gcloud components update, we are getting an error like this:
Failure: Unsupported tag SetStorageClass.
search the gcs storage lifecycle doc did not fund any update.
The command we used is gsutil lifecycle set <json file> gs://<bucket name>/
and gsutil version: 4.25
{
"lifecycle":{
"rule":[
{
"action":{
"type":"SetStorageClass",
"storageClass":"NEARLINE"
},
"condition":{
"age":30,
"matchesStorageClass":[
"REGIONAL",
"STANDARD",
"DURABLE_REDUCED_AVAILABILITY"
]
}
}
]
}
}
EDIT 2
This was fixed in this GitHub commit, which has been included in the newest version (v4.26) of gsutil.
EDIT
It looks like you actually uncovered a bug that occurs when using the XML API. I've opened a GitHub issue an will work on fixing this ASAP:
https://github.com/GoogleCloudPlatform/gsutil/issues/427
Thanks for the report!
Looking at the code in the Boto library, you're probably trying to specify SetStorageClass a JSON key:
{
...
"SetStorageClass": ...
...
}
rather than making it the value of the action's type attribute. Here's an example using your (fixed) sample from a question comment:
{
"lifecycle": {
"rule": [
{
"action": {
"type": "SetStorageClass",
"storageClass": "NEARLINE"
},
"condition": {
"age":30,
"matchesStorageClass": ["STANDARD", "DURABLE_REDUCED_AVAILABILITY"]
}
}
]
}
}

VSCode - adding c# assembly reference

Getting the following error:
The name 'File' does not exist in the current context[dnxcore50]
Tried to build it in-case it was to do with VSCode alone. It threw me same error.
I have installed the dependency using the following:
dnu install System.IO
Gave me the following message
c:\Users\user1\Dropbox\dev\csharp\vscode\ads\WeightedGraphs>dnu
install System.IO
GET https://www.nuget.org/api/v2/FindPackagesById()?Id='System.IO'.
OK https://www.nuget.org/api/v2/FindPackagesById()?Id='System.IO' 679ms
System.IO.4.0.10-beta-22816 was added to project.json.
Restoring packages for c:\Users\user1\Dropbox\dev\csharp\vscode\ads\WeightedGraphs\project.json
Writing lock file c:\Users\user1\Dropbox\dev\csharp\vscode\ads\WeightedGraphs\project.lock.json
Restore complete, 302ms elapsed
project.json
{
"version": "1.0.0-*",
"dependencies": {
"System.IO": "4.0.10-beta-22816"
},
"commands": {
"run": "run"
},
"frameworks": {
"dnx451": {},
"dnxcore50": {
"dependencies": {
"System.Collections": "4.0.10-beta-22816",
"System.Linq": "4.0.0-beta-22816",
"System.Console": "4.0.0-beta-22816"
}
}
}
}
In.cs
using System.IO;
public class In{
public In(string s){
var filename = s;
var path = "";
if(File.Exists(path)){
//Code TO Be Added
}
}
}
You also need to add "System.IO.FileSystem" to your dependencies.

Overwrite if if it exists or create if it does not

I am trying to rewrite a file using puppet with the following function.
If the file exists I still want the file to be rewrite from the source. Will this be achieved with the following method?
define setup_sysctl_conf( $dependence=File[$dummy_dependence_file] )
{
file { $name:
path => '/etc/sysctl.conf',
ensure => present,
mode => 0777,
source => '/vagrant/files/sysctl.conf',
require => $dependence,
}
}
The file: /etc/sysctl.conf will already be present on your host (created by the initscripts package).
I would recommend to modify existing files with puppet using augeas instead of replacing them.
Example (changes net.ipv4.ip_forward to 1):
class sysctl_augeas_example {
augeas{"Set net.ipv4.ip_forward to 1":
context => "/files",
changes => [
"set etc/sysctl.conf/net.ipv4.ip_forward 1",
]
}
}
include sysctl_augeas_example
Save this example as test.pp and run it with puppet apply test.pp