我是新的安息世界。下面是我的ansible playbook,并在为tomcat端口应用模板值之前。我试图根据远程服务器上没有出现tomcat实例来计算端口。
如何在运行shell后使用local_action将值作为变量获取?
-
hosts: "{{Server}}"
tasks:
-
ignore_errors: true
name: "find no of Tomcat Instance available on the Server"
register: Tomcat_Instance_no
shell: "find /example -name tomcat-users.xml -type f -print | wc -l"
- debug: var=Tomcat_Instance_no
#- local_action: copy content="{{ Tomcat_Instance_no.stdout }}" dest="/tmp/{{Server}}_Tomcat_Instance_no"
#- local_action: "shell sh define-tomcat-instance-port.sh {{Server}} {{IName}} {{ Tomcat_Instance_no.stdout }}"
****- local_action: "shell sh http_port=$(( {{ Tomcat_Instance_no.stdout }} * 100 + 8080))"
register: HTPN
- local_action: "shell sh shutdown_port=$(( {{ Tomcat_Instance_no.stdout }} * 100 + 8005))"
register: SHPN
- local_action: "shell sh https_port=$(( {{ Tomcat_Instance_no.stdout }} * 100 + 8043))"
register: SSPN
- local_action: "shell sh ajp_port=$(( {{ Tomcat_Instance_no.stdout }} * 100 + 8009))"
register: AJPN**
#-
#name: bare include
#include_vars: "{{Server}}_{{IName}}.json"
-
ignore_errors: true
name: "find no of Tomcat Instance available on the Server"
copy:
src: "{{ WORKSPACE }}/instance/"
dest: /example/{{IName}}
group: "{{IGID}}"
owner: "{{IUID}}"
mode: 0755
-
name: Deliver configuration files for tomcat
template: src={{ item.src }} dest={{ item.dest }} backup=yes
with_items:
- { src: 'server.xml.j2', dest: '/example/{{IName}}/conf/server.xml' }
- { src: 'set_env.sh.j2', dest: '/example/{{IName}}/scripts/set_env.sh' }
提前致谢
答案 0 :(得分:1)
您需要set_fact:
{% load static %}
{% block stylesheets %}
<link rel="stylesheet" type="text/css" href="{% static "Emu86/style.css"%}">
{% endblock stylesheets %}
我还在- set_fact:
HTPN: "{{ tomcat_no | int * 100 + 8080 }}"
SHPN: "{{ tomcat_no | int * 100 + 8005 }}"
SSPN: "{{ tomcat_no | int * 100 + 8043 }}"
AJPN: "{{ tomcat_no | int * 100 + 8009 }}"
vars:
tomcat_no: "{{ Tomcat_Instance_no.stdout }}"
任务中定义了tomcat_no
别名来减少输入。