» git clone https://github.com/vkozlovski/ansible-cloud-hosting » cd ansible-cloud-hosting » git checkout v2.x
[dc1-cloud] 192.168.1.1 192.168.1.2 192.168.1.3
[dc1-cloud] 192.168.1.1 192.168.1.2 192.168.1.3 [dc2-cloud] 192.168.2.1 192.168.2.2 192.168.2.3 #--- in all DC ---# # cloud in all DC [cloud:children] dc1-cloud dc2-cloud #--- everything in DC ---# [dc1:children] dc1-cloud [dc2:children] dc2-cloud
» make gen-ca
Generating RSA private key, 4096 bit long modulus ...++ ................++ e is 65537 (0x10001) Enter pass phrase for certs/ca/ca-key.pem: Verifying - Enter pass phrase for certs/ca/ca-key.pem: Enter pass phrase for certs/ca/ca-key.pem: You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:US State or Province Name (full name) [Some-State]:California Locality Name (eg, city) []:Cupertino Organization Name (eg, company) [Internet Widgits Pty Ltd]:Ansible Cloud Hosting Organizational Unit Name (eg, section) []: Common Name (eg server FQDN or YOUR name) []:example.com Email Address []:postmaster@example.com
--- common_packages: - sudo - htop - mc - git - apt-transport-https - python-setuptools # easy_install (necessary for install python pip) debian_release: jessie certs_ca_password: '1234' # ;)
» make gen-consul-certs
Generating a 2048 bit RSA private key ..........................+++ .................................................+++ writing new private key to 'privkey.pem' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:US State or Province Name (full name) [Some-State]:California Locality Name (eg, city) []:Cupertino Organization Name (eg, company) [Internet Widgits Pty Ltd]:Ansible Cloud Hosting Organizational Unit Name (eg, section) []: Common Name (eg server FQDN or YOUR name) []:example.com Email Address []:postmaster@example.com Generating a 1024 bit RSA private key ...........................++++++ ..............++++++ writing new private key to 'consul.key' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:US State or Province Name (full name) [Some-State]:California Locality Name (eg, city) []:Cupertino Organization Name (eg, company) [Internet Widgits Pty Ltd]:Ansible Cloud Hosting Organizational Unit Name (eg, section) []: Common Name (eg server FQDN or YOUR name) []:example.com Email Address []:postmaster@example.com Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: Using configuration from myca.conf Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows countryName :PRINTABLE:'US' stateOrProvinceName :PRINTABLE:'California' localityName :PRINTABLE:'Cupertino' organizationName :PRINTABLE:'Ansible Cloud Hosting' commonName :PRINTABLE:'example.com' emailAddress :IA5STRING:'postmaster@example.com' Certificate is to be certified until Nov 22 16:25:08 2025 GMT (3650 days) Write out database with 1 new entries Data Base Updated ------------------------------------------------------------
» docker run --rm --entrypoint "/bin/consul" progrium/consul:latest keygen L+3UkrkFeXHQBT97nTZI/g==
--- # docker docker_api_version: 1.18 docker_key_server: "hkp://pgp.mit.edu:80" docker_key_id: "58118E89F3A912897C070ADBF76221572C52609D" # docker-consul docker_consul_encrypt: 'L+3UkrkFeXHQBT97nTZI/g==' docker_consul_start_join_wan: - "{{ hostvars[groups['dc1'][0]]['ansible_eth0']['ipv4']['address'] }}" # first host in DC1
--- # docker-consul # first host in "my_name_dc" DC docker_consul_join: '{{ hostvars[groups["my_name_dc"][0]]["ansible_eth0"]["ipv4"]["address"] }}' docker_consul_dc: 'dc1' # docker-swarm-manager # first host in "my_name_dc" DC docker_swarm_manager_ip: '{{ hostvars[groups["my_name_dc"][0]]["ansible_eth0"]["ipv4"]["address"] }}'
--- # docker docker_api_version: 1.18 docker_key_server: "hkp://pgp.mit.edu:80" docker_key_id: "58118E89F3A912897C070ADBF76221572C52609D" # docker-consul docker_consul_encrypt: 'L+3UkrkFeXHQBT97nTZI/g==' docker_consul_start_join_wan: - "{{ hostvars[groups['dc1'][0]]['ansible_eth0']['ipv4']['address'] }}" # first host in DC1 - "{{ hostvars[groups['dc2'][0]]['ansible_eth0']['ipv4']['address'] }}" # first host in DC2 ...
» make run
[dc1-cloud] 192.168.1.1 192.168.1.2 192.168.1.3 [dc2-cloud] 192.168.2.1 192.168.2.2 192.168.2.3 #--- in all DC ---# # cloud in all DC [cloud:children] dc1-cloud dc2-cloud #--- everything in DC ---# [dc1:children] dc1-cloud [dc2:children] dc2-cloud
» docker -H tcp://192.168.1.1:8000 --tlsverify=true --tlscacert=certs/ca/ca.pem --tlscert=certs/docker/cert.pem --tlskey=certs/docker/key.pem info
Containers: 13 Images: 12 Role: primary Strategy: spread Filters: health, port, dependency, affinity, constraint Nodes: 3 debian1: 192.168.1.1:2376 └ Containers: 5 └ Reserved CPUs: 0 / 1 └ Reserved Memory: 0 B / 519.2 MiB └ Labels: executiondriver=native-0.2, kernelversion=3.16.0-4-amd64, operatingsystem=Debian GNU/Linux 8 (jessie), storagedriver=aufs debian2: 192.168.1.2:2376 └ Containers: 4 └ Reserved CPUs: 0 / 1 └ Reserved Memory: 0 B / 519.2 MiB └ Labels: executiondriver=native-0.2, kernelversion=3.16.0-4-amd64, operatingsystem=Debian GNU/Linux 8 (jessie), storagedriver=aufs debian3: 192.168.1.3:2376 └ Containers: 4 └ Reserved CPUs: 0 / 1 └ Reserved Memory: 0 B / 519.2 MiB └ Labels: executiondriver=native-0.2, kernelversion=3.16.0-4-amd64, operatingsystem=Debian GNU/Linux 8 (jessie), storagedriver=aufs CPUs: 3 Total Memory: 1.521 GiB Name: debian1
» docker -H tcp://178.62.232.38:8000 --tlsverify=true --tlscacert=certs/ca/ca.pem --tlscert=certs/docker/cert.pem --tlskey=certs/docker/key.pem run -d -p 80:80 -p 443:443 -e "SERVICE_80_NAME=http" -e "SERVICE_443_NAME=https" nginx
» docker -H tcp://192.168.1.1:8000 --tlsverify=true --tlscacert=certs/ca/ca.pem --tlscert=certs/docker/cert.pem --tlskey=certs/docker/key.pem ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e96b351a857e nginx "nginx -g 'daemon off" 3 minutes ago Up 3 minutes 192.168.1.2:80->80/tcp, 192.168.1.2:443->443/tcp debian2/fervent_dubinsky ...
» docker -H tcp://192.168.1.1:8000 --tlsverify=true --tlscacert=certs/ca/ca.pem --tlscert=certs/docker/cert.pem --tlskey=certs/docker/key.pem run -ti debian:testing /bin/bash root@2e68749354b2:/#
root@2e68749354b2:/# ping http PING http.service.consul (172.17.0.6): 56 data bytes 64 bytes from 172.17.0.6: icmp_seq=0 ttl=64 time=0.076 ms 64 bytes from 172.17.0.6: icmp_seq=1 ttl=64 time=0.118 ms 64 bytes from 172.17.0.6: icmp_seq=2 ttl=64 time=0.075 ms ^C--- http.service.consul ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max/stddev = 0.075/0.090/0.118/0.000 ms
» docker -H tcp://178.62.232.38:8000 --tlsverify=true --tlscacert=certs/ca/ca.pem --tlscert=certs/docker/cert.pem --tlskey=certs/docker/key.pem run -d -p 80:80 -p 443:443 -e "SERVICE_80_NAME=http" -e "SERVICE_443_NAME=https" nginx
Error response from daemon: unable to find a node with port 443 available
root@2e68749354b2:/# apt-get update && apt-get install dnsutils --no-install-recommends
root@866f410a5f18:/# dig http.service.dc1.consul. ANY ; <<>> DiG 9.9.5-12+b1-Debian <<>> http.service.dc1.consul. ANY ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17731 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;http.service.dc1.consul. IN ANY ;; ANSWER SECTION: http.service.dc1.consul. 0 IN A 192.168.1.1 http.service.dc1.consul. 0 IN A 192.168.1.2 http.service.dc1.consul. 0 IN A 192.168.1.3 ;; Query time: 4 msec ;; SERVER: 172.17.0.1#53(172.17.0.1) ;; WHEN: Thu Nov 26 10:22:41 UTC 2015 ;; MSG SIZE rcvd: 158
Source: https://habr.com/ru/post/264269/
All Articles