瀏覽代碼

working playbook for ssh host and container setup

master
當前提交
2fc0f08eb7
共有 6 個檔案被更改,包括 70 行新增0 行删除
  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 查看文件

@@ -0,0 +1 @@
__pycache__

+ 3
- 0
.gitmodules 查看文件

@@ -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 查看文件

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

+ 58
- 0
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

+ 6
- 0
hosts.yaml 查看文件

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

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

Loading…
取消
儲存