Giter Site home page Giter Site logo

stady's People

Contributors

hatakeyama-takeshi avatar

Watchers

 avatar

stady's Issues

test

- [ ] MEMBER - [ ] READER - [ ] MANAGER - [ ] MANAGER
- [ ] 豊永 - [ ] 松岡 - [ ] 畠山 - [ ] 伊奈
- [ ] 岡田 - [ ] 堀    - [ ] 松坂
- [ ] MEMBER - [ ] READER
- [ ] 豊永 - [ ] 松岡
- [ ] 岡田 - [ ] 堀

Qiita風に ansibleを触った感想を徒然に書いてみた

前提

とりあえず、作って触って見たいがスタートで、特に業務で使おうという野心はありませんww
chefみたいなツールを、自社メンバーに共有したいってのがスタートですね。

インストール

[環境]

  • ansibleサーバ (ubuntu15.10) 1台
  • ノードサーバ (ubuntu15.10) 2台 (片方はzabbix3.0サーバ、もう片方はzabbix-agentが入っている空のサーバ)

[履歴]
#3

  • インストールは超簡単でした。
  • python入れて、ansibleを入れただけ。
  • ノードサーバ側のsetttingも簡単で、opensslで公開鍵と秘密鍵作って、ノードサーバに公開鍵登録しただけ。
  • ベストプラクティスでは、専用user作って、sudo権限つけなさいって話

触ってみた。

まぁ、ネットに乗っているレベルと変わりませんが。。。。 😓
やってみたので、共有です。

触った感じ、zabbixやjenkinsのような運用ツールというか、ansibleコマンドをインストールした感触でした。
(ubuntuサーバ作る方が時間かかった。。。)
簡単にansibleをいうなれば、ansibleサーバから、各種ノードサーバに一斉にコマンド発行できるイメージです。

具体的には、~/ansible-repo配下に、hostsファイルを書いただけで以下が出来ます。

■hostsサンプル (wsがansibleサーバ、nodeがzabbix3.0サーバ)

[ws]
192.168.219.130

[node]
192.168.219.129

■全部にpingしてみた。

ansible@ansible-virtual-machine:~/ansible-repo$ ansible all -m ping
192.168.219.129 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
192.168.219.130 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
ansible@ansible-virtual-machine:~/ansible-repo$

上記は、対象サーバに一斉にpingしたコマンドです。
対象サーバはhosts管理しているので、ココは自由に書き換えられそうです。
例えばwebサーバだけにコマンド流すとかはできそうですね。

◆ノードサーバだけにping

ansible@ansible-virtual-machine:~/ansible-repo$ ansible ws -m ping
192.168.219.129 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
ansible@ansible-virtual-machine:~/ansible-repo$

◆全部のサーバにuname -a

ansible@ansible-virtual-machine:~/ansible-repo$ ansible all -m command
-a 'uname -a'
192.168.219.134 | SUCCESS | rc=0 >>
Linux ansible-virtual-machine 4.2.0-17-generic #21-Ubuntu SMP Fri Oct
23 19:56:16 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

192.168.219.133 | SUCCESS | rc=0 >>
Linux zabbix30-virtual-machine 4.2.0-17-generic #21-Ubuntu SMP Fri Oct
23 19:56:16 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

ansible@ansible-virtual-machine:~/ansible-repo$

構築導入も結構簡単で、ノード側サーバにはエージェントは本当に不要でした。
opensslで公開鍵を登録してあげるだけ。
結構、既存で動いているサーバにも適応可能ですね。

◆known_hostsに書いてないとコマンド通らない

ansible@ansible-virtual-machine:~/ansible-repo$ ansible all -m ping
The authenticity of host '192.168.219.134 (192.168.219.134)' can't be
established.
ECDSA key fingerprint is SHA256:tEGdORPcNykm0ltty1PSzpUpInJpvthHgeLXXRoX5Wo.
Are you sure you want to continue connecting (yes/no)?

◆ansibleサーバからコマンド一つでノードサーバ情報を引き抜く (絶対こんなに情報いらないw)

