LoginSignup
11
11

More than 5 years have passed since last update.

Bash on Ubuntu on WindowsでAnsibleが動くか試してみたが、Build 14342で2.0.2が動いた

Last updated at Posted at 2016-04-10

Bash on Ubuntu on Windowsなんてものが出てくるなんて聞いたら、普段WindowsとAnsibleを使用している身ともなればもしかしたらこれでAnsibleが動くんじゃないかと期待してしまうのが当然の流れ。

で、Bash on Ubuntu on WindowsをインストールできるWindows 10 Insider Preview Build 14316がテスト環境に降ってきたので早速試してみた。
……そしてAnsibleが動かないことを確認した。 (2016-04-13: Ansible 1.8.4なら動くことを確認した)

(2016-05-12)
Build 14342でPPAからインストールできるAnsible 2.0.2が動作した。
1.8.4で行ったssh_argsの修正も不要。
なので以降の文章は無視して良い。

まずPPAにあるものをインストール→動かない

Bash on Ubuntu on Windowsのインストールは以下に従った。
http://blog.dustinkirkland.com/2016/04/howto-ubuntu-on-windows.html

Bash on Ubuntu on Windowsを起動したらrootユーザになっていた。
aptが使えると聞いていたので実行してみたがエラーになる。
/etc/resolv.confが空だった。1行nameserver <適当なDNSサーバ>を追加しておいた。

その後はaptが使える。Ubuntu 14.04なのでtrustyのリポジトリに繋がる。
というわけでAnsibleのインストールは特に問題なく。

# apt-add-repository ppa:ansible/ansible
# apt update
# apt install ansible

上記でインストールされるAnsibleは2.0.1。

# dpkg -l | grep ansible
ii  ansible                          2.0.1.0-1ppa~trusty              all          A radically simple IT automation platform

で、ansibleのadhocコマンドを実行するとエラー。

# ansible
Traceback (most recent call last):
  File "/usr/bin/ansible", line 40, in <module>
    from ansible.utils.display import Display
  File "/usr/lib/pymodules/python2.7/ansible/utils/display.py", line 49, in <module>
    debug_lock = Lock()
  File "/usr/lib/python2.7/multiprocessing/__init__.py", line 176, in Lock
    return Lock()
  File "/usr/lib/python2.7/multiprocessing/synchronize.py", line 147, in __init__
    SemLock.__init__(self, SEMAPHORE, 1, 1)
  File "/usr/lib/python2.7/multiprocessing/synchronize.py", line 75, in __init__
    sl = self._semlock = _multiprocessing.SemLock(kind, value, maxvalue)
OSError: [Errno 38] Function not implemented

このエラーをgoogleに問い合わせてみると以下のような情報。
http://www.boris.co/2012/02/server-ubuntu-11.html

Bash on Ubuntu on Windowsの環境で見てみると/dev/shmは/run/shmへのシンボリックリンクになっていたが/run/shmは存在しなかった。
この記事を参考に/run/shmを作ってみたりマウントしてみたりしたが解決せず。

(2016-04-13追記:以下でも話題になっている。)
https://wpdev.uservoice.com/forums/266908-command-prompt-console-bash-on-ubuntu-on-windo/suggestions/13333764-python-bugs

実際にはスタックトレース中にあるdebug_lock = Lock()のdebug_lockはデフォルト設定では使われないのでdebug_lock = Noneとかに変えてみた(他に/usr/lib/pymodules/python2.7/ansible/utils/debug.pyでも同じことをやった)ところ、とりあえずansibleだけならヘルプが表示されるようにはなった。エラーは表示されているがこれは正しいエラーである。

# ansible
Usage: ansible <host-pattern> [options]

