SlideShare a Scribd company logo
Ansible as a better
shell script
@24motz
2014-10-04 LT駆動開発08
http://www.ansible.com/home
Ansible as a better shell script
やっていること
NVDA日本語版の更新チェックを数える
(1) サーバーに ssh する
(2) /var/log/httpd を ls してファイル名確認
(3) grep キーワード ファイル名 | wc
[xx/Oct/2014:xx:xx:xx +0000] serverName
xxx.xxx.xxx.xxx - - "GET
/updateCheck/?language=ja_JP&autoCheck=True&x64=Tr
ue&installed=True&version=2014.3jp&versionType=nvdaj
p&osVersion=6.1.7601+Service+Pack+1 HTTP/1.0" 200 -
"- -> /updateCheck/index.py" "Python-urllib/1.17"
最初の自動化=sshの代用品
サーバーに ssh
/var/log/httpd を ls してファイル名を確認
$ ansible -i hosts --sudo -m shell --args "ls
/var/log/httpd" serverName
$ ansible -i hosts --sudo -m shell --args
"grep autoCheck=True
/var/log/httpd/access_log-$LATEST | wc"
serverName
playbookを作ってみた
$ ansible-playbook -i hosts playbook.yml
---
- hosts: serverName
sudo: yes
tasks:
- name: set latest
shell: ls /var/log/httpd | grep access_log | tail
-1 | sed -e s/access_log-//g
register: latest
shell #2
tasks:
- name: get nvda_all
shell: grep autoCheck=True
/var/log/httpd/access_log-{{ latest.stdout }}
| wc | awk '{ print $1 }'
register: nvda_all
set_fact
tasks:
- name: set fact
set_fact:
latest_: "{{ latest.stdout }}"
nvda_all_: "{{ nvda_all.stdout }}"
nvda_2014_3jp_: "{{ nvda_2014_3jp.stdout }}"
win62_: "{{ win62.stdout }}”
debug
tasks:
- name: show msg
debug: msg="{{ latest_ }} all:{{ nvda_all_ }}
2014.3jp:{{ nvda_2014_3jp_ }}
2014.2jp:{{ nvda_2014_2jp_ }}
2014.1jp:{{ nvda_2014_1jp_ }}
2013.3jp:{{ nvda_2013_3jp_ }}
win51:{{ win51_ }} win60:{{ win60_ }}
win61:{{ win61_ }} win62:{{ win62_ }}
win63:{{ win63_ }} x64:{{ x64_ }}
installed:{{ installed_ }}"
結果
PLAY [serverName]
************************************************************
GATHERING FACTS
***************************************************************
ok: [serverName]
TASK: [set latest]
************************************************************
changed: [serverName]
TASK: [set fact]
**************************************************************
ok: [serverName]
TASK: [show msg]
**************************************************************
ok: [serverName] => {
"msg": "20140928 all:3509 2014.3jp:2308 2014.2jp:730 2014.1jp:315 2013.3jp:152
win51:228 win60:124 win61:2163 win62:106 win63:888 x64:1909 installed:3387"
}
PLAY RECAP
********************************************************************
serverName : ok=16 changed=13 unreachable=0 failed=0
最近やってみたこと
$ ansible-playbook --extra-vars “hosts=abc"
- hosts: '{{ hosts }}'
- file: path=/data mode=0755 state=directory
- copy: src=hoge.tgz dest=/tmp/hoge.tgz
- service : name=httpd state=started
- shell: tar xfz /tmp/hoge.tgz
args:
- chdir: /data/hoge
これから試すこと
- fetch : リモートから管理マシンにファイルコピー
- unarchive: copy + shell tar xf
- local_action: ローカルで実行
- debug msg="{{ 'hello world'.upper()[:5] }}"

More Related Content

PDF
Containers: What are they, Really?
PDF
Object Storage with Gluster
PDF
Steam Learn: Composer
PPTX
Practical Glusto Example
PDF
Caching in Docker - the hardest thing in computer science
ODP
testing-nfs
PDF
Networking and Go: An Engineer's Journey (Strangeloop 2019)
PDF
GlusterFS As an Object Storage
Containers: What are they, Really?
Object Storage with Gluster
Steam Learn: Composer
Practical Glusto Example
Caching in Docker - the hardest thing in computer science
testing-nfs
Networking and Go: An Engineer's Journey (Strangeloop 2019)
GlusterFS As an Object Storage

What's hot (20)

