SlideShare a Scribd company logo
Infrastructre as Code 

- Ansible -
2017/11/29
IT
Email: sasaki.ryo@marusa.tech
• Infrastructure as a Code
•
•
•
•
• Ansible
• Ansible
• Ansible
•
• Ansible
•Infrastructure as Code
•Ansible
•Ansible
• Infrastructure as a Code
•
•
•
•
• Ansible
• Ansible
• Ansible
•
• Ansible
Infrastructure as Code
• =
•
• DNS 

VM
•
•
Infrastructure as Code
• 

• 30 30
•
• 1
• 

Infrastructure as Code
•
•
•
•
•
• Infrastructure as a Code
•
•
•
•
• Ansible
• Ansible
• Ansible
•
• Ansible
Puppet
Chef
Ansible


“ ”
Chef / Puppet / Ansible
Linux
Windows
NW
◆ ◆
httpd
httpd
• Infrastructure as a Code
•
•
•
•
• Ansible
• Ansible
• Ansible
•
• Ansible
•
• Chef
•
•
• Ruby
• Puppet
• Chef
• Chef
• Puppet
• Ansible
•
•
•
• Infrastructure as a Code
•
•
•
•
• Ansible
• Ansible
• Ansible
•
• Ansible
•
• /
• NIC
• sshd
•
•
• sudo
•
• iptables / firewalld
100
• Infrastructure as a Code
•
•
•
•
• Ansible
• Ansible
• Ansible
•
• Ansible
•
•
•
•
• VM 



VM => =>
• Infrastructure as a Code
•
•
•
•
• Ansible
• Ansible
• Ansible
•
• Ansible
Ansible
• Chef Puppet
•
• Chef / Puppet
•
• Chef / Puppet Ruby
•
•
•
• Infrastructure as a Code
•
•
•
•
• Ansible
• Ansible
• Ansible
•
• Ansible
Ansible
Ansbile
Playbook Inventory
Linux
RHEL 7.x
Linux
CentOS 6.x
Windows
Windows 2012R2
Linux
Ubuntu 17.x
NW
Cisco IOS 15.x
PUSH
SSH
Ansible
• Ansible
SSH sudo
• sshd_config sudoers
• sudo
•
• ssh
• sudo su –
Ansible
Ansbile
Playbook Inventory
Linux
RHEL 7.x
Linux
CentOS 6.x
Windows
Windows 2012R2
Linux
Ubuntu 17.x
NW
Cisco IOS 15.x
PUSH
or
sudo
or
su
Ansible
• Playbook Inventory 2
• Inventory Playbook
Inventory
※
Playbook
※
Ansible
• Playbook Inventory 2
• Inventory Playbook
- hosts: all
become: yes
tasks:
- name: check install httpd
yum: name=httpd state=latest
- name: check running and enabled httpd
service: name=httpd state=running
enabled=yes
192.168.0.1
192.168.0.2
192.168.0.3
192.168.0.4
192.168.0.5
192.168.0.6
Playbook
./deploy-httpd.yml
Inventory
./hosts
Ansible
• Playbook / 

OS Ansible( )
• CentOS6 7
•
• Ubuntu yum install
• CentOS6 systemd
• OS
• Infrastructure as a Code
•
•
•
•
• Ansible
• Ansible
• Ansible
•
• Ansible
Ansible 



※ 



Ansible
•
• CentOS 7.x or RHEL 7.x
$> yum install epel-release
$> yum install ansible
Ansible
$> pwd
/home/user01/workspace/ansible
$> cat ./hosts
192.168.0.1
192.168.0.2
192.168.0.3
Ansible
$> ansible -i ./hosts all -m ping –k
192.168.0.1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
…
Ansible
-i inventory
-m
-k
$> ansible -i ./hosts all -m
ping –k
192.168.0.1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
…
Ansible
OK
$> ansible -i ./hosts all -m
ping
192.168.0.1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
…
Ansible
※ ~/.ssh
OK
$> ansible -i ./hosts all -m
ping 

