ikepon / vagrant_centos

0 stars 0 forks source link

Vagrant上にansibleでいろいろをやってみる #3

Open ikepon opened 6 years ago

ikepon commented 6 years ago

参考にした記事

ikepon commented 6 years ago

==> Installing dependencies for ansible: libyaml, sqlite, gdbm, python ==> Installing ansible dependency: libyaml ==> Downloading https://homebrew.bintray.com/bottles/libyaml-0.1.7.sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring libyaml-0.1.7.sierra.bottle.tar.gz 🍺 /usr/local/Cellar/libyaml/0.1.7: 8 files, 312.6KB ==> Installing ansible dependency: sqlite ==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.21.0.sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring sqlite-3.21.0.sierra.bottle.tar.gz ==> Caveats Homebrew has detected an existing SQLite history file that was created with the editline library. The current version of this formula is built with Readline. To back up and convert your history file so that it can be used with Readline, run:

sed -i~ 's/\040/ /g' ~/.sqlite_history

before using the sqlite command-line tool again. Otherwise, your history will be lost.

This formula is keg-only, which means it was not symlinked into /usr/local, because macOS provides an older sqlite3.

If you need to have this software first in your PATH run: echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.zshrc

For compilers to find this software you may need to set: LDFLAGS: -L/usr/local/opt/sqlite/lib CPPFLAGS: -I/usr/local/opt/sqlite/include For pkg-config to find this software you may need to set: PKG_CONFIG_PATH: /usr/local/opt/sqlite/lib/pkgconfig

==> Summary 🍺 /usr/local/Cellar/sqlite/3.21.0: 11 files, 3.0MB ==> Installing ansible dependency: gdbm ==> Downloading https://homebrew.bintray.com/bottles/gdbm-1.14.1_1.sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring gdbm-1.14.1_1.sierra.bottle.tar.gz 🍺 /usr/local/Cellar/gdbm/1.14.1_1: 20 files, 555.8KB ==> Installing ansible dependency: python ==> Downloading https://homebrew.bintray.com/bottles/python-2.7.14_2.sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring python-2.7.14_2.sierra.bottle.tar.gz ==> /usr/local/Cellar/python/2.7.14_2/bin/python2 -s setup.py --no-user-cfg install --force --verbose --single-version-externally-managed --record=installed.txt --install-scripts=/usr/local/Cellar/python/ ==> /usr/local/Cellar/python/2.7.14_2/bin/python2 -s setup.py --no-user-cfg install --force --verbose --single-version-externally-managed --record=installed.txt --install-scripts=/usr/local/Cellar/python/ ==> /usr/local/Cellar/python/2.7.14_2/bin/python2 -s setup.py --no-user-cfg install --force --verbose --single-version-externally-managed --record=installed.txt --install-scripts=/usr/local/Cellar/python/ ==> Caveats This formula installs a python2 executable to /usr/local/bin. If you wish to have this formula's python executable in your PATH then add the following to ~/.zshrc: export PATH="/usr/local/opt/python/libexec/bin:$PATH"

Pip and setuptools have been installed. To update them pip2 install --upgrade pip setuptools

You can install Python packages with pip2 install

They will install into the site-package directory /usr/local/lib/python2.7/site-packages

See: https://docs.brew.sh/Homebrew-and-Python.html ==> Summary 🍺 /usr/local/Cellar/python/2.7.14_2: 3,517 files, 48.4MB ==> Installing ansible ==> Downloading https://homebrew.bintray.com/bottles/ansible-2.4.2.0_2.sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring ansible-2.4.2.0_2.sierra.bottle.tar.gz 🍺 /usr/local/Cellar/ansible/2.4.2.0_2: 10,625 files, 134.3MB