PPTX
Inside Sqale's Backend at Sapporo Ruby Kaigi 2012
PDF
Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)
PPTX
How to configure multiple PostgreSQL-9
PDF
What Have Syscalls Done for you Lately?
PDF
Linux fundamental - Chap 09 pkg
PDF
Centralized Logging with syslog
PDF
Haproxy - zastosowania
PDF
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
PDF
OSS AWS 핸즈온 강의
PDF
nix-processmgmt: An experimental Nix-based process manager-agnostic framework
ODP
Introduction to Diskless Remote Boot in Linux
PDF
Up and Running with Glusto & Glusto-Tests in 5 Minutes (or less)
PDF
2 docker engine_hands_on
 
PDF
CoreOS + Kubernetes @ All Things Open 2015
PDF
CoreOS intro
PDF
실시간 서비스 플랫폼 개발 사례
PDF
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
PDF
Instant DevOps
PPTX
Git/Github/Bitbucket@TalkIt. Humber college.
Inside Sqale's Backend at Sapporo Ruby Kaigi 2012
Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)
How to configure multiple PostgreSQL-9
What Have Syscalls Done for you Lately?
Linux fundamental - Chap 09 pkg
Centralized Logging with syslog
Haproxy - zastosowania
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
OSS AWS 핸즈온 강의
nix-processmgmt: An experimental Nix-based process manager-agnostic framework
Introduction to Diskless Remote Boot in Linux
Up and Running with Glusto & Glusto-Tests in 5 Minutes (or less)
2 docker engine_hands_on
 
CoreOS + Kubernetes @ All Things Open 2015
CoreOS intro
실시간 서비스 플랫폼 개발 사례
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
Instant DevOps
Git/Github/Bitbucket@TalkIt. Humber college.
Ad

Similar to Ansible as a better shell script (20)

PDF
Melbourne Infracoders: Compliance as Code with InSpec
PDF
Linux sever building
PDF
Compliance as Code with InSpec - DevOps Melbourne 2017
PDF
Melbourne Chef Meetup: Automating Azure Compliance with InSpec
PDF
Automating Compliance with InSpec - Chef Singapore Meetup
PDF
Open Source Logging and Metrics Tools
PDF
Open Source Logging and Monitoring Tools
PPTX
How to manage Microsoft Azure with open source
PPTX
How to manage Azure with open source
PDF
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
PDF
How to turn any dynamic website into a static site | 24.01.2018 | Artem Danil...
PDF
Automating Compliance with InSpec - AWS North Sydney
PPTX
Securing Hadoop with OSSEC
PPTX
BuildStuff.LT 2018 InSpec Workshop
PPT
Professional deployment
DOC
Installation of Subversion on Ubuntu,...
PDF
Год в Github bugbounty, опыт участия
PDF
PDF
Automating AWS Compliance with InSpec
Melbourne Infracoders: Compliance as Code with InSpec
Linux sever building
Compliance as Code with InSpec - DevOps Melbourne 2017
Melbourne Chef Meetup: Automating Azure Compliance with InSpec
Automating Compliance with InSpec - Chef Singapore Meetup
Open Source Logging and Metrics Tools
Open Source Logging and Monitoring Tools
How to manage Microsoft Azure with open source
How to manage Azure with open source
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
How to turn any dynamic website into a static site | 24.01.2018 | Artem Danil...
Automating Compliance with InSpec - AWS North Sydney
Securing Hadoop with OSSEC
BuildStuff.LT 2018 InSpec Workshop
Professional deployment
Installation of Subversion on Ubuntu,...
Год в Github bugbounty, опыт участия
Automating AWS Compliance with InSpec
Ad

More from Takuya Nishimoto (20)

PPTX
221217 SwiftはPythonに似ている
PPTX
220427-pydata 統計・データ分析 特集
PPTX
220126 python-datalake-spark
PPTX
211120 他人の書いたPythonスクリプトをステップ実行で理解する
PPTX
211020 すごい広島 with OSH 2021.10
PPTX
210917 オープンセミナー@広島のこれまでとこれから
PPTX
210911 これから始める電子工作とMicroPython
PPTX
210728 mpy
PPTX
210630 python
PPTX
210526 Power Automate Desktop Python
PPTX
210428 python
PPTX
200918 hannari-python
PPTX
200429 python
PPTX
200325 flask
PPTX
200208 osh-nishimoto-v2
PPTX
191208 python-kansai-nishimoto
PPTX
191101 nvda-sightworld-nishimoto
PPTX
191114 iotlt-nishimoto
PPTX
191030 anna-with-python
PPTX
190916 nishimoto-nvda-pyconjp
221217 SwiftはPythonに似ている
220427-pydata 統計・データ分析 特集
220126 python-datalake-spark
211120 他人の書いたPythonスクリプトをステップ実行で理解する
211020 すごい広島 with OSH 2021.10
210917 オープンセミナー@広島のこれまでとこれから
210911 これから始める電子工作とMicroPython
210728 mpy
210630 python
210526 Power Automate Desktop Python
210428 python
200918 hannari-python
200429 python
200325 flask
200208 osh-nishimoto-v2
191208 python-kansai-nishimoto
191101 nvda-sightworld-nishimoto
191114 iotlt-nishimoto
191030 anna-with-python
190916 nishimoto-nvda-pyconjp

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
A Presentation on Artificial Intelligence
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Building Integrated photovoltaic BIPV_UPV.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Modernizing your data center with Dell and AMD
The Rise and Fall of 3GPP – Time for a Sabbatical?
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
MYSQL Presentation for SQL database connectivity
Big Data Technologies - Introduction.pptx
Understanding_Digital_Forensics_Presentation.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Per capita expenditure prediction using model stacking based on satellite ima...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Diabetes mellitus diagnosis method based random forest with bat algorithm
A Presentation on Artificial Intelligence
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Empathic Computing: Creating Shared Understanding
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
NewMind AI Weekly Chronicles - August'25 Week I
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...

