Outils pour utilisateurs

Outils du site


tech:cloud_-_packer.io

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
tech:cloud_-_packer.io [2025/03/24 15:06] – créée - modification externe 127.0.0.1tech:cloud_-_packer.io [2025/11/26 21:57] (Version actuelle) Jean-Baptiste
Ligne 1: Ligne 1:
 +<!DOCTYPE markdown>
 +{{tag>Cloud}}
 +
 +# Cloud - packer.io
 +
 +Voir aussi :
 +* [Construction d'images via WebUI Cockpit avec osbuild-composer](https://www.redhat.com/sysadmin/linux-golden-homelab-rhel)
 +* https://forge.inrae.fr/gaev/packer
 +
 +
 +## Config
 +
 +### Prereq
 +
 +''~/.aws/config''
 +
 +~~~ini
 +[default]
 +region = us-east-2
 +output = table
 +~~~
 +
 +''~/.aws/credentials''
 +
 +~~~ini
 +[default]
 +aws_access_key_id = AKIAR5WS3MDOSPIUHRU7
 +aws_secret_access_key = 
 +~~~
 +
 +
 +### Exécution 
 +
 +''packer/example.json''
 +~~~javascript
 +{
 +  "variables": {
 +    "aws_access_key": "",
 +    "aws_secret_key": ""
 +  },
 +  "provisioners": [{
 +        "type": "ansible",
 +        "playbook_file": "../ansible/play-test.yml"
 +  }],
 +  "builders": [{
 +    "type": "amazon-ebs",
 +    "access_key": "{{user `aws_access_key`}}",
 +    "secret_key": "{{user `aws_secret_key`}}",
 +    "region": "us-east-2",
 +    "source_ami_filter": {
 +      "filters": {
 +        "virtualization-type": "hvm",
 +        "name": "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*",
 +        "root-device-type": "ebs"
 +      },
 +      "owners": ["099720109477"],
 +      "most_recent": true
 +    },
 +    "instance_type": "t2.micro",
 +    "ssh_username": "ubuntu",
 +    "ami_name": "packer-example {{timestamp}}"
 +  }]
 +}
 +~~~
 +
 +''ansible/play-test.yml''
 +
 +~~~yaml
 +---
 +
 +- name: test1
 +  hosts: all
 +  become: true
 +
 +  vars:
 +    ansible_python_interpreter: /usr/bin/python3
 +
 +  tasks:
 +    - name: plop
 +      shell: echo plop > /plop
 +~~~
 +
 +~~~bash
 +
 +packer validate example.json
 +packer build example.json
 +~~~
 +
 +## Debug
 +
 +~~~bash
 +packer build --debug example.json
 +~~~
 +
 +
 +### Pour pouvoir se connecter en SSH sur l'instance. 
 +
 +~~~javascript
 +    "ssh_keypair_name": "nom_de_la_clef_presente_sur_aws",
 +    "ssh_private_key_file": "/home/admin/.ssh/id_rsa",
 +~~~
 +
 +
 +|                          |                                                                                 |
 +|  ----------------------- | ------------------------------------------------------------------------------- |
 +|**ssh_keypair_name**      | Nom de la pair de clefs présente sur AWS. Utilisé par AWS pour créer l'instance |
 +|**ssh_private_key_file**  | Chemin de la clef privée pour que Packer puisse se connecter sur l'instance     |
 +
 +Normalement seul **ssh_username** est nécessaire à la création de l'AMI.
 +
 +
 +#### Pour se connecter en SSH sur une instance déjà crée
 +
 +~~~
 +$ ps -ef |grep ssh 
 +ssh -o ControlMaster=auto -o ControlPersist=30m -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o Port=39087 -o IdentityFile="/tmp/ansible-key896233465" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User="admin" -o ConnectTimeout=10 -o ControlPath=/home/admin/.ansible/cp/d7af4b579b 127.0.0.1 /bin/sh
 +~~~
 +
 +~~~bash
 +ssh admin@localhost -i /tmp/ansible-key896233465 -p 39087 /bin/bash
 +
 +ansible-playbook --extra-vars packer_build_name=amazon-ebs -e packer_builder_type=amazon-ebs -i /tmp/packer-provisioner-ansible966542596 /home/admin/workspace/Deploy_AMI_SCM_v2/905239-packebuild/ansible/playbook.yml -e ansible_ssh_private_key_file=/tmp/ansible-key896233465
 +~~~
 +
 +
  

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki