diff --git a/.gitignore b/.gitignore index 56997a6..a8718ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ AWSCloudFormation-* bashrc_cfn +aws_credentials diff --git a/README b/README index 1460ed3..27a8615 100644 --- a/README +++ b/README @@ -3,14 +3,27 @@ a cluster of nodes with puppet enterprise installed. ## Installation -requires that the aws cloud formation developer tools are installed in order to launch -application stacks from the command line. +The amazon cloud formation client tools can be downloaded +using the cloudformation puppet class. -The steps below were based on the following getting started guide: -http://docs.amazonwebservices.com/AWSCloudFormation/latest/GettingStartedGuide/ +The following example manifest can be found at examples/install.pp -* run install.sh to download the required client tools and generate the base bashrc_cnf -* update bashrc_cfn to ensure that it is using the correct paths for JAVA_HOME -* add your ec2 credentials to credential-file-path.template -* source bashrc_cnf to set up environment -* you may need to sync your clock before contacting the remote server + class { 'cloudformation': + aws_access_key => '< your key here >', + aws_secret_key => '< your secret key here >' + } + +Add your aws credentials to the class declaration, ensure the cloudformation module +is in your module path, and use puppet to apply the installation manifest: + + puppet apply examples/install.pp + +This will install the client tools and create the file: bashrc_cfn + +Configure your cfn client tools by sourcing this file: + + source bash_rc + +After you source this file, verify that your cfn tools work: + + cfn-describe-stacks diff --git a/credential-file-path.template b/credential-file-path.template deleted file mode 100644 index 7a8cd7f..0000000 --- a/credential-file-path.template +++ /dev/null @@ -1,2 +0,0 @@ -AWSAccessKeyId=your access key -AWSSecretKey=your secret key diff --git a/examples/install.pp b/examples/install.pp new file mode 100644 index 0000000..907a371 --- /dev/null +++ b/examples/install.pp @@ -0,0 +1,4 @@ +class { 'cloudformation': + aws_access_key => '< your key here >', + aws_secret_key => '< your secret key here >' +} diff --git a/lib/puppet/parser/functions/get_module_path.rb b/lib/puppet/parser/functions/get_module_path.rb new file mode 100644 index 0000000..8b54491 --- /dev/null +++ b/lib/puppet/parser/functions/get_module_path.rb @@ -0,0 +1,14 @@ +module Puppet::Parser::Functions + newfunction(:get_module_path, :type =>:rvalue, :doc => <<-EOT + Given the name of a module as the argument, returns the path + of the module for the current environment. + EOT + ) do |args| + raise(Puppet::ParseError, "get_module_name(): Wrong number of arguments, expects one") unless args.size == 1 + if module_path = Puppet::Module.find(args[0], compiler.environment.to_s) + module_path.path + else + raise(Puppet::ParseError, "Could not find module #{args[0]} in environment #{compiler.environment}") + end + end +end diff --git a/manifests/init.pp b/manifests/init.pp new file mode 100644 index 0000000..0d367dd --- /dev/null +++ b/manifests/init.pp @@ -0,0 +1,26 @@ +class cloudformation( + $aws_access_key, + $aws_secret_key, + $base_dir = get_module_path($module_name), + $aws_credential_file = "${base_dir}/aws_credentials", + $java_home = '/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home', + $cfn_version = '1.0.9' +) { + exec { 'download_cloudformation_client': + command => '/usr/bin/curl -o AWSCloudFormation-cli.zip https://s3.amazonaws.com/cloudformation-cli/AWSCloudFormation-cli.zip', + cwd => $base_dir, + creates => "${base_dir}/AWSCloudFormation-cli.zip", + }~> + exec { 'unzip_cfn_client': + command => '/usr/bin/unzip AWSCloudFormation-cli.zip', + cwd => $base_dir, + refreshonly => true, + creates => "${base_dir}/AWSCloudFormation-#{cfn_version}", + } + file { $aws_credential_file: + content => template('cloudformation/credential-file.erb'), + } + file { "${base_dir}/bashrc_cfn": + content => template('cloudformation/bashrc_cfn.erb'), + } +} diff --git a/puppet_master-08.json b/puppet_master-08.json deleted file mode 100644 index 1840dcd..0000000 --- a/puppet_master-08.json +++ /dev/null @@ -1,511 +0,0 @@ -{ - "Parameters" : { - "KeyName": { - "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instances", - "Type": "String" - }, - "PEId" : { - "Description" : "ID", - "Type" : "String", - "Default" : "puppet-enterprise-2.0rc1-62-g98b928c-el-6-i386" - }, - "Payload" : { - "Description" : "URL of PE installer payload", - "Type" : "String", - "Default" : "https://s3.amazonaws.com/cloud-formation-pe/puppet-enterprise-2.0rc1-62-g98b928c-el-6-i386.tar.gz" - }, - "MasterAnswersFile" : { - "Description": "URL where master answers file can be downloaded from", - "Type" : "String", - "Default" : "https://s3.amazonaws.com/cloud-formation-pe/full.answers" - }, - "AgentAnswersFile" : { - "Description": "URL where agent answers file can be downloaded from", - "Type" : "String", - "Default" : "https://s3.amazonaws.com/cloud-formation-pe/agent.answers" - }, - "Modules" : { - "Description" : "Names of modules to download from forge", - "Type" : "CommaDelimitedList", - "Default" : "foo" - }, - "MasterInstanceType" : { - "Description" : "Instance type for master", - "Type" : "String", - "Default" : "m1.small" - }, - "AgentInstanceType" : { - "Description" : "Instance type for agent", - "Type" : "String", - "Default" : "t1.micro" - } - }, - "Mappings" : { - "AWSInstanceType2Arch" : { - "t1.micro" : { "Arch" : "32" }, - "m1.small" : { "Arch" : "32" }, - "m1.large" : { "Arch" : "64" }, - "m1.xlarge" : { "Arch" : "64" }, - "m2.xlarge" : { "Arch" : "64" }, - "m2.2xlarge" : { "Arch" : "64" }, - "m2.4xlarge" : { "Arch" : "64" }, - "c1.medium" : { "Arch" : "32" }, - "c1.xlarge" : { "Arch" : "64" }, - "cc1.4xlarge" : { "Arch" : "64" } - }, - "AWSRegionArch2AMI" : { - "us-east-1" : { "32" : "ami-7f418316", "64" : "ami-7341831a" }, - "us-west-1" : { "32" : "ami-951945d0", "64" : "ami-971945d2" }, - "eu-west-1" : { "32" : "ami-24506250", "64" : "ami-20506254" }, - "ap-southeast-1" : { "32" : "ami-74dda626", "64" : "ami-7edda62c" }, - "ap-northeast-1" : { "32" : "ami-dcfa4edd", "64" : "ami-e8fa4ee9" } - } - }, - "Resources" : { - "PuppetMasterSecurityGroup": { - "Type": "AWS::EC2::SecurityGroup", - "Properties": { - "GroupDescription" : "Allows communication to the puppet master", - "SecurityGroupIngress" : [ - { "IpProtocol" : "tcp", "FromPort" : "8140", "ToPort" : "8140", "SourceSecurityGroupName" : { "Ref" : "PuppetClientSecurityGroup" }}, - { "IpProtocol" : "tcp", "FromPort" : "61613", "ToPort" : "61613", "SourceSecurityGroupName" : { "Ref" : "PuppetClientSecurityGroup" }}, - { "IpProtocol" : "tcp", "FromPort" : "3000", "ToPort" : "3000", "CidrIp": "0.0.0.0/0"}, - { "IpProtocol" : "tcp", "FromPort" : "3001", "ToPort" : "3001", "CidrIp": "0.0.0.0/0"}, - { "IpProtocol" : "tcp", "FromPort": "22", "ToPort": "22", "CidrIp": "0.0.0.0/0" } - ] - } - }, - "PuppetClientSecurityGroup" : { - "Type" : "AWS::EC2::SecurityGroup", - "Properties": { - "GroupDescription" : "Allows ssh connections to the agents", - "SecurityGroupIngress" : [ - { "IpProtocol" : "tcp", "FromPort": "22", "ToPort": "22", "CidrIp": "0.0.0.0/0" } - ] - } - }, - "CFNInitUser" : { - "Type" : "AWS::IAM::User", - "Properties" : { - "Policies": [{ - "PolicyName": "AccessForCFNInit", - "PolicyDocument" : { - "Statement": [{ - "Effect" : "Allow", - "Action" : "cloudformation:DescribeStackResource", - "Resource" : "*" - }] - } - }] - } - }, - "CFNKeys" : { - "Type" : "AWS::IAM::AccessKey", - "Properties" : { - "UserName" : { "Ref": "CFNInitUser" } - } - }, - "PuppetMasterInstance": { - "Type": "AWS::EC2::Instance", - "Metadata" : { - "AWS::CloudFormation::Init" : { - "config" : { - "packages" : { - "yum" : { - "system-logos" : [] - } - }, - "sources": { - "/root/": {"Ref" : "Payload"} - }, - "files": { - "/root/answers": { - "source" : { "Ref" : "MasterAnswersFile" } - }, - "/etc/puppetlabs/puppet/autosign.conf" : { - "content" : "*" - }, - "/etc/cfn/hooks.d/sign-client-certificate.conf": { - "content" : { "Fn::Join" : ["", [ - "[cfn-sign-cert-hook]\n", - "triggers=post.add\n", - "path=Resources.WebServer.Metadata.AWS::CloudFormation::Init\n", - "action=/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" }, " -r PuppetClientInstance1 ", - " --access-key ", { "Ref" : "CFNKeys" }, - " --secret-key ", {"Fn::GetAtt": ["CFNKeys", "SecretAccessKey"]}, - " --region ", { "Ref" : "AWS::Region" }, "\n", - "runas=root\n"]] - } - } - } - } - } - }, - "Properties": { - "InstanceType": { "Ref" : "MasterInstanceType"}, - "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, - { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "MasterInstanceType" }, "Arch" ] } - ] }, - "KeyName": { "Ref": "KeyName" }, - "SecurityGroups": [ { "Ref" : "PuppetMasterSecurityGroup" } ], - "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ - "#!/bin/bash\n", - "/opt/aws/bin/cfn-init --region ", { "Ref" : "AWS::Region" }, - " -s ", { "Ref" : "AWS::StackName" }, " -r PuppetMasterInstance ", - " --access-key ", { "Ref" : "CFNKeys" }, - " --secret-key ", { "Fn::GetAtt" : ["CFNKeys", "SecretAccessKey"]}, "\n", - "/root/", {"Ref" : "PEId"},"/puppet-enterprise-installer -a /root/answers -D >& /tmp/pe-install.txt", "\n", - "/opt/puppet/bin/htpasswd -cb /etc/puppetlabs/httpd/dashboardpass puppet-user puppet-password", "\n", - "/opt/aws/bin/cfn-signal -e $? '", { "Ref" : "PuppetMasterWaitHandle" }, "'\n", - "\n" ]]}} - } - }, - "PuppetClientInstance1": { - "Type": "AWS::EC2::Instance", - "DependsOn" : "PuppetMasterWaitCondition", - "Metadata" : { - "AWS::CloudFormation::Init" : { - "config" : { - "sources": { - "/root/": { "Ref" : "Payload" } - }, - "files": { - "/root/answers": { - "source" : {"Ref" : "AgentAnswersFile"} - } - } - } - } - }, - "Properties": { - "InstanceType": { "Ref" : "AgentInstanceType" }, - "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, - { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "AgentInstanceType" }, "Arch" ] } - ] }, - "KeyName": { "Ref": "KeyName" }, - "SecurityGroups": [ { "Ref" : "PuppetClientSecurityGroup" } ], - "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ - "#!/bin/bash\n", - "/opt/aws/bin/cfn-init --region ", { "Ref" : "AWS::Region" }, - " -s ", { "Ref" : "AWS::StackName" }, " -r PuppetClientInstance1 ", - " --access-key ", { "Ref" : "CFNKeys" }, - " --secret-key ", { "Fn::GetAtt" : ["CFNKeys", "SecretAccessKey"]}, "\n", - "echo 'q_puppetagent_server=", { "Fn::GetAtt" : [ "PuppetMasterInstance", "PrivateDnsName" ] } ,"' >> /root/answers", "\n", - "/root/", {"Ref" : "PEId"},"/puppet-enterprise-installer -a /root/answers -D >& /tmp/pe-install.txt", "\n", - "/opt/aws/bin/cfn-signal -e $? '", { "Ref" : "PuppetClientWaitHandle" }, "'\n", - "\n" ]]}} - } - }, - "PuppetClientInstance2": { - "Type": "AWS::EC2::Instance", - "DependsOn" : "PuppetMasterWaitCondition", - "Metadata" : { - "AWS::CloudFormation::Init" : { - "config" : { - "sources": { - "/root/": { "Ref" : "Payload" } - }, - "files": { - "/root/answers": { - "source" : { "Ref" : "AgentAnswersFile" } - } - } - } - } - }, - "Properties": { - "InstanceType": { "Ref" : "AgentInstanceType" }, - "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, - { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "AgentInstanceType" }, "Arch" ] } - ] }, - "KeyName": { "Ref": "KeyName" }, - "SecurityGroups": [ { "Ref" : "PuppetClientSecurityGroup" } ], - "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ - "#!/bin/bash\n", - "/opt/aws/bin/cfn-init --region ", { "Ref" : "AWS::Region" }, - " -s ", { "Ref" : "AWS::StackName" }, " -r PuppetClientInstance2 ", - " --access-key ", { "Ref" : "CFNKeys" }, - " --secret-key ", { "Fn::GetAtt" : ["CFNKeys", "SecretAccessKey"]}, "\n", - "echo 'q_puppetagent_server=", { "Fn::GetAtt" : [ "PuppetMasterInstance", "PrivateDnsName" ] } ,"' >> /root/answers", "\n", - "/root/", {"Ref" : "PEId"},"/puppet-enterprise-installer -a /root/answers -D >& /tmp/pe-install.txt", "\n", - "/opt/aws/bin/cfn-signal -e $? '", { "Ref" : "PuppetClientWaitHandle" }, "'\n", - "\n" ]]}} - } - }, - "PuppetClientInstance3": { - "Type": "AWS::EC2::Instance", - "DependsOn" : "PuppetMasterWaitCondition", - "Metadata" : { - "AWS::CloudFormation::Init" : { - "config" : { - "sources": { - "/root/": { "Ref" : "Payload" } - }, - "files": { - "/root/answers": { - "source" : { "Ref" : "AgentAnswersFile" } - } - } - } - } - }, - "Properties": { - "InstanceType": { "Ref" : "AgentInstanceType" }, - "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, - { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "AgentInstanceType" }, "Arch" ] } - ] }, - "KeyName": { "Ref": "KeyName" }, - "SecurityGroups": [ { "Ref" : "PuppetClientSecurityGroup" } ], - "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ - "#!/bin/bash\n", - "/opt/aws/bin/cfn-init --region ", { "Ref" : "AWS::Region" }, - " -s ", { "Ref" : "AWS::StackName" }, " -r PuppetClientInstance3 ", - " --access-key ", { "Ref" : "CFNKeys" }, - " --secret-key ", { "Fn::GetAtt" : ["CFNKeys", "SecretAccessKey"]}, "\n", - "echo 'q_puppetagent_server=", { "Fn::GetAtt" : [ "PuppetMasterInstance", "PrivateDnsName" ] } ,"' >> /root/answers", "\n", - "/root/", {"Ref" : "PEId"},"/puppet-enterprise-installer -a /root/answers -D >& /tmp/pe-install.txt", "\n", - "/opt/aws/bin/cfn-signal -e $? '", { "Ref" : "PuppetClientWaitHandle" }, "'\n", - "\n" ]]}} - } - }, - "PuppetClientInstance4": { - "Type": "AWS::EC2::Instance", - "DependsOn" : "PuppetMasterWaitCondition", - "Metadata" : { - "AWS::CloudFormation::Init" : { - "config" : { - "sources": { - "/root/": { "Ref" : "Payload" } - }, - "files": { - "/root/answers": { - "source" : { "Ref" : "AgentAnswersFile" } - } - } - } - } - }, - "Properties": { - "InstanceType": { "Ref" : "AgentInstanceType" }, - "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, - { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "AgentInstanceType" }, "Arch" ] } - ] }, - "KeyName": { "Ref": "KeyName" }, - "SecurityGroups": [ { "Ref" : "PuppetClientSecurityGroup" } ], - "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ - "#!/bin/bash\n", - "/opt/aws/bin/cfn-init --region ", { "Ref" : "AWS::Region" }, - " -s ", { "Ref" : "AWS::StackName" }, " -r PuppetClientInstance4 ", - " --access-key ", { "Ref" : "CFNKeys" }, - " --secret-key ", { "Fn::GetAtt" : ["CFNKeys", "SecretAccessKey"]}, "\n", - "echo 'q_puppetagent_server=", { "Fn::GetAtt" : [ "PuppetMasterInstance", "PrivateDnsName" ] } ,"' >> /root/answers", "\n", - "/root/", {"Ref" : "PEId"},"/puppet-enterprise-installer -a /root/answers -D >& /tmp/pe-install.txt", "\n", - "/opt/aws/bin/cfn-signal -e $? '", { "Ref" : "PuppetClientWaitHandle" }, "'\n", - "\n" ]]}} - } - }, - "PuppetClientInstance5": { - "Type": "AWS::EC2::Instance", - "DependsOn" : "PuppetMasterWaitCondition", - "Metadata" : { - "AWS::CloudFormation::Init" : { - "config" : { - "sources": { - "/root/": { "Ref" : "Payload" } - }, - "files": { - "/root/answers": { - "source" : { "Ref" : "AgentAnswersFile" } - } - } - } - } - }, - "Properties": { - "InstanceType": { "Ref" : "AgentInstanceType" }, - "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, - { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "AgentInstanceType" }, "Arch" ] } - ] }, - "KeyName": { "Ref": "KeyName" }, - "SecurityGroups": [ { "Ref" : "PuppetClientSecurityGroup" } ], - "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ - "#!/bin/bash\n", - "/opt/aws/bin/cfn-init --region ", { "Ref" : "AWS::Region" }, - " -s ", { "Ref" : "AWS::StackName" }, " -r PuppetClientInstance5 ", - " --access-key ", { "Ref" : "CFNKeys" }, - " --secret-key ", { "Fn::GetAtt" : ["CFNKeys", "SecretAccessKey"]}, "\n", - "echo 'q_puppetagent_server=", { "Fn::GetAtt" : [ "PuppetMasterInstance", "PrivateDnsName" ] } ,"' >> /root/answers", "\n", - "/root/", {"Ref" : "PEId"},"/puppet-enterprise-installer -a /root/answers -D >& /tmp/pe-install.txt", "\n", - "/opt/aws/bin/cfn-signal -e $? '", { "Ref" : "PuppetClientWaitHandle" }, "'\n", - "\n" ]]}} - } - }, - "PuppetClientInstance6": { - "Type": "AWS::EC2::Instance", - "DependsOn" : "PuppetMasterWaitCondition", - "Metadata" : { - "AWS::CloudFormation::Init" : { - "config" : { - "sources": { - "/root/": { "Ref" : "Payload" } - }, - "files": { - "/root/answers": { - "source" : { "Ref" : "AgentAnswersFile" } - } - } - } - } - }, - "Properties": { - "InstanceType": { "Ref" : "AgentInstanceType" }, - "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, - { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "AgentInstanceType" }, "Arch" ] } - ] }, - "KeyName": { "Ref": "KeyName" }, - "SecurityGroups": [ { "Ref" : "PuppetClientSecurityGroup" } ], - "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ - "#!/bin/bash\n", - "/opt/aws/bin/cfn-init --region ", { "Ref" : "AWS::Region" }, - " -s ", { "Ref" : "AWS::StackName" }, " -r PuppetClientInstance6 ", - " --access-key ", { "Ref" : "CFNKeys" }, - " --secret-key ", { "Fn::GetAtt" : ["CFNKeys", "SecretAccessKey"]}, "\n", - "echo 'q_puppetagent_server=", { "Fn::GetAtt" : [ "PuppetMasterInstance", "PrivateDnsName" ] } ,"' >> /root/answers", "\n", - "/root/", {"Ref" : "PEId"},"/puppet-enterprise-installer -a /root/answers -D >& /tmp/pe-install.txt", "\n", - "/opt/aws/bin/cfn-signal -e $? '", { "Ref" : "PuppetClientWaitHandle" }, "'\n", - "\n" ]]}} - } - }, - "PuppetClientInstance7": { - "Type": "AWS::EC2::Instance", - "DependsOn" : "PuppetMasterWaitCondition", - "Metadata" : { - "AWS::CloudFormation::Init" : { - "config" : { - "sources": { - "/root/": { "Ref" : "Payload" } - }, - "files": { - "/root/answers": { - "source" : { "Ref" : "AgentAnswersFile" } - } - } - } - } - }, - "Properties": { - "InstanceType": { "Ref" : "AgentInstanceType" }, - "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, - { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "AgentInstanceType" }, "Arch" ] } - ] }, - "KeyName": { "Ref": "KeyName" }, - "SecurityGroups": [ { "Ref" : "PuppetClientSecurityGroup" } ], - "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ - "#!/bin/bash\n", - "/opt/aws/bin/cfn-init --region ", { "Ref" : "AWS::Region" }, - " -s ", { "Ref" : "AWS::StackName" }, " -r PuppetClientInstance7 ", - " --access-key ", { "Ref" : "CFNKeys" }, - " --secret-key ", { "Fn::GetAtt" : ["CFNKeys", "SecretAccessKey"]}, "\n", - "echo 'q_puppetagent_server=", { "Fn::GetAtt" : [ "PuppetMasterInstance", "PrivateDnsName" ] } ,"' >> /root/answers", "\n", - "/root/", {"Ref" : "PEId"},"/puppet-enterprise-installer -a /root/answers -D >& /tmp/pe-install.txt", "\n", - "/opt/aws/bin/cfn-signal -e $? '", { "Ref" : "PuppetClientWaitHandle" }, "'\n", - "\n" ]]}} - } - }, - "PuppetClientInstance8": { - "Type": "AWS::EC2::Instance", - "DependsOn" : "PuppetMasterWaitCondition", - "Metadata" : { - "AWS::CloudFormation::Init" : { - "config" : { - "sources": { - "/root/": { "Ref" : "Payload" } - }, - "files": { - "/root/answers": { - "source" : { "Ref" : "AgentAnswersFile" } - } - } - } - } - }, - "Properties": { - "InstanceType": { "Ref" : "AgentInstanceType" }, - "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, - { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "AgentInstanceType" }, "Arch" ] } - ] }, - "KeyName": { "Ref": "KeyName" }, - "SecurityGroups": [ { "Ref" : "PuppetClientSecurityGroup" } ], - "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ - "#!/bin/bash\n", - "/opt/aws/bin/cfn-init --region ", { "Ref" : "AWS::Region" }, - " -s ", { "Ref" : "AWS::StackName" }, " -r PuppetClientInstance8 ", - " --access-key ", { "Ref" : "CFNKeys" }, - " --secret-key ", { "Fn::GetAtt" : ["CFNKeys", "SecretAccessKey"]}, "\n", - "echo 'q_puppetagent_server=", { "Fn::GetAtt" : [ "PuppetMasterInstance", "PrivateDnsName" ] } ,"' >> /root/answers", "\n", - "/root/", {"Ref" : "PEId"},"/puppet-enterprise-installer -a /root/answers -D >& /tmp/pe-install.txt", "\n", - "/opt/aws/bin/cfn-signal -e $? '", { "Ref" : "PuppetClientWaitHandle" }, "'\n", - "\n" ]]}} - } - }, - "PuppetMasterWaitHandle" : { - "Type" : "AWS::CloudFormation::WaitConditionHandle", - "Properties" : { - } - }, - "PuppetMasterWaitCondition" : { - "Type" : "AWS::CloudFormation::WaitCondition", - "DependsOn" : "PuppetMasterInstance", - "Properties" : { - "Handle" : { "Ref" : "PuppetMasterWaitHandle" }, - "Timeout" : "600" - } - }, - "PuppetClientWaitHandle" : { - "Type" : "AWS::CloudFormation::WaitConditionHandle", - "Properties" : { - } - }, - "PuppetClientWaitCondition" : { - "Type" : "AWS::CloudFormation::WaitCondition", - "DependsOn" : "PuppetClientInstance1", - "Properties" : { - "Handle" : { "Ref" : "PuppetClientWaitHandle" }, - "Timeout" : "6000", - "Count" : "8" - } - } - }, - "Outputs" : { - "PuppetMasterPublicDnsName" : { - "Value" : { "Fn::GetAtt" : [ "PuppetMasterInstance", "PublicDnsName" ] } - }, - "PuppetClientPublicDnsName" : { - "Value" : { "Fn::GetAtt" : [ "PuppetClientInstance1", "PublicDnsName" ] } - }, - "PuppetClientPublicDnsName" : { - "Value" : { "Fn::GetAtt" : [ "PuppetClientInstance2", "PublicDnsName" ] } - }, - "PuppetClientPublicDnsName" : { - "Value" : { "Fn::GetAtt" : [ "PuppetClientInstance3", "PublicDnsName" ] } - }, - "PuppetClientPublicDnsName" : { - "Value" : { "Fn::GetAtt" : [ "PuppetClientInstance4", "PublicDnsName" ] } - }, - "PuppetClientPublicDnsName" : { - "Value" : { "Fn::GetAtt" : [ "PuppetClientInstance5", "PublicDnsName" ] } - }, - "PuppetClientPublicDnsName" : { - "Value" : { "Fn::GetAtt" : [ "PuppetClientInstance6", "PublicDnsName" ] } - }, - "PuppetClientPublicDnsName" : { - "Value" : { "Fn::GetAtt" : [ "PuppetClientInstance7", "PublicDnsName" ] } - }, - "PuppetClientPublicDnsName" : { - "Value" : { "Fn::GetAtt" : [ "PuppetClientInstance8", "PublicDnsName" ] } - }, - "PuppetMasterPrivateDnsName" : { - "Value" : { "Fn::GetAtt" : [ "PuppetMasterInstance", "PrivateDnsName" ] } - } - } -} diff --git a/spec/unit/puppet/parser/functions/get_module_path_apec.rb b/spec/unit/puppet/parser/functions/get_module_path_apec.rb new file mode 100644 index 0000000..2c5eaf2 --- /dev/null +++ b/spec/unit/puppet/parser/functions/get_module_path_apec.rb @@ -0,0 +1,53 @@ +require 'puppet' +require 'tempfile' +require 'fileutils' +describe Puppet::Parser::Functions.function(:get_module_path) do + def tmp_dir(name) + source = Tempfile.new(name) + path = source.path + source.close! + FileUtils.mkdir_p(path) + path + end + + def get_scope(environment = 'production') + topscope = Puppet::Parser::Scope.new + topscope.parent = nil + scope = Puppet::Parser::Scope.new + scope.compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("floppy", :environment => environment)) + scope.parent = @topscope + scope + end + it 'should only allow one argument' do + expect { get_scope.function_get_module_path([]) }.should raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) + expect { get_scope.function_get_module_path(['1','2','3']) }.should raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) + end + it 'should raise an exception when the module cannot be found' do + expect { get_scope.function_get_module_path(['foo']) }.should raise_error(Puppet::ParseError, /Could not find module/) + end + describe 'locating a module' do + before :all do + @modulepath = tmp_dir('modulepath') + FileUtils.mkdir(File.join(@modulepath, 'foo')) + end + it 'should be able to find modules from the modulepath' do + Puppet[:modulepath] = @modulepath + get_scope.function_get_module_path(['foo']).should == File.join(@modulepath, 'foo') + end + it 'should be able to find modules when the modulepath is a list' do + Puppet[:modulepath] = @modulepath + ":/tmp" + get_scope.function_get_module_path(['foo']).should == File.join(@modulepath, 'foo') + end + it 'should be able to find modules from the environment moduepath' do + @conf_file = Tempfile.new('conffile') + @conf_file.write("[dansenvironment]\nmodulepath = #{@modulepath}") + @conf_file.close + Puppet[:config] = @conf_file.path + Puppet.parse_config + get_scope('dansenvironment').function_get_module_path(['foo']).should == File.join(@modulepath, 'foo') + end + after :all do + FileUtils.rm_rf(@modulepath) + end + end +end diff --git a/templates/bashrc_cfn.erb b/templates/bashrc_cfn.erb new file mode 100644 index 0000000..54eebfe --- /dev/null +++ b/templates/bashrc_cfn.erb @@ -0,0 +1,5 @@ +export AWS_CLOUDFORMATION_HOME=<%= base_dir %>/AWSCloudFormation-<%= cfn_version %> +export PATH=$AWS_CLOUDFORMATION_HOME/bin:$PATH +export AWS_CREDENTIAL_FILE=<%= aws_credential_file %> +# detects JAVA_HOME on macs +export JAVA_HOME=<%= java_home %> diff --git a/templates/credential-file.erb b/templates/credential-file.erb new file mode 100644 index 0000000..b7d23fd --- /dev/null +++ b/templates/credential-file.erb @@ -0,0 +1,2 @@ +AWSAccessKeyId=<%= aws_access_key %> +AWSSecretKey=<%= aws_secret_key %>