commit 2fc0f08eb7878bbd5012797801a0d25d39e21d24 Author: Markus Katharina Brechtel Date: Mon Jan 4 03:07:33 2021 +0100 working playbook for ssh host and container setup diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bee8a64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..d00b4ca --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "connection_plugins/lxc_ssh"] + path = connection_plugins/lxc_ssh + url = https://github.com/andreasscherbaum/ansible-lxc-ssh.git diff --git a/connection_plugins/lxc_ssh b/connection_plugins/lxc_ssh new file mode 160000 index 0000000..d08e694 --- /dev/null +++ b/connection_plugins/lxc_ssh @@ -0,0 +1 @@ +Subproject commit d08e694c16a2d0f71a2883f4c0e8590eb5c743b5 diff --git a/connection_plugins/lxc_ssh.py b/connection_plugins/lxc_ssh.py new file mode 120000 index 0000000..fb66128 --- /dev/null +++ b/connection_plugins/lxc_ssh.py @@ -0,0 +1 @@ +lxc_ssh/lxc_ssh.py \ No newline at end of file diff --git a/containers.yaml b/containers.yaml new file mode 100644 index 0000000..9d17bb6 --- /dev/null +++ b/containers.yaml @@ -0,0 +1,58 @@ +--- + +- hosts: lxd_containers + remote_user: root + gather_facts: false + vars: + lxd_source: + type: image + mode: pull + server: https://images.linuxcontainers.org + protocol: lxd + alias: debian/buster/amd64 + tasks: + - name: lxd container installed and started + community.general.lxd_container: + name: "{{inventory_hostname}}" + state: started + source: "{{lxd_source}}" + profiles: ["default"] + wait_for_ipv4_addresses: true + timeout: 600 + delegate_to: "{{ lxd_host }}" + - name: install python3 in lxd container + command: lxc exec {{inventory_hostname}} -- apt-get -y install python3 + delegate_to: "{{ lxd_host }}" + +- hosts: lxd_containers + remote_user: root + connection: lxc_ssh + gather_facts: false + vars: + ansible_host: "{{lxd_host}}" + ansible_ssh_extra_args: "{{inventory_hostname}}" + ssh_ip: "{{ansible_default_ipv6.address}}" + tasks: + - setup: + - name: openssh server + apt: + pkg: openssh-server + - name: make sure host_vars directory is present for host + local_action: file + args: + path: "{{inventory_dir}}/host_vars/{{inventory_hostname}}" + state: directory + - name: record lxd containers IPv6 address for connection in host_vars + local_action: copy + args: + content: + ansible_host: "{{ssh_ip}}" + ssh_ip: "{{ssh_ip}}" + dest: "{{inventory_dir}}/host_vars/{{inventory_hostname}}/lxd_host.auto.json" + - import_role: + name: root_user + - import_role: + name: ssh_host_key + +- hosts: lxd_containers + remote_user: root diff --git a/hosts.yaml b/hosts.yaml new file mode 100644 index 0000000..7c62c0b --- /dev/null +++ b/hosts.yaml @@ -0,0 +1,6 @@ +--- + +- hosts: lxd_hosts + remote_user: root + roles: + - name: lxd