Options:
  -a MODULE_ARGS, --args=MODULE_ARGS
                        module arguments
  --ask-become-pass     ask for privilege escalation password
  -k, --ask-pass        ask for connection password
  --ask-su-pass         ask for su password (deprecated, use become)
  -K, --ask-sudo-pass   ask for sudo password (deprecated, use become)
  --ask-vault-pass      ask for vault password
  -B SECONDS, --background=SECONDS
                        run asynchronously, failing after X seconds
                        (default=N/A)
  -b, --become          run operations with become (nopasswd implied)
  --become-method=BECOME_METHOD
                        privilege escalation method to use (default=sudo),
                        valid choices: [ sudo | su | pbrun | pfexec | runas |
                        doas ]
  --become-user=BECOME_USER
                        run operations as this user (default=root)
  -C, --check           don't make any changes; instead, try to predict some
                        of the changes that may occur
  -c CONNECTION, --connection=CONNECTION
                        connection type to use (default=smart)
  -D, --diff            when changing (small) files and templates, show the
                        differences in those files; works great with --check
  -e EXTRA_VARS, --extra-vars=EXTRA_VARS
                        set additional variables as key=value or YAML/JSON
  -f FORKS, --forks=FORKS
                        specify number of parallel processes to use
                        (default=5)
  -h, --help            show this help message and exit
  -i INVENTORY, --inventory-file=INVENTORY
                        specify inventory host path
                        (default=/etc/ansible/hosts) or comma separated host
                        list.
  -l SUBSET, --limit=SUBSET
                        further limit selected hosts to an additional pattern
  --list-hosts          outputs a list of matching hosts; does not execute
                        anything else
  -m MODULE_NAME, --module-name=MODULE_NAME
                        module name to execute (default=command)
  -M MODULE_PATH, --module-path=MODULE_PATH
                        specify path(s) to module library (default=None)
  --new-vault-password-file=NEW_VAULT_PASSWORD_FILE
                        new vault password file for rekey
  -o, --one-line        condense output
  --output=OUTPUT_FILE  output file name for encrypt or decrypt; use - for
                        stdout
  -P POLL_INTERVAL, --poll=POLL_INTERVAL
                        set the poll interval if using -B (default=15)
  --private-key=PRIVATE_KEY_FILE, --key-file=PRIVATE_KEY_FILE
                        use this file to authenticate the connection
  --scp-extra-args=SCP_EXTRA_ARGS
                        specify extra arguments to pass to scp only (e.g. -l)
  --sftp-extra-args=SFTP_EXTRA_ARGS
                        specify extra arguments to pass to sftp only (e.g. -f,
                        -l)
  --ssh-common-args=SSH_COMMON_ARGS
                        specify common arguments to pass to sftp/scp/ssh (e.g.
                        ProxyCommand)
  --ssh-extra-args=SSH_EXTRA_ARGS
                        specify extra arguments to pass to ssh only (e.g. -R)
  -S, --su              run operations with su (deprecated, use become)
  -R SU_USER, --su-user=SU_USER
                        run operations with su as this user (default=root)
                        (deprecated, use become)
  -s, --sudo            run operations with sudo (nopasswd) (deprecated, use
                        become)
  -U SUDO_USER, --sudo-user=SUDO_USER
                        desired sudo user (default=root) (deprecated, use
                        become)
  --syntax-check        perform a syntax check on the playbook, but do not
                        execute it
  -T TIMEOUT, --timeout=TIMEOUT
                        override the connection timeout in seconds
                        (default=10)
  -t TREE, --tree=TREE  log output to this directory
  -u REMOTE_USER, --user=REMOTE_USER
                        connect as this user (default=None)
  --vault-password-file=VAULT_PASSWORD_FILE
                        vault password file
  -v, --verbose         verbose mode (-vvv for more, -vvvv to enable
                        connection debugging)
  --version             show program's version number and exit
ERROR! Missing target hosts

インストールされた時点で/etc/ansible/hostsがあるのを確認し、じゃあlocalhostにpingモジュールでも使ってみるかと実行してみる。

