def test_support_only(self): expected_json = """ { "provisioners": [ { "type": "shell", "inline": [ "ls" ], "except": [ "azure-arm" ] } ] } """ p = provisioner.Shell(inline=["ls"]) p.__setattr__('except', ["azure-arm"]) t = Template() t.add_provisioner(p) to_json = t.to_json() assert to_json == json.dumps(json.loads(expected_json), sort_keys=True, indent=2, separators=(',', ': '))
def test_template_provisioners(self): expected_json = """ { "provisioners": [ { "source": "/src/path", "destination": "/dest/path", "direction": "upload", "type": "file" } ] } """ t = Template() t.add_provisioner( provisioner.File( source="/src/path", destination="/dest/path", direction=provisioner.File.Upload, )) to_json = t.to_json() assert to_json == json.dumps(json.loads(expected_json), sort_keys=True, indent=2, separators=(',', ': '))
def main(): """ main method. """ args = get_args() ami_config_file = args.var_file ami_config = get_config(ami_config_file) target_ami_name = generate_ami_name(ami_config['ami_name_prefix']) print(target_ami_name) template = Template() template.add_builder( builder.AmazonEbs( region=ami_config['region'], ami_name=target_ami_name, instance_type=ami_config['instance_type'], source_ami=ami_config['source_ami'], ssh_username=ami_config['ssh_username'], ami_description=ami_config['ami_description'], ami_virtualization_type=ami_config['ami_virtualization_type'], force_deregister=ami_config['force_deregister'], shutdown_behavior=ami_config['shutdown_behavior'], vpc_id=ami_config['vpc_id'], subnet_id=ami_config['subnet_id'], ssh_private_key_file=ami_config['ssh_private_key_file'], ssh_keypair_name=ami_config['ssh_keypair_name'], security_group_id=ami_config['security_group_id'], ) ) template.add_provisioner( provisioner.Ansible( playbook_file=ami_config['playbook_name'], command=ami_config['cmd_ansible'], user=ami_config['ssh_username'], ) ) PackerExecutable(machine_readable=False) p = PackerExecutable(executable_path=ami_config['cmd_packer']) (ret, out, err) = p.build( template.to_json(), ) print(out) print(err)
def create_template_from_config(self, tag_configs): """ Generate a packer template using configurations. :param tag_configs: dict containing the tag details :return: template of type packerlicious.Template """ template = Template() template.add_builder( builder.AmazonEbs( access_key="{{user `aws_access_key`}}", secret_key="{{user `aws_secret_key`}}", region=builder_config.get("region", "ap-southeast-2"), instance_type=builder_config.get("type", "t2.micro"), ssh_username="******", ami_name=self.ami_name, source_ami="ami-02769748522663066", tags=tag_configs)) template.add_provisioner(provisioner.Shell(script=script_path)) return template
def test_support_pause_before(self): expected_json = """ { "provisioners": [ { "type": "shell", "inline": [ "ls" ], "pause_before": "10s" } ] } """ p = provisioner.Shell(inline=["ls"], pause_before="10s") t = Template() t.add_provisioner(p) to_json = t.to_json() assert to_json == json.dumps(json.loads(expected_json), sort_keys=True, indent=2, separators=(',', ': '))
def test_property_attributes_renders(self): expected_json = """ { "provisioners": [ { "attributes": ["examples/linux.yml"], "profile": "a_profile", "type": "inspec" } ] } """ t = Template() p = provisioner.Inspec( attributes=["examples/linux.yml"], profile="a_profile" ) t.add_provisioner(p) to_json = t.to_json() assert to_json == json.dumps(json.loads(expected_json), sort_keys=True, indent=2, separators=(',', ': '))
str(int(current_box_version["version"].split('.')[2]) + 1) print("Building new catosplace/ubuntu1804-desktop-base box version " + next_box_version) version = UserVar("version", next_box_version) post_processors = [ post_processor.Vagrant( output = "builds/ubuntu1804-desktop-base.box", include = [ "info.json" ] ) ] t = Template() t.add_variable(desktop_user_variables) t.add_variable(version) t.add_builder(builders) t.add_provisioner(provisioners) # Move to new script user artifice #t.add_post_processor(post_processors) # View Packer Template print(t.to_json()) (ret, out, err) = PackerExecutable(machine_readable=False).validate(t.to_json()) print(out.decode('unicode_escape')) (ret, out, err) = PackerExecutable(machine_readable=False).build(t.to_json()) print(out.decode('unicode_escape'))