AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[template](server)

Martin Hope
Lethargos
Asked: 2021-03-28 10:38:51 +0800 CST

使用 ansible 模板文件以获取不同主机的不同变量部分(通过其索引)

  • 0

我正在尝试将证书分发到其相应的主机(我将仅给出私钥任务的示例):

- name: create certificate private key
  community.crypto.openssl_privatekey:
    path: "/root/client/{{ item }}.key"
    type: Ed25519
    backup: yes
    return_content: yes
  register: privatekey
  loop: "{{ ansible_play_hosts_all }}"
  when: "'prometheus1' in inventory_hostname"

我可以像这样为其他主机调用变量:

{{ hostvars['prometheus1']['privatekey']['results'][0]['privatekey'] }}

索引指向某个键,因此 0 将是第一个主机 ( prometheus1),1 将是第二个主机,依此类推。

我想模板化是要走的路,但我根本不知道如何编写模板。我认为ansible_play_hosts_all是解决方案的关键,因为它的索引对应于私钥的索引,例如: ansible_play_hosts_all[2]-->hostvars['prometheus1']['privatekey']['results'][2]['privatekey']

但逻辑是:

for i in index of ansible_play_hosts_all
add the  hostvars['prometheus1']['privatekey']['results'][i]['privatekey']
if ansible_play_hosts_all[i] in inventory_hostname

我想有这样的效果:) 非常感谢任何帮助。


更新

也许更准确一些:

{% for i in ansible_play_hosts_all|length) %}
{{ hostvars['prometheus1']['privatekey']['results'][i]['privatekey'] }}
{% endfor %}

并在其中添加条件:

{% if ansible_play_hosts_all[i] in inventory_hostname %}
ansible template jinja2
  • 3 个回答
  • 401 Views
Martin Hope
Wipiid
Asked: 2021-02-03 09:51:34 +0800 CST

使用 ansible 模板化 firewalld 区域 - xml 或 vars 问题

  • 0

使用 ansible 模板化 firewalld 区域 - xml 操作问题 我对规则系列有点困惑。

我的CORRECTED vars 文件中有什么内容:

firewalld_zones: 
  - name: public
    short: "Public"
    description: "Public Zone"
    service:
      - { name: ssh }
      - { name: dhcpv6-client }
    port:
      - { protocol: tcp, port: 8000 }
      - { protocol: tcp, port: 8089 }
      - { protocol: udp, port: 52311 }
      - { protocol: udp, port: 514 }
      - { protocol: tcp, port: 8191 }
      - { protocol: tcp, port: 8888 }
    masquerade: true
    forward-port:
      - { to-port: 8000, protocol: tcp, port: 443 }
    rule:
      - family: ipv4
        source:
          - address: "172.18.0.0/16"
          - action: accept
      - family: ipv4
        source:
          - address: "172.17.0.0/16"
          - action: accept

我得到更正的变量和模板:

<?xml version="1.0" encoding="utf-8"?>
<zone>
  <short>PUBLIC</short>
  <description>Public Zone</description>
  <service name="ssh"/>
  <service name="dhcpv6-client"/>
  <port protocol="tcp" port="8000"/>
  <port protocol="tcp" port="8089"/>
  <port protocol="udp" port="52311"/>
  <port protocol="udp" port="514"/>
  <port protocol="tcp" port="8191"/>
  <port protocol="tcp" port="8888"/>
  <masquerade/>
  <forward-port to-port="8000" protocol="tcp" port="443"/>
  <rule family="ipv4">
    <source address="172.18.0.0/16"/>
    <accept/>
  </rule>
  <rule family="ipv4">
    <source address="172.17.0.0/16"/>
    <accept/>
  </rule>
</zone>