➜ ansible_vagrant git:(master) ✗ ansible --version ansible 2.4.2.0 config file = None configured module search path = [u'/Users/ikepon/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/Cellar/ansible/2.4.2.0_2/libexec/lib/python2.7/site-packages/ansible executable location = /usr/local/bin/ansible python version = 2.7.10 (default, Feb 7 2017, 00:08:15) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)]

ikepon commented 6 years ago

記事には vagrant up で走るってあったけど、設定が悪いのか ansible が走らない...

➜  centos7 git:(master) ✗ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'centos/7' is up to date...
==> default: A newer version of the box 'centos/7' is available! You currently
==> default: have version '1710.01'. The latest is version '1801.01'. Run
==> default: `vagrant box update` to update.
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: No guest additions were detected on the base box for this VM! Guest
    default: additions are required for forwarded ports, shared folders, host only
    default: networking, and more. If SSH fails on this machine, please install
    default: the guest additions and repackage the box to continue.
    default:
    default: This is not an error message; everything may continue to work properly,
    default: in which case you may ignore this message.
==> default: Configuring and enabling network interfaces...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Rsyncing folder: /Users/ikepon/ikepon/00_DIG/centos7/ => /vagrant
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.
ikepon commented 6 years ago

vagrant provision を実行したら走った!

➜  centos7 git:(master) ✗ vagrant provision
==> default: Running provisioner: ansible...
Vagrant has automatically selected the compatibility mode '2.0'
according to the Ansible version installed (2.4.2.0).

Alternatively, the compatibility mode can be specified in your Vagrantfile:
https://www.vagrantup.com/docs/provisioning/ansible_common.html#compatibility_mode

    default: Running ansible-playbook...
[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
version 2.6. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.

PLAY [vagrants] ****************************************************************

TASK [Gathering Facts] *********************************************************
ok: [192.168.33.10]

TASK [install packages zsh] ****************************************************
changed: [192.168.33.10]

PLAY RECAP *********************************************************************
192.168.33.10              : ok=2    changed=1    unreachable=0    failed=0
ikepon commented 6 years ago

zsh がインストールされてる

[vagrant@localhost ~]$ zsh --version
zsh 5.0.2 (x86_64-redhat-linux-gnu)
ikepon commented 6 years ago

もう一回 vagrant provision を実行すると最後の行の changed が 0 になる。 これですでに実行されているものは、2回目以降は実行されないってのが分かる。

➜  centos7 git:(master) ✗ vagrant provision
==> default: Running provisioner: ansible...
Vagrant has automatically selected the compatibility mode '2.0'
according to the Ansible version installed (2.4.2.0).

Alternatively, the compatibility mode can be specified in your Vagrantfile:
https://www.vagrantup.com/docs/provisioning/ansible_common.html#compatibility_mode

    default: Running ansible-playbook...
[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
version 2.6. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.

PLAY [vagrants] ****************************************************************

TASK [Gathering Facts] *********************************************************
ok: [192.168.33.10]

TASK [install packages zsh] ****************************************************
ok: [192.168.33.10]

PLAY RECAP *********************************************************************
192.168.33.10              : ok=2    changed=0    unreachable=0    failed=0
ikepon commented 6 years ago

git をインストール 元々入ってたので、 changed=0 になってる。

➜  centos7 git:(master) ✗ vagrant provision
==> default: Running provisioner: ansible...
Vagrant has automatically selected the compatibility mode '2.0'
according to the Ansible version installed (2.4.2.0).

Alternatively, the compatibility mode can be specified in your Vagrantfile:
https://www.vagrantup.com/docs/provisioning/ansible_common.html#compatibility_mode

    default: Running ansible-playbook...
[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
version 2.6. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.

PLAY [vagrants] ****************************************************************

TASK [Gathering Facts] *********************************************************
ok: [192.168.33.10]

TASK [install packages zsh] ****************************************************
ok: [192.168.33.10]

TASK [install packages git] ****************************************************
ok: [192.168.33.10]

PLAY RECAP *********************************************************************
192.168.33.10              : ok=3    changed=0    unreachable=0    failed=0
ikepon commented 6 years ago

https://qiita.com/iamdaisuke/items/46da26b4060ddec18895 この記事を参考に必要そうなものをインストール。 新しくインストールされたもの ⬇️ それ以外はすでに入ってた。

TASK [install packages libyaml-devel] ******************************************
changed: [192.168.33.10]
ikepon commented 6 years ago

mkdir の permission がない。 sudo にしてやると、 rbenv がないって言われる。 ユーザーを定義してやれば大丈夫な気はするけど...

fatal: [192.168.33.10]: FAILED! => {"changed": true, "cmd": "bash -lc \"rbenv install 2.5.0\"", "delta": "0:00:31.991281", "end": "2018-01-20 15:38:47.247250", "msg": "non-zero return code", "rc": 1, "start": "2018-01-20 15:38:15.255969", "stderr": "/etc/profile: line 79: rbenv: command not found\nmkdir: cannot create directory ‘/usr/local/rbenv/shims’: Permission denied\nmkdir: cannot create directory ‘/usr/local/rbenv/versions’: Permission denied\nmkdir: cannot create directory ‘/usr/local/rbenv/shims’: Permission denied\nmkdir: cannot create directory ‘/usr/local/rbenv/versions’: Permission denied\nDownloading ruby-2.5.0.tar.bz2...\n-> https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.0.tar.bz2\nInstalling ruby-2.5.0...\nmkdir: cannot create directory ‘/usr/local/rbenv/versions’: Permission denied\n\nBUILD FAILED (CentOS Linux 7 using ruby-build 20171226-3-g01e7b7b)\n\nInspect or clean up the working tree at /tmp/ruby-build.20180120153815.19557\nResults logged to /tmp/ruby-build.20180120153815.19557.log\n\nLast 10 log lines:\n/tmp/ruby-build.20180120153815.19557 ~\n/tmp/ruby-build.20180120153815.19557/ruby-2.5.0 /tmp/ruby-build.20180120153815.19557 ~", "stderr_lines": ["/etc/profile: line 79: rbenv: command not found", "mkdir: cannot create directory ‘/usr/local/rbenv/shims’: Permission denied", "mkdir: cannot create directory ‘/usr/local/rbenv/versions’: Permission denied", "mkdir: cannot create directory ‘/usr/local/rbenv/shims’: Permission denied", "mkdir: cannot create directory ‘/usr/local/rbenv/versions’: Permission denied", "Downloading ruby-2.5.0.tar.bz2...", "-> https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.0.tar.bz2", "Installing ruby-2.5.0...", "mkdir: cannot create directory ‘/usr/local/rbenv/versions’: Permission denied", "", "BUILD FAILED (CentOS Linux 7 using ruby-build 20171226-3-g01e7b7b)", "", "Inspect or clean up the working tree at /tmp/ruby-build.20180120153815.19557", "Results logged to /tmp/ruby-build.20180120153815.19557.log", "", "Last 10 log lines:", "/tmp/ruby-build.20180120153815.19557 ~", "/tmp/ruby-build.20180120153815.19557/ruby-2.5.0 /tmp/ruby-build.20180120153815.19557 ~"], "stdout": "", "stdout_lines": []}

sudo 付ける

fatal: [192.168.33.10]: FAILED! => {"changed": true, "cmd": "bash -lc \"rbenv versions\"", "delta": "0:00:00.013011", "end": "2018-01-20 15:44:23.632614", "msg": "non-zero return code", "rc": 127, "start": "2018-01-20 15:44:23.619603", "stderr": "/etc/profile: line 79: rbenv: command not found\n/root/.bash_profile: line 14: rbenv: command not found\n/root/.bash_profile: line 16: rbenv: command not found\n/root/.bash_profile: line 18: rbenv: command not found\n/root/.bash_profile: line 20: rbenv: command not found\n/root/.bash_profile: line 22: rbenv: command not found\nbash: rbenv: command not found", "stderr_lines": ["/etc/profile: line 79: rbenv: command not found", "/root/.bash_profile: line 14: rbenv: command not found", "/root/.bash_profile: line 16: rbenv: command not found", "/root/.bash_profile: line 18: rbenv: command not found", "/root/.bash_profile: line 20: rbenv: command not found", "/root/.bash_profile: line 22: rbenv: command not found", "bash: rbenv: command not found"], "stdout": "", "stdout_lines": []}