Ansible
Web
---
- name: apache web server
hosts: localhost
become: true
tasks:
- name: install apache
yum:
name: httpd
state: latest
- name: service
service:
name: httpd
state: started
- name: copy index file to html directory
copy:
src: index.html
dest: /var/www/html/index.html
index.html은 너무 길어 딱히 여기 적지 않음
SSH
- hosts: localhost
become: yes
tasks:
- name: Change SSH Port
lineinfile:
path: /etc/ssh/sshd_config
regexp: '^#?Port'
line: Port 2053
notify:
- restart sshd
handlers:
- name: restart sshd
service:
name: sshd
state: restart
저거 원래 hosts가 all이였는데, 이러면 안되고 localhost면 inventory 없이도 system manager에서 실행된다.
되는 이유는 automation이 쉘로 실행시키는데 저걸 쉘로 자기 자신에게 실행시키는것이라 되는것이다.
system manager automation
system manager automation에서 runbook으로 쓰기 위해 내가 한건 수동으로 ansible을 사용하는거였다.
s3에 ansible 파일을 올리고 이걸 automation에서 shell로 실행시켰다.
schemaVersion: '0.3'
description: ansible
mainSteps:
- name: RunCommandOnInstances
action: aws:runCommand
isEnd: true
inputs:
DocumentName: AWS-RunShellScript
Parameters:
commands:
- '#!/bin/bash'
- aws s3 cp s3://ansible-s3-bucket-eca/WEB/ /home/ec2-user/ --recursive
- aws s3 cp s3://ansible-s3-bucket-eca/SSH/ /home/ec2-user/ --recursive
- sudo yum install -y ansible
- ansible-playbook /home/ec2-user/web.yaml
- ansible-playbook /home/ec2-user/ssh.yaml
Targets:
- Key: tag:managed
Values:
- 'true'