Skip to content
This repository has been archived by the owner on Mar 2, 2022. It is now read-only.

Commit

Permalink
Доработки:
Browse files Browse the repository at this point in the history
- docker-machine мастером может быть удаленный хост (в оригинале только локалхост)
- исправлены баги
- в Pre-generate client certificate не увидел необходимости - закомментировал
  • Loading branch information
ujhgj committed Dec 24, 2018
1 parent 1106db4 commit 9cc2468
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
docker_machine_master: 127.0.0.1
docker_machine_executable: docker-machine
docker_machine_create: false
docker_machine_remove: false
docker_machine_manage_config: false
Expand Down
4 changes: 2 additions & 2 deletions tasks/docker_machine_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- block: # Check and install Docker Machine
- name: Get version of Docker Machine
shell: docker-machine version | awk '{print substr($3, 1, length($3)-1)}'
delegate_to: 127.0.0.1
delegate_to: "{{ docker_machine_master }}"
register: docker_machine_version

# TODO Find the way to check version and better way to install docker machine
Expand All @@ -12,7 +12,7 @@
# dest: "{{ docker_machine_install_path }}"
# mode: 0755
# force: yes
# delegate_to: 127.0.0.1
# delegate_to: "{{ docker_machine_master }}"
# become: true
# when: docker_machine_version.stdout <= docker_machine_install_version

Expand Down
47 changes: 25 additions & 22 deletions tasks/docker_machine_create.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
---
- block: # Pre-generate client certificate

- name: Check if client certificate exists
stat:
path: "{{ docker_machine_client_certificate_file }}"
run_once: true
register: docker_machine_client_certificate_check

- name: Generate client certificate
shell: |
docker-machine create --driver none --url http://not-exist delete-me;
docker-machine rm -f delete-me
delegate_to: 127.0.0.1
run_once: true
when: not docker_machine_client_certificate_check.stat.exists
#- block: # Pre-generate client certificate
#
# - name: Check if client certificate exists
# stat:
# path: "{{ docker_machine_client_certificate_file }}"
# run_once: true
# register: docker_machine_client_certificate_check
#
# - name: Generate client certificate
# shell: |
# docker-machine create --driver none --url http://not-exist delete-me;
# docker-machine rm -f delete-me
# delegate_to: 127.0.0.1
# run_once: true
# when: not docker_machine_client_certificate_check.stat.exists


- block: # Create Docker Machine

- name: Remove Docker Machine
command: docker-machine rm -f {{ inventory_hostname }}
delegate_to: 127.0.0.1
command: "{{ docker_machine_executable }} rm -f {{ inventory_hostname }} --storage-path {{ docker_machine_storage_path }}"
delegate_to: "{{ docker_machine_master }}"
when: docker_machine_host_check.stat.exists and docker_machine_remove

# can't use ansible_host if it is not set explicitly because of 'delegate_to'
# see https://github.com/ansible/ansible/issues/14958
- debug: msg={{ lookup('dig', inventory_hostname) }}
delegate_to: "{{ docker_machine_master }}"
- name: Create Docker Machine
command: |
docker-machine create --driver generic
--generic-ssh-user {{ ansible_user }}
--generic-ip-address {{ ansible_host }}
--generic-ssh-port {{ ansible_port }}
{{ docker_machine_executable }} create --driver generic
--generic-ssh-user root
--generic-ip-address {{ lookup('dig', inventory_hostname) }}
{{ docker_machine_extra_parameters|default('') }}
{{ inventory_hostname }}
delegate_to: 127.0.0.1
delegate_to: "{{ docker_machine_master }}"
when: not docker_machine_host_check.stat.exists or docker_machine_remove

tags:
Expand Down
2 changes: 2 additions & 0 deletions tasks/docker_machine_manage_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- name: Check if machine exists
stat:
path: "{{ docker_machine_config_file }}"
delegate_to: "{{ docker_machine_master }}"
register: docker_machine_host_check

- name: Search and replace Docker Machine configuration file
Expand All @@ -12,6 +13,7 @@
replace: "{{ item.replace }}"
with_items: "{{ docker_machine_config_variables }}"
when: docker_machine_host_check.stat.exists == true
delegate_to: "{{ docker_machine_master }}"

tags:
- docker-machine-manage-config

0 comments on commit 9cc2468

Please sign in to comment.