ansible@ansible-virtual-machine:~/ansible-repo$ ansible node -m setup
192.168.219.133 | SUCCESS => {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "192.168.219.133"
        ],
        "ansible_all_ipv6_addresses": [
            "fe80::20c:29ff:fea7:2737"
        ],
        "ansible_architecture": "x86_64",
        "ansible_bios_date": "05/20/2014",
        "ansible_bios_version": "6.00",
        "ansible_cmdline": {
            "BOOT_IMAGE": "/boot/vmlinuz-4.2.0-17-generic",
            "auto": true,
            "find_preseed": "/preseed.cfg",
            "locale": "en_US",
            "noprompt": true,
            "priority": "critical",
            "quiet": true,
            "ro": true,
            "root": "UUID=7021ff19-b992-4b2e-ad9c-24df8183438a"
        },
        "ansible_date_time": {
            "date": "2016-02-28",
            "day": "28",
            "epoch": "1456668963",
            "hour": "06",
            "iso8601": "2016-02-28T14:16:03Z",
            "iso8601_basic": "20160228T061603256142",
            "iso8601_basic_short": "20160228T061603",
            "iso8601_micro": "2016-02-28T14:16:03.256219Z",
            "minute": "16",
            "month": "02",
            "second": "03",
            "time": "06:16:03",
            "tz": "PST",
            "tz_offset": "-0800",
            "weekday": "Sunday",
            "weekday_number": "0",
            "weeknumber": "08",
            "year": "2016"
        },
        "ansible_default_ipv4": {
            "address": "192.168.219.133",
            "alias": "eno16777736",
            "broadcast": "192.168.219.255",
            "gateway": "192.168.219.2",
            "interface": "eno16777736",
            "macaddress": "00:0c:29:a7:27:37",
            "mtu": 1500,
            "netmask": "255.255.255.0",
            "network": "192.168.219.0",
            "type": "ether"
        },
        "ansible_default_ipv6": {},
        "ansible_devices": {
            "fd0": {
                "holders": [],
                "host": "",
                "model": null,
                "partitions": {},
                "removable": "1",
                "rotational": "1",
                "scheduler_mode": "deadline",
                "sectors": "8",
                "sectorsize": "512",
                "size": "4.00 KB",
                "support_discard": "0",
                "vendor": null
            },
            "sda": {
                "holders": [],
                "host": "SCSI storage controller: LSI Logic / Symbios
Logic 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)",
                "model": "VMware Virtual S",
                "partitions": {
                    "sda1": {
                        "sectors": "39843840",
                        "sectorsize": 512,
                        "size": "19.00 GB",
                        "start": "2048"
                    },
                    "sda2": {
                        "sectors": "2",
                        "sectorsize": 512,
                        "size": "1.00 KB",
                        "start": "39847934"
                    },
                    "sda5": {
                        "sectors": "2093056",
                        "sectorsize": 512,
                        "size": "1022.00 MB",
                        "start": "39847936"
                    }
                },
                "removable": "0",
                "rotational": "1",
                "scheduler_mode": "deadline",
                "sectors": "41943040",
                "sectorsize": "512",
                "size": "20.00 GB",
                "support_discard": "0",
                "vendor": "VMware,"
            },
            "sr0": {
                "holders": [],
                "host": "SATA controller: VMware SATA AHCI controller",
                "model": "VMware SATA CD00",
                "partitions": {},
                "removable": "1",
                "rotational": "1",
                "scheduler_mode": "deadline",
                "sectors": "91208",
                "sectorsize": "2048",
                "size": "178.14 MB",
                "support_discard": "0",
                "vendor": "NECVMWar"
            },
            "sr1": {
                "holders": [],
                "host": "SATA controller: VMware SATA AHCI controller",
                "model": "VMware SATA CD01",
                "partitions": {},
                "removable": "1",
                "rotational": "1",
                "scheduler_mode": "deadline",
                "sectors": "2528448",
                "sectorsize": "2048",
                "size": "4.82 GB",
                "support_discard": "0",
                "vendor": "NECVMWar"
            }
        },
        "ansible_distribution": "Ubuntu",
        "ansible_distribution_major_version": "15",
        "ansible_distribution_release": "wily",
        "ansible_distribution_version": "15.10",
        "ansible_dns": {
            "nameservers": [
                "127.0.1.1"
            ],
            "search": [
                "localdomain"
            ]
        },
        "ansible_domain": "",
        "ansible_eno16777736": {
            "active": true,
            "device": "eno16777736",
            "ipv4": {
                "address": "192.168.219.133",
                "broadcast": "192.168.219.255",
                "netmask": "255.255.255.0",
                "network": "192.168.219.0"
            },
            "ipv6": [
                {
                    "address": "fe80::20c:29ff:fea7:2737",
                    "prefix": "64",
                    "scope": "link"
                }
            ],
            "macaddress": "00:0c:29:a7:27:37",
            "module": "e1000",
            "mtu": 1500,
            "pciid": "0000:02:01.0",
            "promisc": false,
            "type": "ether"
        },
        "ansible_env": {
            "HOME": "/home/ansible",
            "LANG": "en_US.UTF-8",
            "LC_ADDRESS": "ja_JP.UTF-8",
            "LC_ALL": "en_US.UTF-8",
            "LC_IDENTIFICATION": "ja_JP.UTF-8",
            "LC_MEASUREMENT": "ja_JP.UTF-8",
            "LC_MESSAGES": "en_US.UTF-8",
            "LC_MONETARY": "ja_JP.UTF-8",
            "LC_NAME": "ja_JP.UTF-8",
            "LC_NUMERIC": "ja_JP.UTF-8",
            "LC_PAPER": "ja_JP.UTF-8",
            "LC_TELEPHONE": "ja_JP.UTF-8",
            "LC_TIME": "ja_JP.UTF-8",
            "LOGNAME": "ansible",
            "MAIL": "/var/mail/ansible",
            "PATH":
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games",
            "PWD": "/home/ansible",
            "SHELL": "/bin/bash",
            "SHLVL": "1",
            "SSH_CLIENT": "192.168.219.134 43628 22",
            "SSH_CONNECTION": "192.168.219.134 43628 192.168.219.133 22",
            "SSH_TTY": "/dev/pts/4",
            "TERM": "xterm",
            "USER": "ansible",
            "XDG_RUNTIME_DIR": "/run/user/1001",
            "XDG_SESSION_ID": "43",
            "_": "/bin/sh"
        },
        "ansible_fips": false,
        "ansible_form_factor": "Other",
        "ansible_fqdn": "zabbix30-virtual-machine",
        "ansible_hostname": "zabbix30-virtual-machine",
        "ansible_interfaces": [
            "eno16777736",
            "lo"
        ],
        "ansible_kernel": "4.2.0-17-generic",
        "ansible_lo": {
            "active": true,
            "device": "lo",
            "ipv4": {
                "address": "127.0.0.1",
                "broadcast": "host",
                "netmask": "255.0.0.0",
                "network": "127.0.0.0"
            },
            "ipv6": [
                {
                    "address": "::1",
                    "prefix": "128",
                    "scope": "host"
                }
            ],
            "mtu": 65536,
            "promisc": false,
            "type": "loopback"
        },
        "ansible_lsb": {
            "codename": "wily",
            "description": "Ubuntu 15.10",
            "id": "Ubuntu",
            "major_release": "15",
            "release": "15.10"
        },
        "ansible_machine": "x86_64",
        "ansible_machine_id": "e8d13139c36c46e4845f3953f3379339",
        "ansible_memfree_mb": 23,
        "ansible_memory_mb": {
            "nocache": {
                "free": 317,
                "used": 658
            },
            "real": {
                "free": 23,
                "total": 975,
                "used": 952
            },
            "swap": {
                "cached": 23,
                "free": 716,
                "total": 1021,
                "used": 305
            }
        },
        "ansible_memtotal_mb": 975,
        "ansible_mounts": [
            {
                "device": "/dev/sda1",
                "fstype": "ext4",
                "mount": "/",
                "options": "rw,relatime,errors=remount-ro,data=ordered",
                "size_available": 13864468480,
                "size_total": 19945680896,
                "uuid": "7021ff19-b992-4b2e-ad9c-24df8183438a"
            }
        ],
        "ansible_nodename": "zabbix30-virtual-machine",
        "ansible_os_family": "Debian",
        "ansible_pkg_mgr": "apt",
        "ansible_processor": [
            "GenuineIntel",
            "Intel(R) Core(TM) i7-4700MQ CPU @ 2.40GHz"
        ],
        "ansible_processor_cores": 1,
        "ansible_processor_count": 1,
        "ansible_processor_threads_per_core": 1,
        "ansible_processor_vcpus": 1,
        "ansible_product_name": "VMware Virtual Platform",
        "ansible_product_serial": "NA",
        "ansible_product_uuid": "NA",
        "ansible_product_version": "None",
        "ansible_python_version": "2.7.10",
        "ansible_selinux": false,
        "ansible_service_mgr": "systemd",
        "ansible_ssh_host_key_dsa_public": (削除),
        "ansible_ssh_host_key_ecdsa_public":(削除),
        "ansible_ssh_host_key_ed25519_public"(削除),
        "ansible_ssh_host_key_rsa_public":(削除),
        "ansible_swapfree_mb": 716,
        "ansible_swaptotal_mb": 1021,
        "ansible_system": "Linux",
        "ansible_system_vendor": "VMware, Inc.",
        "ansible_uptime_seconds": 42941,
        "ansible_user_dir": "/home/ansible",
        "ansible_user_gecos": ",,,",
        "ansible_user_gid": 1001,
        "ansible_user_id": "ansible",
        "ansible_user_shell": "/bin/bash",
        "ansible_user_uid": 1001,
        "ansible_userspace_architecture": "x86_64",
        "ansible_userspace_bits": "64",
        "ansible_virtualization_role": "guest",
        "ansible_virtualization_type": "VMware",
        "module_setup": true
    },
    "changed": false
}
ansible@ansible-virtual-machine:~/ansible-repo$

