Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSH key not added to created VM when ssh_key parameter is set #1734

Open
TheSpy0 opened this issue Sep 30, 2024 · 5 comments · May be fixed by #1736
Open

SSH key not added to created VM when ssh_key parameter is set #1734

TheSpy0 opened this issue Sep 30, 2024 · 5 comments · May be fixed by #1736
Labels
bug Something isn't working has_pr PR fixes have been made medium_priority Medium priority work in In trying to solve, or in working with contributors

Comments

@TheSpy0
Copy link

TheSpy0 commented Sep 30, 2024

SUMMARY

When creating a virtual machine inside a DevTest Lab, an SSH public key is not added to the authorized_keys file when the ssh_key parameter is set using either a path to the public key, the contents of the key (have tried as a string and using a file lookup), or the name of an SSH key stored in Azure. The module documentation was not clear on how it is supposed to be set.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

azure_rm_devtestlabvirtualmachine module

ANSIBLE VERSION
ansible [core 2.16.4]
  config file = None
  configured module search path = ['/home/the-spy/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/the-spy/.local/lib/python3.12/site-packages/ansible
  ansible collection location = /home/the-spy/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/the-spy/.local/bin/ansible
  python version = 3.12.5 (main, Aug  7 2024, 00:00:00) [GCC 13.3.1 20240522 (Red Hat 13.3.1-1)] (/usr/bin/python3)
  jinja version = 3.1.3
  libyaml = True
COLLECTION VERSION
Collection         Version
------------------ -------
azure.azcollection 2.7.0 
CONFIGURATION
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/nano
OS / ENVIRONMENT

Fedora release 39 (Thirty Nine)

STEPS TO REPRODUCE

Run a playbook with the task below defined, using either the contents of the SSH key, or a lookup plugin with the file path to the key.

# Only including the specific task here. Will post entire whole playbook if necessary.
- name: Create a VM within the lab
      azure.azcollection.azure_rm_devtestlabvirtualmachine:
        name: "{{ vm_name }}"
        lab_name: "{{ lab_name }}"
        resource_group: "{{ resource_group_name }}"
        notes: Virtual machine notes
        os_type: linux
        vm_size: Standard_A2_v2
        user_name: dtladmin
        password: Th!s1saP@ssw0rd
        ssh_key: "contents of ssh key" # Also tried "{{ lookup('file', '/path/to/pub/key.pub') }}"
        lab_subnet:
          virtual_network_name: "{{ vn_name }}"
          name: "{{ vn_name }}Subnet"
        disallow_public_ip_address: false
        image:
          offer: RHEL
          publisher: RedHat
          sku: 8-lvm
          os_type: Linux
          version: latest
        allow_claim: false
EXPECTED RESULTS

Expecting there to be a public key in ~/.ssh/authorized_keys file.

ACTUAL RESULTS

The ~/.ssh/authorized_keys file is present but empty.

[dtladmin@created-vm-name ~]$ cat ~/.ssh/authorized_keys 
[dtladmin@created-vm-name ~]$ 
@TheSpy0 TheSpy0 changed the title SSH key not added to create VM SSH key not added to created VM when ssh_key parameter is set Sep 30, 2024
@Fred-sun Fred-sun added work in In trying to solve, or in working with contributors bug Something isn't working labels Oct 8, 2024
@Fred-sun Fred-sun linked a pull request Oct 8, 2024 that will close this issue
@Fred-sun
Copy link
Collaborator

Fred-sun commented Oct 8, 2024

@TheSpy0 Sorry for the trouble, this is a bug, if you need ssh authorization login, you need to set I(is_authentication_with_ssh_key=True), this parameter has been added in #1736. Thank you!

@Fred-sun Fred-sun added has_pr PR fixes have been made medium_priority Medium priority labels Oct 8, 2024
@Fred-sun
Copy link
Collaborator

Fred-sun commented Oct 8, 2024

sample as:

- name: Create a VM within the lab
      azure.azcollection.azure_rm_devtestlabvirtualmachine:
        name: "{{ vm_name }}"
        lab_name: "{{ lab_name }}"
        resource_group: "{{ resource_group_name }}"
        notes: Virtual machine notes
        os_type: linux
        vm_size: Standard_A2_v2
        user_name: dtladmin
        password: Th!s1saP@ssw0rd
        ssh_key: "contents of ssh key" # Also tried "{{ lookup('file', '/path/to/pub/key.pub') }}"
        lab_subnet:
          virtual_network_name: "{{ vn_name }}"
          name: "{{ vn_name }}Subnet"
        disallow_public_ip_address: false
        is_authentication_with_ssh_key: True
        image:
          offer: RHEL
          publisher: RedHat
          sku: 8-lvm
          os_type: Linux
          version: latest
        allow_claim: false

@TheSpy0
Copy link
Author

TheSpy0 commented Oct 10, 2024

@Fred-sun Thank you. To be able to test this parameter, I just need to clone your repository in the project directory and use the Add-support-is_authentication_with_ssh_key branch, correct?

@Fred-sun
Copy link
Collaborator

Yes! Please!

@TheSpy0
Copy link
Author

TheSpy0 commented Oct 12, 2024

It works for me when using your updated collection.
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has_pr PR fixes have been made medium_priority Medium priority work in In trying to solve, or in working with contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants