Browse Source

working playbook for ssh host and container setup

master
commit
2fc0f08eb7
6 changed files with 70 additions and 0 deletions
  1. +1
    -0
      .gitignore
  2. +3
    -0
      .gitmodules
  3. +1
    -0
      connection_plugins/lxc_ssh
  4. +1
    -0
      connection_plugins/lxc_ssh.py
  5. +58
    -0
      containers.yaml
  6. +6
    -0
      hosts.yaml

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
__pycache__

+ 3
- 0
.gitmodules View File

@@ -0,0 +1,3 @@
[submodule "connection_plugins/lxc_ssh"]
path = connection_plugins/lxc_ssh
url = https://github.com/andreasscherbaum/ansible-lxc-ssh.git

+ 1
- 0
connection_plugins/lxc_ssh

@@ -0,0 +1 @@
Subproject commit d08e694c16a2d0f71a2883f4c0e8590eb5c743b5

+ 1
- 0
connection_plugins/lxc_ssh.py View File

@@ -0,0 +1 @@
lxc_ssh/lxc_ssh.py

+ 58
- 0
containers.yaml View File

@@ -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

+ 6
- 0
hosts.yaml View File

@@ -0,0 +1,6 @@
---

- hosts: lxd_hosts
remote_user: root
roles:
- name: lxd

Loading…
Cancel
Save