Ansible quickstart

  • View
    2.823

  • Download
    7

Embed Size (px)

DESCRIPTION

Ansible Quickstart

Text of Ansible quickstart

  • 1. Ansible ~ Quick Start ~ Internet Initiative Inc. Hideki Saito (@saito_hideki)1ver1.1

2. Ansible - 2 3. : ( ) -Twitter: @saito_hideki Blog: http://d.hatena.ne.jp/pyde/: (IIJ) -http://www.iij.ad.jp/: OpenStack : Python/OpenStack /Ansible: -http://www.iij.ad.jp/GIO/3 4. Ansible Ansible Ansible 4 5. Ansible5 6. Ansible - Python**** - OS Playbook1 - - ( ) - pushSSH - : http://www.ansibleworks.com/ - : https://github.com/ansible/ansible - githubtagv0.012009 - (2013-12)v1.4.1 6 7. 2 ) -Puppetruby) Chef (ruby) Capistrano (ruby) Ansiblepython!!!) API-Apache libcloud Deltacloud Rightscale SCALR 7 8. () module - ansible playbook - (module) plugin - modulecallbackansible inventory - hosts8 9. Ansible9 10. ubuntu12.04lts[1]) 1. 12.04v1.1OpenStack github(v1.3.4)!$ sudo apt-get install -y git python-pip python-virtualenv!2. virtualenvAnsible 1. virtualenv ansibleOS! ! ! ! !$ virtualenv app New python executable in ansible/bin/python Installing distribute....done. Installing pip...done. $ source app/bin/activate (app) $2. ansible (app) $ pip install PyYAML jinja2 10 11. ubuntu12.04lts[2]) ! 3. githubansible- v1.3.4checkout - app/share/ansible/(app) (app) (app) (app) (app) (app)$ mkdir src && cd src $ git clonehttps://github.com/ansible/ansible.git $ cd ansible $ git checkout -b v1.3.4 v1.3.4 Switched to a new branch 'v1.3.4 $ python setup.pybuildmodulesmodulesA)modulesB)pythonpython-virtualenv(A) ~/app/python-virtualenv(B) ~/hogehoge/!OS virtualenv 11 12. ubuntu12.04lts[3]) 3. 1. IP !(app) $ echo 192.168.100.110 > hosts! 2. ping(success) (app) $ ansible -i hosts all -u foo -k -m ping SSH password: ******** 192.168.100.110 | success >> { "changed": false, "ping": "pong" }! -i: -u: ssh -k: ssh -m 12 13. restartedubuntu12.04lts[4]) ! 3. setup Playbook (app) $ ansible -i hosts all -u foo -k -m setup SSH password: ******** 172.16.8.130 | success >> { "ansible_facts": { "ansible_all_ipv4_addresses": [ "192.168.122.1", "172.16.8.130", "169.254.169.254" ], "ansible_all_ipv6_addresses": [ "fe80::20c:29ff:fe8e:2665", "fe80::883d:a8ff:fead:cfaf" ], "ansible_architecture": "x86_64", "ansible_bios_date": "07/31/2013", "ansible_bios_version": "6.00", "ansible_br_ex": { "active": true, [] 13 14. Ansible14 15. ) Ansible pythonsftpssh 15 16. ) python Ansible16 17. Ansible CategoryDescriptionCloudEC2/OpenStackCommandsDatabaseMySQLFilesInternalAnsibleInventoryMessagingAMQPMonitoringNet InfrastructureNetworkHTTP/FTPNotificationIRC/EMail)Packagingyum/apt/pipSource ControlgitSystemOSUtilitiesAnsibleWeb InfrastructuredjangoWeb 17 18. Ansible ansible-doc [] ansible-doc (app) $ ansible-doc file > FILE!!Sets attributes of files, symlinks, and directories, or removes files/symlinks/directories. Many other modules support the same options as the [file] module - including [copy], [template], and [assemble].Options (= is mandatory):!- force force the creation of the symlinks in two cases: the source file does not exist (but will appear later); the destination exists and a file (so, we need to unlink the "path" file and create symlink to the "src" file in place of it). (Choices: yes, no) Notes:!See also [copy], [template], [assemble]- file: path=/etc/foo.conf owner=foo group=foo mode=0644 - file: src=/file/to/link/to dest=/path/to/symlink owner=foo group=foo state=link18 19. servicehttpd (app) $ ansible -i hosts all -u foo -k -K -m service -a "name=httpd state=restarted" SSH password: ******** sudo password [defaults to SSH password]: ******** 172.16.0.1 | success >> { "changed": true, "name": "httpd", "state": "started" }! ! ! !yumlibselinux-python (app) $ ansible -i hosts all -u foo -k -K -m yum -a "name=libselinux-python state=present" SSH password: ******** sudo password [defaults to SSH password]: ******** 172.16.0.1 | success >> { "changed": true, "msg": "", "rc": 0, "results": [ "Loaded plugins: fastestmirror, prioritiesnLoading mirror speeds from cached hostfilen * base: ftp.jaist.ac.jpn * epel: ftp.kddilabs.jpn * extras: ftp.jaist.ac.jpn * updates: ftp.jaist.ac.jpn183 packages excluded due to repository priority protectionsnSetting up Install ProcessnResolving Dependenciesn--> Running transaction checkn---> Package libselinux-python.x86_64 0:2.0.94-5.3.el6_4.1 will be installedn--> Finished Dependency ResolutionnnDependencies Resolvedn n================================================================================n Package Arch Version Repository Size n================================================================================nInstalling:n libselinux-python x86_64 2.0.94-5.3.el6_4.1 updates 202 knnTransaction Summary n================================================================================nInstall 1 Package(s)nnTotal download size: 202 knInstalled size: 653 knDownloading Packages:nRunning rpm_check_debugnRunning Transaction Test nTransaction Test SucceedednRunning Transactionnr Installing : libselinux-python-2.0.94-5.3.el6_4.1.x86_64 1/1 nr Verifying : libselinux-python-2.0.94-5.3.el6_4.1.x86_64 1/1 nnInstalled:n libselinuxpython.x86_64 0:2.0.94-5.3.el6_4.1 nnComplete!n" ] }19 20. AnsiblePlaybook1 apachemysql1 1 nginx MySQL PHPAnsiblePlaybook WordPress 20 21. AnsiblePlaybook2 Playbookwordpress-releaseplaybook/group_vars/ all roles/ -A/ tasks/ main.yml handlers/ main.yml templates/ foo.conf.j2 bar.conf.j2 baz.conf.j2 le/ hogehoge.conf -B/Playbook mysqlroles tasks tasksmy.cnf mysqld my.cnf {{ }} jinja2 -C/ site.ymlPlaybook(roles)21 22. AnsiblePlaybook3 Playbook $ ansible-playbook -u root -k -i hosts site.yml SSH password: ********! !PLAY [Install Wordpress, MySQL, Nginx, and PHP-FPM] *************************** GATHERING FACTS *************************************************************** ok: [192.168.100.110] [] TASK: [Install Mysql package] ************************************************* changed: [192.168.100.110] => (item=mysql-server,MySQL-python,libselinux-python,libsemanage-python)!TASK: [Create Mysql configuration file] *************************************** changed: [192.168.100.110] [] PLAY RECAP ******************************************************************** 192.168.100.110 : ok=25 changed=24 unreachable=0 failed=022 23. ansibleplaybook httpd YAML --- - hosts: webservers vars: http_port: 80 max_clients: 200 remote_user: root tasks: - name: ensure apache is at the latest version yum: pkg=httpd state=latest - name: write the apache config file template: src=/srv/httpd.j2 dest=/etc/httpd.conf notify: - restart apache - name: ensure apache is running service: name=httpd state=started handlers: - name: restart apache service: name=httpd state=restarted 23 24. Ansible Ansible(virtualenv) Ansible Ansible Playbook24 25. Ansible -http://www.ansibleworks.com/docs/-http://www.ansibleworks.comhttp://www.ansibleworks.com/docs/modules.htmlExample ansible-examples -https://github.com/ansible/ansible-examplesopenstack-ansible -https://github.com/yosshy/openstack-ansible25 26. 26