【发布时间】:2022-01-12 15:08:48
【问题描述】:
所以我创建了这个 Ansible 剧本来:
- 复制一个 zip 文件并解压
- 复制一个 zip 文件并解压
- 使文件内的脚本可执行
- 运行脚本
- 启用 2 项服务
- name: fideliplaybook
hosts: k8scluster
tasks:
- name: copying file with playbook
become: true
copy:
src: /home/lc/lc.zip
dest: /home/lc/
mode: 755
- name: Update apt cache and install unzip
become: true
command: apt install unzip
- name: unzip file
become: true
unarchive:
src: /home/lc/lc.zip
dest: /home/lc/
- name: make script executable
become: true
file: dest=/home/lc/lc/install.sh mode=755
- name: Execute the script
become: true
command: sh /home/lc/lc/install.sh
- name: Enable service 1
become: true
command: systemctl enable service1.service
- name: Enable service 2
become: true
command: systemctl enable service1.service
我在这里面临的问题是,当 ansible 试图执行脚本“install.sh”时 它以某种方式失败,因为脚本无法找到其他 2 个脚本,尽管其他脚本在同一个文件中。
所以 lc.zip 中有 3 个脚本,但是当使用 ansible 运行 install.sh 时,它找不到其他 2 个脚本。 我通过在第一个脚本中输入 2 个脚本的完整路径来解决此问题。 但任何人都知道为什么会出现这个问题。
当我使用 ansible hosts 文件来定义主机和变量时,还有一个问题,它不能像这样与 INI 一起使用:
[webservers]
www[01:50].example.com
它只在 YAML 中工作:
...
webservers:
hosts:
www[01:50].example.com:
有人知道为什么吗?
【问题讨论】:
标签: ansible