# ansible localhost -m ping -vvv
Using /etc/ansible/ansible.cfg as config file
ERROR! Unexpected Exception: [Errno 38] Function not implemented
the full traceback was:

Traceback (most recent call last):
  File "/usr/bin/ansible", line 86, in <module>
    sys.exit(cli.run())
  File "/usr/lib/pymodules/python2.7/ansible/cli/adhoc.py", line 181, in run
    run_tree=run_tree,
  File "/usr/lib/pymodules/python2.7/ansible/executor/task_queue_manager.py", line 92, in __init__
    self._final_q = multiprocessing.Queue()
  File "/usr/lib/python2.7/multiprocessing/__init__.py", line 218, in Queue
    return Queue(maxsize)
  File "/usr/lib/python2.7/multiprocessing/queues.py", line 63, in __init__
    self._rlock = Lock()
  File "/usr/lib/python2.7/multiprocessing/synchronize.py", line 147, in __init__
    SemLock.__init__(self, SEMAPHORE, 1, 1)
  File "/usr/lib/python2.7/multiprocessing/synchronize.py", line 75, in __init__
    sl = self._semlock = _multiprocessing.SemLock(kind, value, maxvalue)
OSError: [Errno 38] Function not implemented

結局さっきと同じエラーで引っかかる、と。
ちょっと/usr/lib/pymodules/python2.7/ansible/executor/task_queue_manager.pyを触ってみたが、これは私の能力では解決できず。

というところで終了。
まあこのmultiprocessingが動くようになれば動くんじゃないかという感触。

メモ

(2016-04-28)
Build 14332時点でもまだPPAでインストールできるバージョンは動いていない。
https://github.com/Microsoft/BashOnWindows/issues/135 がcloseになるかfixedラベルが貼られた時点でこの問題は解決するはずだ。

fixinboundラベルって何だろ?
Canary Ringにはもう修正が入っているという解釈だとラベルを貼られているissueの数が多すぎるように思えるので、修正することが決定した、程度だろうか。

Ansible 1.8.4をインストールしてみた→動いた

その後、 https://groups.google.com/forum/#!topic/ansible-project/3XQVBKkwfGE を見るとAnsible 1.5.4が動作するとの情報が。

ならばどこまで動くか確認する。
結果として1.8.4なら行けそうという結論に。

# apt update
# apt install git python-dev python-pip
# pip install paramiko PyYAML Jinja2 httplib2 six pywinrm
# git clone git://github.com/ansible/ansible.git --recursive
# cd ansible
# git checkout v1.8.4
# git submodule update --init --recursive
# source hacking/env-setup

あと、以下の内容でansible.cfgを作る必要がある。

ansible.cfg
[ssh_connection]
ssh_args =

これで今のところLinux環境の1.8.4と変わりなく使えるように見える。
(ただし、SSHはパスワード認証ではだめで、鍵認証にしないとならないようだ。Bash on Ubuntu on Windowsでssh-keygenもssh-copy-idも使えるので特に問題ないが)
自分自身のWindows側を対象にWindows系モジュールも使えている(1.8.4なのでできることは少ないが)。

他にBash on Ubuntu on Windowsで試してできなかったこと

正式版の時点でできるようになってくれると嬉しいのだが。

  • sshサービスが起動するか試すが上がらない。initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: No such file or directoryなんてメッセージが出る。upstart使うのは全部だめっぽい。
  • それではと別のSSHサーバとしてdropbearをインストールしてみた。これはupstartを使わずSysVinitで完結するサービスで起動はエラーにならなかったが22/tcpでListenされなかった。ポートでListenする類もだめっぽい。(2016-04-11追記:Listenはできている人もいるようなのでまた別の要因だろうか)
  • 聞いていた通りだが/proc使うものは多分全部だめっぽい。
  • ping(Ansibleのモジュールではなく普通のコマンドね)もエラーになる。ping: icmp open socket: Socket type not supportedだそうだ。
11
11
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11