-i ~/.ssh/id_rsa
192.168.0.1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
Ansible
$> ansible -i ./hosts all -m shell -a “ipconfig”
“shell”
-a
192.168.0.[1-3] ipconfig


or
Ansible
• Playbook YAML
• YAML Wikipedia
• https://ja.wikipedia.org/wiki/YAML
•
• hosts
• become
• tasks
• handlers
Ansible
• hosts
• Inventory
• ”all”
• become
•
• sudo su
• tasks
•
•
• handlers
• tasks
• Ansible
$> cat ./deploy-httpd.yml
- hosts: all
- become: yes
tasks:
- name: check install httpd
yum: name=httpd state=latest
- name: check running and enabled
httpd
service: name=httpd state=running
enabled=yes
$> cat ./deploy-httpd.yml
- hosts: all
- become: yes
tasks:
- name: check install httpd
yum: name=httpd state=latest
- name: check running and enabled
httpd
service: name=httpd state=running
enabled=yes
sudo
tasks
$> cat ./deploy-httpd.yml
- hosts: all
- become: yes
tasks:
- name: check install httpd
yum: name=httpd state=latest
- name: check running and enabled
httpd
service: name=httpd state=running
enabled=yes
yum
httpd
Ansible
$> ansible-playbook -i ./hosts all ./deploy-
httpd.yml
ansible-playbook Inventory Playbook
192.168.0.[1-3]
httpd
on
Ansible
$> ansible-playbook -i ./hosts all ./deploy-
httpd.yml —check
--check dry-run 

Playbook
※
--check
• Infrastructure as a Code
•
•
•
•
• Ansible
• Ansible
• Ansible
•
• Ansible
- file:
path=/var/log/hogehoge
state=directory
mode=0755
file
- copy:
src=/home/ansible/httpd.conf
dest=/etc/httpd/httpd.conf
owner=user01
group=group1
mode=0755
copy
- user:
name=user01
uid=1000
group=group1
home=/home/user01
shell=/bin/bash
user
- yum:
name=httpd
yum
- service:
name=httpd
state=started
enabled=yes
service
- lineinfile:
dest=~/.ssh/authorized_keys
line=[ ]
lineinfile
- replace:
dest=/etc/ssh/sshd_config
regexp=“PermitRootLogin yes”
replace=“PermitRootLogin no”
replace
• Ansible
• Linux Windows Cisco IOS, FortiGate, AWS, Azure
• 1400
• http://docs.ansible.com/ansible/latest/list_of_all_modules.html
•
•
Infrastructre as Ccodeの実現 - Ansibleの基本 -
slave-1
172.16.0.1
slave-2
172.16.0.2
ansible-master
172.16.0.100
• Infrastructure as a Code
•
•
•
•
• Ansible
• Ansible
• Ansible
•
• Ansible
Ansible
Ansbile
Linux
RHEL 7.x
Linux
Ubuntu 17.xPUSH
sshd_conf.2
sshd_conf.1
$> cat ./hosts
[slave1]
172.16.0.1
[slave2]
172.16.0.2
[slave1:vars]
target_sshd_conf=./sshd_config_for_slave1
[slave2:vars]
target_sshd_conf=./sshd_config_for_slave2
- name: deploy sshd_conf
copy:
src={{ target_sshd_conf }}
dest=/etc/ssh/sshd_config
owner=root
group=root
mode=0640
Ansible
:1 :2
Ansible
Ansible
:1 :2
Ansible
:1
Ansible
$> ansible-playbook -i ./hosts all ./deploy-
httpd.yml
--become-method=su --become-ask-pass
root
SSH root sudo
--become-method: root
--become-ask-pass: root
Ansible
$> ansible-playbook -i ./hosts all ./deploy-
httpd.yml
--become-method=sudo --become-ask-pass
sudo
--become-method 

sudo
Infrastructre as Ccodeの実現 - Ansibleの基本 -
• Playbook
•
• Playbook
•
• Playbook ansible-playbook
•
• Playbook 

/
Infrastructre as Ccodeの実現 - Ansibleの基本 -

More Related Content

