티스토리 뷰

linux

packer ami update

fendys 2024. 8. 2. 00:27
반응형

request - version check!!!

 

###### ami-update.json
#### use packer build ami-update.json
{
  "_comment": "AMI using Amazon Linux2",
  "variables": {
      "name": "ami-packer-build"
  },
  "builders": [
    {
        "type": "amazon-ebs",
        "region": "ap-northeast-2",
        "source_ami": "ami-id",
        "vpc_id": "vpc-id",
        "subnet_id": "subnet-id",
        "security_group_id": "sg-id",
        "instance_type": "t2.small",
        "ssh_interface": "private_ip",
        "ssh_username": "ec2-user",
        "ami_description": " AMI using Amazon Linux2",
        "ami_name": "ami-packer-build-{{timestamp}}",
        "tags":
        {
         "Name": "ami-packer-buil"
        },
      "ami_users": ["account id"]
    }
  ],
  "provisioners": [
    {
      "type": "ansible",
      "user": "ec2-user",
      "use_proxy": false,
      "keep_inventory_file": true,
      "playbook_file": "../playbook/ami-awslinux2-update.yml",
      "extra_arguments": [
        "--extra-vars",
        "\"ansible_user=ec2-user ansible_become_method=sudo ansible_become_user=root ansible_host={{ build `Host` }} ansible_port=22 ansible_ssh_common_args='-o StrictHostKeyChecking=no'\""
      ],
      "ansible_env_vars": [
        "ANSIBLE_HOST_KEY_CHECKING=False"
        ]
    }
  ]
}
##### ami-awslinux2-update.yml
- name: Build Amazon Linux Base Image
  hosts: all
  roles:
    - set_cpsible
    
    
    
    
############     set_cpsible main.yml
---
# tasks file for set_cfendys
- name: useradd fendys
  become: yes
  shell: sudo useradd -u 1001 fendys

- name: fendys .ssh
  become: yes
  file:
    path: /home/fendys/.ssh
    state: directory
    owner: nike
    group: nike
    mode: '0700'
.
.
.
반응형

'linux' 카테고리의 다른 글

"grubby" 커널 변경 명령어  (0) 2024.07.10
sed 활용  (0) 2024.04.05
grub2 설정 변경  (0) 2023.11.30
linux 유저 생성 스크립트  (0) 2023.11.01
linux bash user 90 day no login chshell nologin!  (0) 2023.11.01