You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ---
  2. - hosts: lxd_containers
  3. remote_user: root
  4. gather_facts: false
  5. vars:
  6. lxd_container_source:
  7. type: image
  8. mode: pull
  9. server: https://images.linuxcontainers.org
  10. protocol: lxd
  11. alias: debian/buster/amd64
  12. tasks:
  13. - name: lxd container installed and started
  14. community.general.lxd_container:
  15. name: "{{inventory_hostname}}"
  16. state: started
  17. source: "{{lxd_container_source}}"
  18. config: "{{lxd_container_config}}"
  19. profiles: ["default"]
  20. wait_for_ipv4_addresses: true
  21. timeout: 600
  22. delegate_to: "{{ lxd_host }}"
  23. - name: install python3 in lxd container
  24. command: lxc exec {{inventory_hostname}} -- apt-get -y install python3
  25. delegate_to: "{{ lxd_host }}"
  26. - hosts: lxd_containers
  27. remote_user: root
  28. connection: lxc_ssh
  29. gather_facts: false
  30. vars:
  31. ansible_host: "{{lxd_host}}"
  32. ansible_ssh_extra_args: "{{inventory_hostname}}"
  33. ssh_ip: "{{ansible_default_ipv6.address}}"
  34. tasks:
  35. - setup:
  36. - name: openssh server
  37. apt:
  38. pkg: openssh-server
  39. - name: make sure host_vars directory is present for host
  40. local_action: file
  41. args:
  42. path: "{{inventory_dir}}/host_vars/{{inventory_hostname}}"
  43. state: directory
  44. - name: record lxd containers IPv6 address for connection in host_vars
  45. local_action: copy
  46. args:
  47. content:
  48. ansible_host: "{{ssh_ip}}"
  49. ssh_ip: "{{ssh_ip}}"
  50. external_ip: "{{ssh_ip}}"
  51. dest: "{{inventory_dir}}/host_vars/{{inventory_hostname}}/lxd_host.auto.json"
  52. - import_role:
  53. name: root_user
  54. - import_role:
  55. name: ssh_host_key
  56. - hosts: lxd_containers
  57. remote_user: root