実際にplaybook書いてみたが、失敗w

上記は、pingだけですが、playbookを作れば、対象サーバへの一斉ユーザ追加やログ収集、
ssl証明書更新やntpインストール、たぶんapach再起動みたいなこともansibleで出来そうという事でした。
エージェントレスとかを考えると、古いウォーターフォール型のシステム運用でも、気軽に導入できる気がするので、試してみた。

◆ntpをインストールさせようとして失敗したログ
(sudo使えるようにしないとダメだとさ)

ansible@ansible-virtual-machine:~/ansible-repo$ ansible-playbook -C ntp.yml
[DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user and
make sure become_method is 'sudo' (default). This feature will be removed in a
future release. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.

PLAY ***************************************************************************

TASK [setup] *******************************************************************
fatal: [192.168.219.133]: UNREACHABLE! => {"changed": false, "msg":
"SSH encountered an unknown error during the connection. We recommend
you re-run the command using -vvvv, which will enable SSH debugging
output to help diagnose the issue", "unreachable": true}
fatal: [192.168.219.134]: FAILED! => {"changed": false, "failed":
true, "module_stderr": "", "module_stdout": "sudo: a password is
required\r\n", "msg": "MODULE FAILURE", "parsed": false}

NO MORE HOSTS LEFT *************************************************************
        to retry, use: --limit @ntp.retry

PLAY RECAP *********************************************************************
192.168.219.133            : ok=0    changed=0    unreachable=1    failed=0
192.168.219.134            : ok=0    changed=0    unreachable=0    failed=1

ansible@ansible-virtual-machine:~/ansible-repo$

実行した結果、サーバに届いてないとか、実行に失敗したというのが、ひとめで分かりますね。

◆うまくいくとこうなる。

$ ansible-playbook ntp.yml

PLAY [all] ********************************************************************

GATHERING FACTS ***************************************************************
ok: [192.168.219.133]
ok: [192.168.219.134]

TASK: [install latest ntp package] ********************************************
changed: [192.168.219.133]
changed: [192.168.219.134]

PLAY RECAP ********************************************************************
192.168.219.133            : ok=2    changed=1    unreachable=0    failed=0
192.168.219.134            : ok=2    changed=1    unreachable=0    failed=0

ansibleのいいところは、ドライランができることでした。
-Cオプションをいれると、実際にはntpインストールするサーバでコマンドがうまくいくかを先にチェックしてくれます。
これは、心強い。(どこまで信用できるかは、疑心暗鬼w)

playブックですが、YAML形式で、Ansible独自の手続き言語らしいのですが、
まぁ、やっていることはコマンドと変わらないかなぁと。
それこそ、参考書に転がっているレベルはnetにいっぱいありました。
あんまり心配いらないですね

windowsをnodeにできる?そっちも簡単?

もうひとつ、調べてたのは、winodows相手に、ansibleコマンドを打てるかです。
加えて、簡単かどうかがpointです。

こちらは、chefと一緒でcygwinインストール必須でした。。。。
時間切れの為、いったん後回し。
win2008R2環境だけ作っておいたので、あとで試してみる。

触ってみての感触。

下馬評どおり、簡単です。linuxは。
windowsになるとcygwinインストールしないといけないとか、chefと変わんないので、
既存で、chef/puppetを使っている場合は、導入メリット薄めです。

さわってみてですが、
playbookとhostsの管理方法に課題があるとネットにありましたが、まさにそうだとおもいました。
コマンド実行のために書いたファイルが散乱します。
複数人で書いているとごちゃごちゃになりそうでした。
(一人で遊んでても、このバックアップファイルなんだ?と迷う始末。。。)

git intして、github上で管理するのが必須ですね。
(次作るときは、絶対git登録しよう。。。)
ベストプラクティスはあるみたいですが、、、ここら辺は実際に使っている人の講演会とかで聞くのが一番よさそう。

プラス面として押したいのが、ドライラン機能。
chefで実行後確認とか、はらはらしながら実行するとかは、やっぱり運用者としては博打的な要素が強い。
もっと、高機能リリースするようにしないと、どれぐらいの精度か分からないけど、、、
実行前にプレ実行できるのは、YESな機能とおもいました。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.