Ansible热添加多个端口

时间:2017-09-13 20:25:49

标签: ansible

Ansible Playbook

如何在ansible-playbook中使用firewall-cmd命令添加多个端口(交互式提示)

df$date.time<-strptime(df$date.time, "%d/%m/%y %H:%M:%S", tz="GMT0")
df$date.time<- as.POSIXlt(df$date.time, "%Y/%m/%d %H:%M:%S", tz="GMT0")
df$date.time<-round(df$date.time, units="hours")

> head(df$date.time)
[1] "2017-03-12 00:00:00 GMT"
[2] "2017-03-12 02:00:00 GMT"
[3] "2017-03-12 04:00:00 GMT"
[4] "2017-03-12 06:00:00 GMT"

我可以为一个端口而不是多个端口

1 个答案:

答案 0 :(得分:0)

vars_prompt&#34;循环&#34;如果不编写自定义插件,则无法实现(如Ansible 2.3所述)。

您可以通过期望以逗号分隔的字符串并稍后将其拆分为列表来解决此问题:

- hosts: localhost
  gather_facts: no
  vars_prompt:
    - name: ports
      prompt: "Enter port(s) number"
      private: no
  tasks:
    - name: add port
      shell: /bin/firewall-cmd --permanent --add-port={{ item }}/tcp
      with_items: "{{ ports.split(',') }}"