Ansible as a better shell script

  • 1. Ansible as a better shell script @24motz 2014-10-04 LT駆動開発08 http://www.ansible.com/home
  • 3. やっていること NVDA日本語版の更新チェックを数える (1) サーバーに ssh する (2) /var/log/httpd を ls してファイル名確認 (3) grep キーワード ファイル名 | wc [xx/Oct/2014:xx:xx:xx +0000] serverName xxx.xxx.xxx.xxx - - "GET /updateCheck/?language=ja_JP&autoCheck=True&x64=Tr ue&installed=True&version=2014.3jp&versionType=nvdaj p&osVersion=6.1.7601+Service+Pack+1 HTTP/1.0" 200 - "- -> /updateCheck/index.py" "Python-urllib/1.17"
  • 4. 最初の自動化=sshの代用品 サーバーに ssh /var/log/httpd を ls してファイル名を確認 $ ansible -i hosts --sudo -m shell --args "ls /var/log/httpd" serverName $ ansible -i hosts --sudo -m shell --args "grep autoCheck=True /var/log/httpd/access_log-$LATEST | wc" serverName
  • 5. playbookを作ってみた $ ansible-playbook -i hosts playbook.yml --- - hosts: serverName sudo: yes tasks: - name: set latest shell: ls /var/log/httpd | grep access_log | tail -1 | sed -e s/access_log-//g register: latest
  • 6. shell #2 tasks: - name: get nvda_all shell: grep autoCheck=True /var/log/httpd/access_log-{{ latest.stdout }} | wc | awk '{ print $1 }' register: nvda_all
  • 7. set_fact tasks: - name: set fact set_fact: latest_: "{{ latest.stdout }}" nvda_all_: "{{ nvda_all.stdout }}" nvda_2014_3jp_: "{{ nvda_2014_3jp.stdout }}" win62_: "{{ win62.stdout }}”
  • 8. debug tasks: - name: show msg debug: msg="{{ latest_ }} all:{{ nvda_all_ }} 2014.3jp:{{ nvda_2014_3jp_ }} 2014.2jp:{{ nvda_2014_2jp_ }} 2014.1jp:{{ nvda_2014_1jp_ }} 2013.3jp:{{ nvda_2013_3jp_ }} win51:{{ win51_ }} win60:{{ win60_ }} win61:{{ win61_ }} win62:{{ win62_ }} win63:{{ win63_ }} x64:{{ x64_ }} installed:{{ installed_ }}"
  • 9. 結果 PLAY [serverName] ************************************************************ GATHERING FACTS *************************************************************** ok: [serverName] TASK: [set latest] ************************************************************ changed: [serverName] TASK: [set fact] ************************************************************** ok: [serverName] TASK: [show msg] ************************************************************** ok: [serverName] => { "msg": "20140928 all:3509 2014.3jp:2308 2014.2jp:730 2014.1jp:315 2013.3jp:152 win51:228 win60:124 win61:2163 win62:106 win63:888 x64:1909 installed:3387" } PLAY RECAP ******************************************************************** serverName : ok=16 changed=13 unreachable=0 failed=0
  • 10. 最近やってみたこと $ ansible-playbook --extra-vars “hosts=abc" - hosts: '{{ hosts }}' - file: path=/data mode=0755 state=directory - copy: src=hoge.tgz dest=/tmp/hoge.tgz - service : name=httpd state=started - shell: tar xfz /tmp/hoge.tgz args: - chdir: /data/hoge
  • 11. これから試すこと - fetch : リモートから管理マシンにファイルコピー - unarchive: copy + shell tar xf - local_action: ローカルで実行 - debug msg="{{ 'hello world'.upper()[:5] }}"