PDF
Ansible 101 - Presentation at Ansible STL Meetup
PPTX
Introduction to ansible
PDF
Ansible
ODP
ansible why ?
ODP
Using Ansible at Scale to Manage a Public Cloud
PDF
High Performance Drupal
PDF
Highly available Drupal on a Raspberry Pi cluster
PPTX
Ansible Tutorial For Beginners | What Is Ansible And How It Works? | Ansible ...
Ansible 101 - Presentation at Ansible STL Meetup
Introduction to ansible
Ansible
ansible why ?
Using Ansible at Scale to Manage a Public Cloud
High Performance Drupal
Highly available Drupal on a Raspberry Pi cluster
Ansible Tutorial For Beginners | What Is Ansible And How It Works? | Ansible ...

What's hot (20)

PDF
Ansible Intro - June 2015 / Ansible Barcelona User Group
PDF
Ansible + Drupal: A Fortuitous DevOps Match
PDF
Ansible is the simplest way to automate. SymfonyCafe, 2015
PPTX
Baking in the cloud with packer and puppet
PDF
Network Automation (NetDevOps) with Ansible
PPTX
Network automation (NetDevOps) with Ansible
PDF
Network Automation: Ansible 101
PDF
CommandBox at CFCamp 2014
PDF
Put a Button on It: Removing Barriers to Going Fast
PDF
HTTPS and Ansible
PDF
DevOps for Humans - Ansible for Drupal Deployment Victory!
PDF
DevOps with Ansible
PDF
Make your Ansible playbooks maintainable, flexible, and scalable
PPTX
Configuration primer
PDF
Using Ansible for Deploying to Cloud Environments
PDF
Ansible for Drupal infrastructure and deployments
PDF
Managing sensitive data with Ansible vault
PPTX
Ansible in CI
PDF
Managing Your Cisco Datacenter Network with Ansible
PDF
The future of node
Ansible Intro - June 2015 / Ansible Barcelona User Group
Ansible + Drupal: A Fortuitous DevOps Match
Ansible is the simplest way to automate. SymfonyCafe, 2015
Baking in the cloud with packer and puppet
Network Automation (NetDevOps) with Ansible
Network automation (NetDevOps) with Ansible
Network Automation: Ansible 101
CommandBox at CFCamp 2014
Put a Button on It: Removing Barriers to Going Fast
HTTPS and Ansible
DevOps for Humans - Ansible for Drupal Deployment Victory!
DevOps with Ansible
Make your Ansible playbooks maintainable, flexible, and scalable
Configuration primer
Using Ansible for Deploying to Cloud Environments
Ansible for Drupal infrastructure and deployments
Managing sensitive data with Ansible vault
Ansible in CI
Managing Your Cisco Datacenter Network with Ansible
The future of node
Ad

Similar to Infrastructre as Ccodeの実現 - Ansibleの基本 - (20)

PDF
IT Automation with Ansible
PDF
2010 Smith Scripting101
PDF
EC2 AMI Factory with Chef, Berkshelf, and Packer
PPTX
Herd your chickens: Ansible for DB2 configuration management
PDF
Ansible + WordPress - WordCamp Toronto 2016
PDF
Linux 系統管理與安全:系統防駭與資訊安全
PDF
A tour of Ansible
PDF
Jenkins and ansible reference
PPTX
Ansible as configuration management tool for devops
PDF
Shell scripting
PPTX
Ansible, voyage au centre de l'automatisation
PDF
Ansible : what's ansible & use case by REX
PDF
Integrating icinga2 and the HashiCorp suite
PDF
Automating complex infrastructures with Puppet
PDF
JIP Pipeline System Introduction
PDF
Automation with ansible
PPTX
MySQL At Yelp
PDF
History Of Redis Replication And Future Prospects: Zhao Zhao
KEY
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
PPT
Logstash
IT Automation with Ansible
2010 Smith Scripting101
EC2 AMI Factory with Chef, Berkshelf, and Packer
Herd your chickens: Ansible for DB2 configuration management
Ansible + WordPress - WordCamp Toronto 2016
Linux 系統管理與安全:系統防駭與資訊安全
A tour of Ansible
Jenkins and ansible reference
Ansible as configuration management tool for devops
Shell scripting
Ansible, voyage au centre de l'automatisation
Ansible : what's ansible & use case by REX
Integrating icinga2 and the HashiCorp suite
Automating complex infrastructures with Puppet
JIP Pipeline System Introduction
Automation with ansible
MySQL At Yelp
History Of Redis Replication And Future Prospects: Zhao Zhao
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
Logstash
Ad