您能否提供一个示例变量来将规则与规则族混合?我尝试了无数次迭代,但没有运气。:(

我的更正模板文件的内容:

<?xml version="1.0" encoding="utf-8"?>
<zone{% if item.target is defined %} target="{{ item.target }}"{% endif %}>
  <short>{{ item.short|default(item.name)|upper }}</short>
{% if item.description is defined %}
  <description>{{ item.description }}</description>
{% endif %}
{% for tag in item %}
{# Settings which can be used several times #}
{% if tag in ['interface','source','service','port','protocol','icmp-block','forward-port','source-port'] %}
{% for subtag in item[tag] %}
  <{{ tag }}{% for name,value in subtag.items() %} {{ name }}="{{ value }}"{% endfor %}/>
{% endfor %}
{# Settings which can be used once #}
{% elif tag in ['icmp-block-inversion','masquerade'] and item[tag] == True %}
  <{{ tag }}/>
{% endif %}
{% endfor %}
{% for rule in item.rule|default([]) %}
  <rule{% if rule.family is defined %} family="{{ rule.family }}"{% endif %}>
{% for tag in rule %}
{% if tag in ['source','destination','service','port','icmp-block','icmp-type','masquerade','forward-port','protocol'] %}
{% for subtag in rule[tag] %}
  {% for name,value in subtag.items() %}
{% if name in ['action'] %}
  <{{ value }}/>
{% else %}
  <{{ tag }} {{ name }}="{{ value }}"/>
{% endif %}
{% endfor %}
{% endfor %}
{% endif %}
{% endfor %}
  </rule>
{% endfor %}
</zone>
firewalld ansible template firewalld-zone jinja2
  • 2 个回答
  • 155 Views
Martin Hope
Skullone
Asked: 2016-11-25 10:05:58 +0800 CST

Puppet/hiera : 从一个模板生成多个文件

  • 0

我正在运行 puppet 4,我想从同一个模板生成几个配置文件,每个配置文件都有不同的配置。

例如 :

# cat /tmp/a.conf 
test1

# cat /tmp/b.conf 
test2

而且我需要将所有这些信息放在 hiera 中,所以我认为是这样的:

test::clusters:
  - 'a.conf'
    text: 'test1'
  - 'b.conf'
    text: 'test2'

谢谢

puppet template puppetmaster hiera
  • 2 个回答
  • 796 Views
Martin Hope
udyshnkr
Asked: 2016-11-01 17:38:48 +0800 CST

如何将 item.src 传递给 Ansible 中的模板?

  • 0

我有一个 Jinja2 模板,我想从我的vars/main.yml.

对于每组变量,我需要在远程服务器上生成一个单独的文件。

我vars/main.yml的结构如下:

List:
  - { src: [
        classPath1: xxx,
        classPath2: xxx, 
        contxtHost: xxx,
        logDir: xxx, 
        contxtRegion: xxx,
        .... 
        ],
      dest: xxxx 
    }
  - { src: [
        xxxx
        ], 
      dest: xxxx 
    }

在我的剧本任务中定义如下:

  - name: testing templates 
    template: "src=templates/sampletest.j2 
               dest=/path/in/Server/{{ item.dest }}
               owner=app 
               group=app 
               mode=0644"
    with_items: '{{ List }}'

如何传递item.src给我的模板?

注意:我正在尝试根据每组变量生成多个文件,item.src并且文件名item.dest使用with_items.

ansible template
  • 1 个回答
  • 4195 Views
Martin Hope
Alexandre Juma
Asked: 2016-10-22 02:50:38 +0800 CST

rsyslog 模板无法正常工作

  • 0

谁能帮我解决这个奇异的问题?

我有一些系统日志服务器将消息转发到中央系统日志服务器(rsyslogd 7.4.7)。在中央系统日志服务器中,我不想将时间戳添加到已标记的消息中,因此我创建了一个模板,该模板仅打印整个 %msg% ,仅此而已。

$template t_my_log_output,"/var/syslog/cm.MY.%$YEAR%%$MONTH%%$DAY%-%msg:F,32:5%.log"
$template ProxiesTemplate2,"%msg%\n"
:rawmsg, contains, " MYAPP "                            -?t_my_log_output;ProxiesTemplate2

问题是 rsyslog 没有附加整个消息。它缺少第一个 %msg% 字符:

41:52 2016-10-21 10:41:42 APP xxx.yyy.zzz.qqq myproc[14]  [_getMsg]: msg

我采取了 tcpdump 只是为了确保两个日期/时间都进来了:

11:41:52.311287 IP xxx.yyy.zzz.qqq.43438 > xxx.yyy.zzz.qqq.syslog: [|syslog]
E.....@.<...
.@.
[email protected] 11:41:52 2016-10-21 10:41:42 APP xxx.yyy.zzz.qqq myproc[14]  [_getMsg]: msg
................

谢谢您的帮助

亚历克斯

rsyslog template
  • 1 个回答
  • 568 Views
Martin Hope
Timo
Asked: 2016-07-01 03:44:55 +0800 CST

更新 azure scaleset - 从预建图像切换到自定义图像

  • 0

我在 azure 中部署了一个 scaleset,我需要通过 credativ 将底层 debian-image 更改为自定义图像。我发现了一些对我不起作用的好资源:

  • https://msftstack.wordpress.com/2016/05/17/how-to-upgrade-an-azure-vm-scale-set-without-shutting-it-down/
  • https://github.com/gbowerman/vmsstools

两篇文章都提到将基础库存图像更新为较新版本或将 uri 更改为自定义图像。但我需要从库存图像更改为自定义图像。这涉及将 json-template 从

storageProfile : {
"imageReference" : {
    publisher : [variables('imagePublisher')],
    offer : [variables('imageOffer')],
    sku : [variables('sku')],
    version : [variables('imageVersion')]
},
osDisk : {
    name : [concat(variables('vmssName'), 'osdisk')],
    vhdContainers : [
        [concat('https://', variables('uniqueStringArray')[0], variables('newStorageAccountSuffix'), '.blob.core.windows.net/', variables('vhdContainerName'))],
        [concat('https://', variables('uniqueStringArray')[1], variables('newStorageAccountSuffix'), '.blob.core.windows.net/', variables('vhdContainerName'))],
        [concat('https://', variables('uniqueStringArray')[2], variables('newStorageAccountSuffix'), '.blob.core.windows.net/', variables('vhdContainerName'))],
        [concat('https://', variables('uniqueStringArray')[3], variables('newStorageAccountSuffix'), '.blob.core.windows.net/', variables('vhdContainerName'))],
        [concat('https://', variables('uniqueStringArray')[4], variables('newStorageAccountSuffix'), '.blob.core.windows.net/', variables('vhdContainerName'))]
    ],
    caching : ReadOnly,
    createOption : FromImage
}}

像这样:

osDisk : {
name : [concat(variables('vmssName'), 'osdisk')],
vhdContainers : [
    [concat('https://', variables('uniqueStringArray')[0], variables('newStorageAccountSuffix'), '.blob.core.windows.net/', variables('vhdContainerName'))],
    [concat('https://', variables('uniqueStringArray')[1], variables('newStorageAccountSuffix'), '.blob.core.windows.net/', variables('vhdContainerName'))],
    [concat('https://', variables('uniqueStringArray')[2], variables('newStorageAccountSuffix'), '.blob.core.windows.net/', variables('vhdContainerName'))],
    [concat('https://', variables('uniqueStringArray')[3], variables('newStorageAccountSuffix'), '.blob.core.windows.net/', variables('vhdContainerName'))],
    [concat('https://', variables('uniqueStringArray')[4], variables('newStorageAccountSuffix'), '.blob.core.windows.net/', variables('vhdContainerName'))]
],
caching : ReadOnly,
createOption : FromImage,
"osType" : "Linux",
uri : https : //storageaccount.blob.core.windows.net/tstclstrvhd/my.vhd

}

这样做的方法是什么?我可以使用不同的图像重新部署规模集吗?

谢谢和问候,蒂莫

更新: 好的,我现在设法复制了 vhd。

  1. 使用 CLI 在规模集的 VM 上解除分配:azure vmssvm deallocate
  2. 使用 azure-cli 复制 blob: azure storage blob copy start --dest-account-key xxx --dest-account-name xxx

我很好奇图片中的内容。解除分配是否会重置图像?我的所有自定义设置都消失了吗?

virtual-machines azure template
  • 1 个回答
  • 630 Views
Martin Hope
lug
Asked: 2012-07-14 01:14:28 +0800 CST

/etc/skel 中以后用户名的占位符

  • 3

是否有可能在位于 /etc/skel 的配置文件中使用占位符,稍后由用户名替换?

例如,我将“:USER:”放在一个配置文件中,并创建一个用户名为“test”的新用户。然后“:USER:”应该被替换为“test”。

感谢您的回复。

linux ubuntu users xubuntu template
  • 3 个回答
  • 1665 Views
Martin Hope
Kyle Sevenoaks
Asked: 2010-03-26 00:41:53 +0800 CST

我的 -tpl 文件不会更新!

  • 0

我在 www.euroworker.no 上运行该站点,它是一个 linux 服务器,该站点有一个后端编辑器。这是一个 smarty/php 站点,当我尝试更新一些 .tpl(两个或三个)时,它们不会更新。我已经尝试通过 FTP 上传,但也不起作用。

我不知道服务器如何工作或任何事情,请帮忙?

它在livecart系统上运行。

谢谢!

php update template
  • 3 个回答
  • 593 Views
Martin Hope
noesgard
Asked: 2009-09-01 03:48:24 +0800 CST

如何在 SharePoint 中查找用于网站或页面的模板

  • 13
锁定。这个问题及其答案被锁定,因为这个问题离题但具有历史意义。它目前不接受新的答案或交互。

如何/在哪里可以找到用于 SharePoint 网站或页面的模板。

我有一个想要模仿的页面,但我不知道在哪里可以找到该页面和站点的模板?

sharepoint sharepoint-2007 template
  • 8 个回答
  • 107006 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve