2015-12-17 12 views
9

サブネットにあるWindowsホストをLinuxジャンプホストでのみプロビジョニングしたい。Linuxジャンプサーバーの背後にあるWindowsホストに接続する方法

Windowsマシンはwinrm接続方法を使用します。 LinuxジャンプサーバーはSSH経由で利用できます。

で直接利用できる場合、私はWindowsホストへのアクセス問題がない:

ansible_connection: winrm 

私はLinuxのジャンプサーバにタスクを委任しようとした場合で(つまりは、Windowsへの直接アクセスを持っている):

- name: Ping windows 
    hosts: windows_machines 
    tasks: 
    - name: ping 
     win_ping: 
     delegate_to: "{{ item }}" 
     with_items: "{{ groups['jump_servers'][0] }}" 

ジャンプホストへのWINRM接続を確立するために接続しようとします。正確に私が心に持っていたものではありません。

ansible_port: 5986 
ansible_connection: winrm 
ansible_winrm_server_cert_validation: ignore 

どうすべきI支給Windowsホスト要塞ホストを経由して:windows_machinesグループのために、私は定義されたgroup_varsを持っていることを

注意?

答えて

4

私の優先事項はすべての構成を1か所に持たせ、Anitoryの一部を砦/ジャンプホストに配らないことでした。私は5986ポート用のsshトンネルを確立するために行った。

[windows] 
windows1 ansible_host=127.0.0.1 ansible_ssh_user=Administrator actual_host=192.168.0.2 (...) 

Ansibleは、ローカルホスト上の5986ポートにアクセスすることにより接続することができますので、ansible_hostがなければならない:私は少しインベントリファイルを変更する必要がありました、これが機能するために

- name: Tunneled configuration of Windows host in a subnet 
    hosts: windows 
    connection: local #This is the trick to connect to localhost not actual host 
    gather_facts: no 
    tasks: 
    - name: First setup a tunnel 
     local_action: command ssh -Nf -4 -o ControlPersist=1m -o ControlMaster=auto -o ControlPath="~/.ssh/mux2win-%[email protected]%h:%p" -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o UserKnownHostsFile="/dev/null" -i {{ hostvars[item].ansible_ssh_private_key_file }} {{ hostvars[item].ansible_ssh_user }}@{{ hostvars[item].ansible_host }} -L {{ ansible_port }}:{{ actual_host }}:{{ ansible_port }} 
     with_items: 
     - "{{ groups['jump_servers'][0] }}" #I know my topology so I know which host to use 
    - name: (optional) Second ensure it is up 
     local_action: command ssh -O check -S "~/.ssh/mux2win-%[email protected]%h:%p" {{ hostvars[item].ansible_ssh_user }}@{{ hostvars[item].ansible_host }} 
     with_items: 
     - "{{ groups['jump_servers'][0] }}" 

    # ------- actual windows tasks (from ansible examples) ------------ 
    - name: Ping 
     connection: local 
     win_ping: 
    - name: test raw module- run ipconfig 
     raw: ipconfig 
     register: ipconfig 
    - debug: var=ipconfig 

    - name: Test stat module- test stat module on file 
     win_stat: path="C:/Windows/win.ini" 
     register: stat_file 

    - debug: var=stat_file 

    - name: Check stat_file result 
     assert: 
      that: 
      - "stat_file.stat.exists" 
      - "not stat_file.stat.isdir" 
      - "stat_file.stat.size > 0" 
      - "stat_file.stat.md5" 
    # ------- end of actual windows tasks ------------ 

    - name: Stop the tunnel. It would stop anyway after 1m. 
     local_action: command ssh -O stop -S "~/.ssh/mux2win-%[email protected]%h:%p" {{ hostvars[item].ansible_ssh_user }}@{{ hostvars[item].ansible_host }} 
     with_items: 
     - "{{ groups['jump_servers'][0] }}" 

:ここ は完全な作業です127.0.0.1に設定し、Windowsマシンの実際のIPに関する情報をカスタム変数actual_hostに設定する必要があります。

3

タスク上のdelegate_toオプションはそうではありません。

代わりに、delegate_toは、ロール/プレイブックにリストされているグループではなく、特定のノードに対してのみタスクが実行されるようにします。

たとえば、一般的に定義されているボックスのクラスタにMySQLを設定する役割がありますが、マスターだけで特定の設定やタスクを実行したい場合は、マスターがスレーブにレプリケートするようにします。

SSH proxyingあなたは砦/ジャンプホスト経由でSSH接続を転送することができますが、明らかにSSHで接続する必要があります。

私がここでお手伝いすることができるのは、保護されていないゾーンの外でマシンからAnatile(または実際には何か)によってトリガされた要塞/ジャンプホストから直接Anoysを使用することだけです。

関連する問題