More from Ryo Sasaki (14)

PDF
AWS_Loft_IoTスタートアップ向け_ビットキーの右肩上がりなIoTトラフィックを捌く基盤の考慮と工夫
PDF
ヘルプセンターを支える技術_生成AI時代の自己解決エンジニアリング_ どこに何の問題があるだろう? HWからSWまでの全領域を横断した最速解...
PDF
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
PDF
ゼロトラスト三銃士〜Okta x Jamf x Netskopeネタ10連発〜
PDF
ビットキーのIoT基盤におけるAWS IoT Rule Action 活用
PDF
[Cloud Native Days Tokyo 2022] たまにはオンプレもいいぞ? GKE と Armadillo IoT で実現する ハイフ...
PDF
[Okta x Jamf合同新年会] Okta Workflowsによるノーコード業務改善 〜Jamf APIを使ってMac端末情報を自動収集してみよう〜
PDF
CNDT2022_たまにはオンプレもいいぞ? GKE と Armadillo IoT で実現する ハイブリッドクラウド
PDF
Datadog Agent on CloudRunによるGCPトレービリティ向上
PDF
DynamoDBの初心者に伝えたい初めて触るときの勘所
PDF
OpenStackを導入・1年運用したチームの変化
PDF
AWSの真髄
PDF
Linux Kernel Parameter Tuning
PDF
きっと今すぐ使えるハッシュの基礎知識
AWS_Loft_IoTスタートアップ向け_ビットキーの右肩上がりなIoTトラフィックを捌く基盤の考慮と工夫
ヘルプセンターを支える技術_生成AI時代の自己解決エンジニアリング_ どこに何の問題があるだろう? HWからSWまでの全領域を横断した最速解...
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
ゼロトラスト三銃士〜Okta x Jamf x Netskopeネタ10連発〜
ビットキーのIoT基盤におけるAWS IoT Rule Action 活用
[Cloud Native Days Tokyo 2022] たまにはオンプレもいいぞ? GKE と Armadillo IoT で実現する ハイフ...
[Okta x Jamf合同新年会] Okta Workflowsによるノーコード業務改善 〜Jamf APIを使ってMac端末情報を自動収集してみよう〜
CNDT2022_たまにはオンプレもいいぞ? GKE と Armadillo IoT で実現する ハイブリッドクラウド
Datadog Agent on CloudRunによるGCPトレービリティ向上
DynamoDBの初心者に伝えたい初めて触るときの勘所
OpenStackを導入・1年運用したチームの変化
AWSの真髄
Linux Kernel Parameter Tuning
きっと今すぐ使えるハッシュの基礎知識

Recently uploaded (20)

PDF
Soil Improvement Techniques Note - Rabbi
PPTX
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PDF
737-MAX_SRG.pdf student reference guides
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PPTX
Feature types and data preprocessing steps
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PDF
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
PPTX
Module 8- Technological and Communication Skills.pptx
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PPTX
introduction to high performance computing
PPTX
Fundamentals of Mechanical Engineering.pptx
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PPTX
Safety Seminar civil to be ensured for safe working.
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
Soil Improvement Techniques Note - Rabbi
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
737-MAX_SRG.pdf student reference guides
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Feature types and data preprocessing steps
distributed database system" (DDBS) is often used to refer to both the distri...
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
Module 8- Technological and Communication Skills.pptx
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Categorization of Factors Affecting Classification Algorithms Selection
introduction to high performance computing
Fundamentals of Mechanical Engineering.pptx
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
Safety Seminar civil to be ensured for safe working.
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx

Infrastructre as Ccodeの実現 - Ansibleの基本 -