-
Notifications
You must be signed in to change notification settings - Fork 770
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[ansible][docker.py]Replace docker shell with connection plugin #1269
[ansible][docker.py]Replace docker shell with connection plugin #1269
Conversation
i think this is a more generic approach. @qiluo-msft , what do you think? |
@msosyak , can you add the docker-ce-cli installation in the sonic-mgmt docker so that we will have docker command in the sonic-mgmt docker. https://github.com/Azure/sonic-buildimage/blob/master/dockers/docker-sonic-mgmt/Dockerfile.j2 |
@msosyak, can you resolve the conflict? |
164acae
to
a8b139b
Compare
a8b139b
to
a327d81
Compare
@lguohan Conflict resolved. |
In the scope of migration from docker shell plugin to docker connection plugin, we need to have docker-ce-cli installed in docker-sonic-mgmt. sonic-net/sonic-mgmt#1269 Added docker-ce-cli package to docker-sonic-mgmt.
authorized_key: | ||
user: "{{ ansible_ssh_user }}" | ||
state: present | ||
key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key [](start = 4, length = 3)
You can get key
from previous openssh_keypair
return values. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your refinement! I feel public_key
is just more straightforward.
In reply to: 356376796 [](ancestors = 356376796)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not choose the name of the public key file.
"Name of the files containing the public and private key. The file containing the public key will have the extension .pub. "
https://docs.ansible.com/ansible/latest/modules/openssh_keypair_module.html#parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe there is some miscommunication. I suggest
key: out.public_key
Could you help explorer this one? Seems it is designed just for this purpose.
In reply to: 356776386 [](ancestors = 356776386,356376796)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, yes, I missed this option. Changed.
with_items: | ||
- "lldp" | ||
- "syncd" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this part into add_container_to_inventory, add with_items for all containers? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we can, but I do not see the reason for that. There are only two places where we add more than one container.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean if we move every include_task: add_container_to_inventory
into inside that file with all the known container names, we can keep other files clean, only include_tasks once.
In reply to: 356377776 [](ancestors = 356377776)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not use it in all test cases, so I do not see the reason to implicitly add all containers to inventory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One remaining minor issue: #1269 (review). Otherwise it looks good to me.
In the scope of migration from docker shell plugin to docker connection plugin, we need to have docker-ce-cli installed in docker-sonic-mgmt. sonic-net/sonic-mgmt#1269 Added docker-ce-cli package to docker-sonic-mgmt.
…-net#3868) In the scope of migration from docker shell plugin to docker connection plugin, we need to have docker-ce-cli installed in docker-sonic-mgmt. sonic-net/sonic-mgmt#1269 Added docker-ce-cli package to docker-sonic-mgmt.
Description of PR
We are using a custom docker shell plugin to run tasks inside the container on the remote hosts. But shell plugins ware not made for this purpose. So I would recommend deprecate docker shell plugin and use native docker connection plugin.
To be able to use docker connection plugin to run tasks inside containers on the remote host we just should to:
Summary:
Replace docker shell plugin by native ansible docker connection plugin.
Fixes #1268
Type of change
Approach
Dynamically add needed containers to inventory and use delegate_to to run tasks inside containers.
How did you do it?
How did you verify/test it?
Any platform specific information?
Supported testbed topology if it's a new test case?
Documentation
There are some articles found during the investigation:
https://medium.com/better-programming/docker-tips-access-the-docker-daemon-via-ssh-97cd6b44a53
https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#non-ssh-connection-types
https://www.serverlab.ca/tutorials/containers/docker/how-to-access-remote-docker-daemon-using-ssh/
https://docs.ansible.com/ansible/latest/modules/authorized_key_module.html