Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Ansible2.0と実用例

4 137 vues

Publié le

OSSコンソーシアムクラウド部会(2016/2/1)での発表資料

Publié dans : Technologie
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici

Ansible2.0と実用例

  1. 1. Ansible2.0と実⽤例 2016/2/1 OSSラボ株式会社 http://www.ossl.co.jp TWITTER: http://twitter.com/satoruf LINKEDIN: http://jp.linkedin.com/in/satorufunai/ja SLIDESHARE: http://www.slideshare.net/sfunai FACEBOOK: http://www.facebook.com/satoru.funai OSSコンソーシアムクラウド部会 第13回部会 2016/2/1 Copyright 2016(C) OSS Laboratories Inc. All Rights Reserved 1
  2. 2. Ansible2.0 新機能 l 内部構造を書き直した l その他いっぱいありすぎ l Windows対応 l 140以上の新規モジュールの追加 l openstack, docker, zabbix, vmwareなど l inventory, connection pluginも追加 l serf, consul, dockerなどからインベントリ情報を取ってこれる l などなど l 詳しくはこちら l https://raw.githubusercontent.com/ansible/ansible/stable-2.0/CHANGELOG.md 2016/2/1 Copyright 2016(C) OSS Laboratories Inc. All Rights Reserved 2
  3. 3. 使ってみた機能 l Block l Expect l taskレベルで変数の定義、上書き l Windowsモジュール 2016/2/1 Copyright 2016(C) OSS Laboratories Inc. All Rights Reserved 3
  4. 4. Tomcat 7 install on CentOS 6 #1 # Install tomcat name: Check Tomcat file: path=/opt/tomcat register: result_cat ignore_errors: True block: - name: add group "tomcat” group: name=tomcat - name: add user "tomcat” user: name=tomcat group=tomcat password=password - name: Download unarchive: src=http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.65/bin/apache- tomcat-7.0.65.tar.gz dest=/tmp copy=no - name: Move tomcat dir shell: mv /tmp/apache-tomcat-7.0.65 /opt/tomcat creates=/opt/tomcat - name: Replace config replace: dest=/opt/tomcat/conf/tomcat-users.xml regexp='{{ item.regexp }}' replace='{{ item.replace }}’ with_items: - regexp: ‘^<tomcat-users>’ replace: ’’ - regexp: ‘^</tomcat-users>’ replace: ‘’ 2016/2/1 Copyright 2016(C) OSS Laboratories Inc. All Rights Reserved 4
  5. 5. Tomcat 7 install on CentOS 6 #2 - name: Sed config lineinfile: dest=/opt/tomcat/conf/tomcat-users.xml line='{{ item }}’ with_items: - ‘<tomcat-users>’ - ‘ <role rolename="manager-script"/>’ - ‘ <user username="tomcat" password="password" roles="manager-script"/>’ - ‘</tomcat-users>’ - name: Change Owner file: path=/opt/tomcat owner=tomcat group=tomcat recurse=yes - name: Startup script copy copy: src=roles/tomcat/files/tomcat dest=/etc/init.d/ mode=755 - name: setenv copy copy: src=roles/tomcat/files/setenv.sh dest=/opt/tomcat/bin mode=755 when: result_cat|failed - name: Restart Tomcat service: name=tomcat state=restarted enabled=yes 2016/2/1 Copyright 2016(C) OSS Laboratories Inc. All Rights Reserved 5
  6. 6. Clean-up Tomcat #Stop Tomcat - hosts: all_hosts remote_user: osslabo become: yes vars: logs: - /opt/tomcat/logs/localhost* - /opt/tomcat/logs/catalina.*.log tasks: - name: Stop Tomcat service: name=tomcat pattern=/opt/tomcat state=stopped register: tomcat_stop ignore_errors: True - debug: var=tomcat_stop - name: Check PID command: /usr/bin/pgrep -f tomcat register: pid_result ignore_errors: True - debug: var=pid_result - name: Kill tomcat command: /usr/bin/pkill -KILL -f tomcat ignore_errors: True when: pid_result.rc == 0 - name: Remove logs shell: find {{logs | join(' ')}} -type f | xargs rm –f register: remove_result ignore_errors: True - debug: var=remove_result Clean-up Tomcat file: path={{ item }} state=absent では、wildcard(*)が使えない sudoではなく、becomeで他のユーザでも実⾏できる pgrepで結果がなければ(=プロセスが ない)、リターンコードは1になる 2016/2/1 Copyright 2016(C) OSS Laboratories Inc. All Rights Reserved 6
  7. 7. expectの例 l 前提条件:python >= 2.6, pexpect >= 3.3 ------- - hosts: localhost connection: local tasks: - name: expect expect: command: ssh root@192.168.1.1 echo HOST NAME IS `hostname` ; uname –a responses: (?i)password: "Password” register: get_hostname - debug: var=get_hostname.stdout_lines Expectブロックを抜けると、 sshもクローズする 2016/2/1 Copyright 2016(C) OSS Laboratories Inc. All Rights Reserved 7
  8. 8. expectの例実⾏結果 # ansible-playbook test.yml -l localhost PLAY *************************************************************************** TASK [setup] ******************************************************************* ok: [localhost] TASK [expect] ****************************************************************** changed: [localhost] TASK [debug var=get_hostname.stdout_lines] ************************************* ok: [localhost] => { "changed": false, "get_hostname.stdout_lines": [ "root@192.168.1.1's password: ", "HOST NAME IS example-server", "Linux example-server 2.6.32-573.3.1.el6.x86_64 #1 SMP Thu Aug 13 22:55:16 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux” ] } PLAY RECAP ********************************************************************* localhost : ok=3 changed=1 unreachable=0 failed=0 2016/2/1 Copyright 2016(C) OSS Laboratories Inc. All Rights Reserved 8
  9. 9. Registerで取得できる値の例 l モジュールによって異なる l “changed”: false | true:実⾏結果 l “cmd”: ”…”:実⾏モジュールと内容 l “rc”: 0 | 1 | …:リターンコード l “stdout”: ”…”:標準出⼒(改⾏⽂字がエスケープされる) l “stdout_lines”: […]:標準出⼒(splitされ複数⾏になる) l 条件分岐 l when: result | succeeded, failedではモジュール実⾏結果なので、 shell/commandなどのリターンコードで分岐させたい場合は l when: result.rc !=0 と使える 2016/2/1 Copyright 2016(C) OSS Laboratories Inc. All Rights Reserved 9
  10. 10. 動きが変わったモジュールの例 l Serviceモジュール - name: Check pacemaker service: name=pacemaker enabled=yes register: result_heartbeat ignore_errors: True l と書くと、パッケージがインストールされていない場合は、エラーとなったが、2.0からは、インストールされてい ない場合は、エラーにならない。 l パッケージがインストールされている場合は、今までどおりの起動、停⽌、再起動、⾃動起動させるかを⾏える。 l Packageモジュール(NEW) l serviceモジュールでインストールパッケージの確認が⾏えなくなったため、2.0以降はpackageモジュールにて⾏う 必要がある - name: Check pacemaker package: name=pacemaker register: result_heartbeat ignore_errors: True l Copyモジュールのオプション l remote_src=Trueを指定することにより、Ansible実⾏ホスト→リモートホストへファイルのコピーではなく、リモー トホストのファイルをリモートホストの別の場所にコピーを⾏える。 - name: Copy tomcat dir copy: src=/tmp/apache-tomcat-7.0.65/LICENSE dest=/opt/tomcat remote_src=True directory_mode=yes 2016/2/1 Copyright 2016(C) OSS Laboratories Inc. All Rights Reserved 10
  11. 11. Windowsサポート l win_acl (E):ファイル/ディレクトリのアクセス権限設定 l win_chocolatey (E):yum/apt-getのようなcliパッケージマ ネージャ(https://chocolatey.org)を利⽤するパッケージ操 作 l win_copy:ファイル/ディレクトリの転送 l win_dotnet_ngen (E):.NETネイティブ イメージ サービス を任意に実⾏ l win_environment (E):.NET環境変数の作成変更 l win_feature :Windows Roles/Featuresのインストール/ 削除 l win_file :ファイル/ディレクトリの作成/削除 l win_firewall_rule (E):ファイアウオールルールの操作 l win_get_url:URLからのファイルダウンロード l win_group:ローカルグループの操作 l win_iis_virtualdirectory (E):IIS仮想ディレクトリの操作 l win_iis_webapplication (E:IIS Webアプリケーションの操 作 l win_iis_webapppool (E):IIS Webアプリケーションプール の操作 l win_iis_webbinding (E) :IIS Webバインドの操作 l win_iis_website (E) :IIS Webサイトの操作 l win_lineinfile:ファイル内の⾏操作 l win_msi:Windows MSIのインストール/削除 l win_nssm (E):NSSM(http://nssm.cc/)を利⽤して任意 のアプリをサービスとして起動する l win_package (E):ファイル/urlからのインストーラーを 使ったインストール/削除 l win_ping:Windowsへのping l win_regedit (E):レジストリの操作 l win_scheduled_task (E):タスクの操作 l win_service:Windowsサービスの操作 l win_stat:Windows上のファイルstat l win_template:Python⽤のテンプレートエンジンjinja2のテ ンプレートをWindowsに転送 l win_unzip (E):Windows上のzipファイルを解凍 l win_updates (E):Windows更新プログラムの操作 l win_user:ローカルユーザの操作 l win_webpicmd (E):WebPICMD(Web Platform Installer command-line)を利⽤したパッケージのインストール http://docs.ansible.com/ansible/list_of_windows_modules.html 2016/2/1 Copyright 2016(C) OSS Laboratories Inc. All Rights Reserved 11
  12. 12. Windows前提条件 l Ansible2.0では、WinRM経由でWindowsに接続する l PowerShell 3.0<が必要 l Windows 7 SP1, Windows Server 2008 SP1以上 l Windows Server 2008での例 l 以下のファイルをダウンロードし実⾏する l Microsoft .NET Framework 4.5.2 l http://www.microsoft.com/en-us/download/details.aspx?id=42643 l ファイル名:NDP452-KB2901954-Web.exe l Windows Management Framework 4.0 l http://www.microsoft.com/ja-jp/download/details.aspx?id=40855 l ファイル名:Windows Server 2008 R2 SP1 x64: Windows6.1-KB2819745-x64- MultiPkg.msu l Windows Server 2012, Windows 8以降ではデフォルトで PowerShell 4.0< 2016/2/1 Copyright 2016(C) OSS Laboratories Inc. All Rights Reserved 12
  13. 13. 事前準備 l Powershellの確認 PS C:¥Users¥Administrator> $PSVersionTable Name Value ---- ----- PSVersion 4.0 WSManStackVersion 3.0 SerializationVersion 1.1.0.1 CLRVersion 4.0.30319.34209 BuildVersion 6.3.9600.16406 PSCompatibleVersions {1.0, 2.0, 3.0, 4.0} PSRemotingProtocolVersion 2.2 l ネットワークプロファイルの変更 l ネットワークプロファイルがパブリックならばプライベートにする。ドメインであったり元々プライベートであったりするなら ば変更の必要はない。 l Windows側の準備を⾏ってくれるスクリプトが公式に⽤意されているので、⽤意されたスクリプトをダウンロード し、以下のコマンドを実⾏する。 PS > mkdir C:¥work PS > cd C:¥work PS C:¥work > Invoke-WebRequest –Uri https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 – OutFile ConfigureRemotingForAnsible.ps1 PS C:¥work> powershell –ExecutionPolicy RemoteSigned .¥ConfigureRemotingForAnsible.ps1 PS > Set-ExecutionPolicy RemoteSigned –Force PS > winrm set winrm/config/service/auth ‘@{Basic=“true”}’ PS > winrm set winrm/config/service ‘@{AllowUnencrypted=“true”}’ PS > Set-ExecutionPolicy –Scope CurrentUser RemoteSigned l Ansible側(Linux)での設定 $ pip install pywinrm 2016/2/1 Copyright 2016(C) OSS Laboratories Inc. All Rights Reserved 13
  14. 14. 実⾏例 l hostsファイルの設定 [windows] win2008 #windwosのホスト名、IP [windows:vars] ansible_ssh_user=Administrator #ユーザ ansible_ssh_pass=password #パスワード ansible_ssh_port=5986 ansible_connection=winrm l 動作確認 $ ansible windows -i hosts -m win_ping –vvvv <win2008> ESTABLISH WINRM CONNECTION FOR USER: Administrator on PORT 5986 TO win2008 <win2008> REMOTE_MODULE win_ping <win2008> EXEC (New-Item -Type Directory -Path $env:temp -Name "ansible-tmp-1427882816.58- 246867798460713").FullName | Write-Host -Separator ''; <win2008> PUT /tmp/tmpAiMUZj TO C:¥Users¥Administrator¥AppData¥Local¥Temp¥ansible-tmp- 1427882816.58-246867798460713¥¥win_ping<win2008> PUT /tmp/tmpBEeRpO TO C:¥Users¥Administrator¥AppData¥Local¥Temp¥ansible-tmp-1427882816.58- 246867798460713¥¥arguments<win2008> EXEC & C:¥Users¥Administrator¥AppData¥Local¥Temp¥ansible-tmp-1427882816.58- 246867798460713¥¥win_ping.ps1 C:¥Users¥Administrator¥AppData¥Local¥Temp¥ansible-tmp- 1427882816.58-246867798460713¥¥arguments; Remove-Item "C:¥Users¥Administrator¥AppData¥Local¥Temp¥ansible-tmp-1427882816.58-246867798460713¥" - Force -Recurse; win2008 | success >> { "changed": false, "ping": "pong" }2016/2/1 Copyright 2016(C) OSS Laboratories Inc. All Rights Reserved 14

×