以下是我的Ansible-playbook。当我尝试使用带有--tags'install_fc'的ansible-playbook命令执行它时,它会执行所有播放,尽管只希望执行KVM上的安装包play 1。
代码块:
---
- name: install package on KVM
hosts: '{{ host }}'
tags: install_fc
tasks:
- name: expect installation using dnf
command: /usr/bin/dnf install expect -y
- name: install package on Ubuntu KVM
hosts: '{{ host }}'
tags: install_ubu
tasks:
- name: expect installation using apt-get
command: apt-get install expect -y
- name: Download package from build server
hosts: '{{ host }}'
tags: copy_source_code
tasks:
- name: making directory on KVM
command: mkdir -p "/root/Desktop/Sanity/{{ TID }}/{{ Image_dir }}"
- name: copy files remote
shell: |
set timeout 1000
spawn ftp {{ buildIP }}
expect ":"
send "{{ build_user }}\n"
expect "ssword:"
send "{{ build_password }}\n"
expect "ftp>"
send "get {{ build_path }}/{{ build_filename }} /root/Desktop/Sanity/{{ TID }}/{{ Image_dir }}/{{ build_filename }}\n"
expect "ftp>"
send "quit\n"
set multiPrompt {[#$]}
expect -re $multiPrompt
exit 0
args:
executable: /usr/bin/expect
register: shell_output
- debug:
var: shell_output.stdout_lines
- set_fact:
ftp_no_file: |
{{shell_output.stdout_lines |
map('regex_findall','No such file or directory') |
map('join') | list }}
- fail:
msg: "File {{ build_filename }} not found on build server."
when: "'No such file or directory' in ftp_no_file"
- meta: end_play
when: "'No such file or directory' in ftp_no_file"
- name: untarring package
hosts: '{{ host }}'
tags: untar
tasks:
- name: untar the build package
shell: tar -zxvf {{ build_filename }}
args:
chdir: /root/Desktop/Sanity/{{ TID }}/{{ Image_dir }}/
我应该如何运行剧本,以便仅运行install_fc剧本?