我为 LXD 设置了 ansible 和不同的服务器。有谁能给我提供一个插件,用于通过 ansible 在 LXD 容器内执行操作,例如安装 nginx 或删除默认 ubuntu 用户。
Lxd 版本:4(ubuntu 20.04 LTS) Ansible 版本:5(ansible-core 2.12)--> ubuntu 20.04 LTS
我的任务>main.yml 看起来像这样。
- name: dynamic-site-host
add_host:
name: "{{ item.container_name }}-host"
ansible_host: "{{ ansible_host }}"
#ansible_connection: lxd
ansible_ssh_extra_args: "{{ item.container_name }}"
ansible_ssh_user: root
ansible_python_interpreter: /usr/bin/python3
with_items: "{{ container_params }}"
- name: set-dynamic-site-host-name
delegate_to: "{{ item.container_name }}-host"
set_fact:
site_host_name: "{{ item.container_name }}-host"
with_items: "{{ container_params }}"
- name: set-site-vars-dynamically
delegate_to: "{{ site_host_name }}"
set_fact:
site_params: "{{ item }}"
with_items: "{{ container_params }}"
- name: Remove the user 'ubuntu'
delegate_to: "{{ site_host_name }}"
user:
name: ubuntu
state: absent
remove: yes
ansible.cfg
[defaults]
inventory= ./hosts
#connection_plugins = ./plugins/lxc_ssh/
ansible_host_key_checking= false
host file
[default]
hosting ansible_host=138.xxx.xxx.xx ansible_ssh_user=root
答案1
你可以像在普通主机上一样在 LXD 容器中运行任务ssh
,也可以使用LXC容器ansible模块