`
annan211
  • 浏览: 446482 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

ansible 根据主机处理不同case

 
阅读更多
Ansible 根据主机的不同,有时候需要处理不同的场景,例如存在如下场景,配置多台VM的Compoment 不同的 TLS证书和Password。

inventory 文件

[dispatcher-connector]
192.168.99.17
192.168.99.5

[dispatcher-manager]
192.168.99.17

[dispatcher-tools]
192.168.99.17



configure.yml 文件
---
- name: tls enable for connector
  hosts: dispatcher-connector
  vars_files:
    - ./vars/dispatcher.yml
  vars:
    certs_store_path: "{{ connector_certs_dir }}"
    configure_file: "{{ dispatcher_installation_home }}/dispatcher/dispatcher-connector/conf/connector.properties"
  become: yes
  become_user: root  
  tasks:        
    - debug: var=hostvars[inventory_hostname]['ansible_default_ipv4']['address']   
    - debug: var=connector_mqtt[hostvars[inventory_hostname]['ansible_default_ipv4']['address']]['ssl.keystore.location']
    - debug: var={{connector_mqtt_key_store_password_base64[inventory_hostname]}}              
    
    - name: add mqtt configure tls config
      include: "{{ playbook_dir }}/common/connector-mqtt-tls-enable.yml"
      when: connector_mqtt_tls_enable

    - name: add http configure tls config
      include: "{{ playbook_dir }}/common/connector-http-tls-enable.yml"
      when: connector_http_tls_enable
  tags: dispatcher-connector




vars 变量文件
############################## Dispatcher Installation Basic Info ###############
latest_version: 4.1.1
origin_version: 4.1.1
dispatcher_installation_home: /opt/ddi/dispatcher
dispatcher_user_name: dispatcher
dispatcher_group_name: dispatcher
dispatcher_user_home: /home/dispatcher
dispatcher_connector_http_host: "{{ groups['dispatcher-connector'][0] }}"

############################## Dispatcher EP Installation Info #################
connector_ep_list:
manager_ep_list:
connector_lib_dir: "{{ dispatcher_installation_home }}/dispatcher-{{ latest_version }}/dispatcher-connector/lib"
manager_lib_dir: "{{ dispatcher_installation_home }}/dispatcher-{{ latest_version }}/dispatcher-manager/webapps/WEB-INF/lib"

certs_from_path: "{{ playbook_dir }}/files"
connector_certs_dir: "{{ dispatcher_installation_home }}/dispatcher-{{ latest_version }}/dispatcher-connector/conf/certs"
manager_certs_dir: "{{ dispatcher_installation_home }}/dispatcher-{{ latest_version }}/dispatcher-manager/conf/certs"
tools_certs_dir: "{{ dispatcher_installation_home }}/dispatcher-{{ latest_version }}/dispatcher-tools/cli/conf/certs"


############################## tls setting for dispatcher ######################
connector_mqtt_tls_enable: true

connector_mqtt:
  192.168.99.17:
    key_store_password_base64: MTEyMjMz
    key_manager_password_base64: MTEyMjMz
    trust_store_password_base64: Y2hhbmdlaXQ=
    ssl.keystore.location: "/opt/connector-mqtt.server.keystore.jks"
    ssl.truststore.location: "/opt/connector-mqtt.server.truststore.jks"
  192.168.99.5:
    key_store_password_base64: MTEyMjMz
    key_manager_password_base64: MTEyMjMz
    trust_store_password_base64: Y2hhbmdlaXQ=
    ssl.keystore.location: "/opt/connector-mqtt.server.keystore.jks"
    ssl.truststore.location: "/opt/connector-mqtt.server.truststore.jks"

connector_http_tls_enable: true

connector_http:
  192.168.99.17:
    key_store_password_base64: MTEyMjMz
    key_manager_password_base64: MTEyMjMz
    trust_store_password_base64: Y2hhbmdlaXQ=
    ssl.keystore.location: "{{ playbook_dir }}/files/192.168.99.17/connector-mqtt.server.keystore.jks"
    ssl.truststore.location: "{{ playbook_dir }}/files/192.168.99.17/connector-mqtt.server.truststore.jks"
  192.168.99.5:
    key_store_password_base64: MTEyMjMz
    key_manager_password_base64: MTEyMjMz
    trust_store_password_base64: Y2hhbmdlaXQ=
    ssl.keystore.location: "{{ playbook_dir }}/files/192.168.99.5/connector-mqtt.server.keystore.jks"
    ssl.truststore.location: "{{ playbook_dir }}/files/192.168.99.5/connector-mqtt.server.truststore.jks"

#connector_mqtt_key_store_password_base64: MTEyMjMz
#connector_mqtt_key_manager_password_base64: MTEyMjMz
#connector_mqtt_trust_store_password_base64: Y2hhbmdlaXQ=

#connector_http_key_store_password_base64: MTEyMjMz
#connector_http_key_manager_password_base64: MTEyMjMz
#connector_http_trust_store_password_base64: Y2hhbmdlaXQ=
connectivity_https_port: 8443
monitor_https_port: 8444
connectivity_http_port: 8080
monitor_http_port: 8161



common/connector-mqtt-tls-enable.yml

---
- name: create certs store directory
  file:
    path: "{{ certs_store_path }}"
    owner: dispatcher
    group: dispatcher
    state: directory

- name: copy dispatcher-connector keystore certs
  copy:
    src: "{{ connector_mqtt[hostvars[inventory_hostname]['ansible_default_ipv4']['address']]['ssl.keystore.location'] }}"
    dest: "{{ certs_store_path }}/connector-mqtt.server.keystore.jks"
    mode: 0644

- name: copy dispatcher-connector truststore certs
  copy:
    src: "{{ connector_mqtt[hostvars[inventory_hostname]['ansible_default_ipv4']['address']]['ssl.truststore.location'] }}"
    dest: "{{ certs_store_path }}/connector-mqtt.server.truststore.jks"
    mode: 0644

- name: modify connector keystore path if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.key.store.path=\s*/?\w+'
    line: 'mqtt.ssl.key.store.path={{ certs_store_path }}/connector-mqtt.server.keystore.jks'
    backrefs: yes
    backup: yes
    state: present

- name: add connector keystore path if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.key.store.path=\s*/?\w+'
    line: 'mqtt.ssl.key.store.path={{ certs_store_path }}/connector-mqtt.server.keystore.jks'
    insertafter: '^mqtt.authentication.certificate.deviceId.key'
    state: present

- name: modify connector keystore password if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.key.store.password=\s*/?\w+'
    line: "mqtt.ssl.key.store.password={{ connector_mqtt[hostvars[inventory_hostname]['ansible_default_ipv4']['address']]['key_store_password_base64'] }}"
    backrefs: yes
    backup: yes
    state: present

- name: add connector keystore password if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.key.store.password=\s*/?\w+'
    line: "mqtt.ssl.key.store.password={{ connector_mqtt[hostvars[inventory_hostname]['ansible_default_ipv4']['address']]['key_store_password_base64'] }}"
    insertafter: '^mqtt.ssl.key.store.path'
    state: present

- name: modify connector key manager password if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.key.manager.password=\s*/?\w+'
    line: "mqtt.ssl.key.manager.password={{ connector_mqtt[hostvars[inventory_hostname]['ansible_default_ipv4']['address']]['key_manager_password_base64'] }}"
    backrefs: yes
    backup: yes
    state: present

- name: add connector keystore password if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.key.manager.password=\s*/?\w+'
    line: "mqtt.ssl.key.manager.password={{ connector_mqtt[hostvars[inventory_hostname]['ansible_default_ipv4']['address']]['key_manager_password_base64'] }}"
    insertafter: '^mqtt.ssl.key.store.password'
    state: present

- name: modify connector truststore path if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.trust.store.path=\s*/?\w+'
    line: 'mqtt.ssl.trust.store.path={{ certs_store_path }}/connector-mqtt.server.truststore.jks'
    backrefs: yes
    backup: yes
    state: present

- name: add connector truststore path if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.trust.store.path=\s*/?\w+'
    line: 'mqtt.ssl.trust.store.path={{ certs_store_path }}/connector-mqtt.server.truststore.jks'
    insertafter: '^mqtt.ssl.key.manager.password'
    state: present

- name: modify connector truststore password if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.trust.store.password=\s*/?\w+'
    line: "mqtt.ssl.trust.store.password={{ connector_mqtt[hostvars[inventory_hostname]['ansible_default_ipv4']['address']]['trust_store_password_base64'] }}"
    backrefs: yes
    backup: yes
    state: present

- name: add connector truststore password if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.trust.store.password=\s*/?\w+'
    line: "mqtt.ssl.trust.store.password={{ connector_mqtt[hostvars[inventory_hostname]['ansible_default_ipv4']['address']]['trust_store_password_base64'] }}"
    insertafter: '^mqtt.ssl.trust.store.path'
    state: present



common/connector-http-tls-enable.yml

---
- name: create certs store directory
  file:
    path: "{{ certs_store_path }}"
    owner: dispatcher
    group: dispatcher
    state: directory

- name: copy dispatcher-connector keystore certs
  copy:
    src: "{{ connector_http[hostvars[inventory_hostname]['ansible_default_ipv4']['address']]['ssl.keystore.location'] }}"
    dest: "{{ certs_store_path }}/connector-http.server.keystore.jks"
    mode: 0644

- name: copy dispatcher-connector truststore certs
  copy:
    src: "{{ connector_http[hostvars[inventory_hostname]['ansible_default_ipv4']['address']]['ssl.truststore.location'] }}"
    dest: "{{ certs_store_path }}/connector-http.server.truststore.jks"
    mode: 0644

- name: modify connector keystore path if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.key.store.path=\s*/?\w+'
    line: 'http.ssl.key.store.path={{ certs_store_path }}/connector-http.server.keystore.jks'
    backrefs: yes
    backup: yes
    state: present

- name: add connector keystore path if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.key.store.path=\s*/?\w+'
    line: 'http.ssl.key.store.path={{ certs_store_path }}/connector-http.server.keystore.jks'
    insertafter: '^mqtt.ssl.trust.store.password'
    state: present

- name: modify connector keystore password if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.key.store.password=\s*/?\w+'
    line: "http.ssl.key.store.password={{ connector_http[hostvars[inventory_hostname]['ansible_default_ipv4']['address']]['key_store_password_base64'] }}"
    backrefs: yes
    backup: yes
    state: present

- name: add connector keystore password  for http if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.key.store.password=\s*/?\w+'
    line: "http.ssl.key.store.password={{ connector_http[hostvars[inventory_hostname]['ansible_default_ipv4']['address']]['key_store_password_base64'] }}"
    insertafter: '^http.ssl.key.store.path'
    state: present

- name: modify connector key manager password  for http if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.key.manager.password=\s*/?\w+'
    line: "http.ssl.key.manager.password={{ connector_http[hostvars[inventory_hostname]['ansible_default_ipv4']['address']]['key_manager_password_base64'] }}"
    backrefs: yes
    backup: yes
    state: present

- name: add connector key manager password  for http if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.key.manager.password=\s*/?\w+'
    line: "http.ssl.key.manager.password={{ connector_http[hostvars[inventory_hostname]['ansible_default_ipv4']['address']]['key_manager_password_base64'] }}"
    insertafter: '^http.ssl.key.store.password'
    state: present

- name: modify connector truststore path for http  if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.trust.store.path=\s*/?\w+'
    line: 'http.ssl.trust.store.path={{ certs_store_path }}/connector-http.server.truststore.jks'
    backrefs: yes
    backup: yes
    state: present

- name: add connector truststore path for http if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.trust.store.path=\s*/?\w+'
    line: 'http.ssl.trust.store.path={{ certs_store_path }}/connector-http.server.truststore.jks'
    insertafter: '^http.ssl.key.manager.password'
    state: present

- name: modify connector truststore password for http if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.trust.store.password=\s*/?\w+'
    line: "http.ssl.trust.store.password={{ connector_http[hostvars[inventory_hostname]['ansible_default_ipv4']['address']]['trust_store_password_base64'] }}"
    backrefs: yes
    backup: yes
    state: present

- name: add connector truststore password for http if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.trust.store.password=\s*/?\w+'
    line: "http.ssl.trust.store.password={{ connector_http[hostvars[inventory_hostname]['ansible_default_ipv4']['address']]['trust_store_password_base64'] }}"
    insertafter: '^http.ssl.trust.store.path'
    state: present


Result




第二种方式

inventory 文件

[dispatcher-connector]
192.168.99.17
192.168.99.5

[dispatcher-manager]
192.168.99.17

[dispatcher-tools]
192.168.99.17




vars 变量文件
---

############################## Dispatcher Installation Basic Info ###############
latest_version: 4.1.1
origin_version: 4.1.1
dispatcher_installation_home: /opt/ddi/dispatcher
dispatcher_user_name: dispatcher
dispatcher_group_name: dispatcher
dispatcher_user_home: /home/dispatcher
dispatcher_connector_http_host: "{{ groups['dispatcher-connector'][0] }}"

############################## Dispatcher EP Installation Info #################
connector_ep_list:
manager_ep_list:
connector_lib_dir: "{{ dispatcher_installation_home }}/dispatcher-{{ latest_version }}/dispatcher-connector/lib"
manager_lib_dir: "{{ dispatcher_installation_home }}/dispatcher-{{ latest_version }}/dispatcher-manager/webapps/WEB-INF/lib"

certs_from_path: "{{ playbook_dir }}/files"
connector_certs_dir: "{{ dispatcher_installation_home }}/dispatcher-{{ latest_version }}/dispatcher-connector/conf/certs"
manager_certs_dir: "{{ dispatcher_installation_home }}/dispatcher-{{ latest_version }}/dispatcher-manager/conf/certs"
tools_certs_dir: "{{ dispatcher_installation_home }}/dispatcher-{{ latest_version }}/dispatcher-tools/cli/conf/certs"


############################## tls setting for dispatcher ######################
connector_mqtt_tls_enable: true
connector_http_tls_enable: true

connector_mqtt_key_store_password_base64:
  host1: MTEyMjMz1
  host2: MTEyMjMz2

connector_mqtt_key_manager_password_base64:
  host1: MTEyMjMz1
  host2: MTEyMjMz2

connector_mqtt_trust_store_password_base64:
  host1: Y2hhbmdlaXQ=1
  host2: Y2hhbmdlaXQ=2

connector_mqtt_ssl_keystore_location:
  host1: /opt/ssl/connector-mqtt.server.keystore1.jks
  host2: /opt/ssl/connector-mqtt.server.keystore2.jks

connector_mqtt_ssl_truststore_location:
  host1: /opt/ssl/connector-mqtt.server.truststore1.jks
  host2: /opt/ssl/connector-mqtt.server.truststore2.jks

connector_http_key_store_password_base64:
  host1: MTEyMjMz1
  host2: MTEyMjMz2

connector_http_key_manager_password_base64:
  host1: MTEyMjMz1
  host2: MTEyMjMz2

connector_http_trust_store_password_base64:
  host1: Y2hhbmdlaXQ=1
  host2: Y2hhbmdlaXQ=2

connector_http_ssl_keystore_location:
  host1: /opt/ssl/connector-http.server.keystore1.jks
  host2: /opt/ssl/connector-http.server.keystore2.jks

connector_http_ssl_truststore_location:
  host1: /opt/ssl/connector-http.server.truststore1.jks
  host2: /opt/ssl/connector-http.server.truststore2.jks




configure.yml文件

---
- name: tls enable for connector
  hosts: dispatcher-connector
  vars_files:
    - ./vars/dispatcher.yml
  vars:
    certs_store_path: "{{ connector_certs_dir }}"
    configure_file: "{{ dispatcher_installation_home }}/dispatcher/dispatcher-connector/conf/connector.properties"
  become: yes
  become_user: root
  tasks:
    - name: add kafka tls config
      include: "{{ playbook_dir }}/common/kafka-tls-enable.yml"
      when: kafka_tls_enable

    - name: add cassandra tls config
      include: "{{ playbook_dir }}/common/cassandra-tls-enable.yml"
      when: cassandra_tls_enable

    - name: add mqtt configure tls config
      include: "{{ playbook_dir }}/common/connector-mqtt-tls-enable.yml"
      when: connector_mqtt_tls_enable

    - name: add http configure tls config
      include: "{{ playbook_dir }}/common/connector-http-tls-enable.yml"
      when: connector_http_tls_enable

  tags: dispatcher-connector

- name: tls enable for manager
  hosts: dispatcher-manager
  vars_files:
    - ./vars/dispatcher.yml
  vars:
    certs_store_path: "{{ manager_certs_dir }}"
    configure_file: "{{ dispatcher_installation_home }}/dispatcher/dispatcher-manager/conf/manager.properties"
  become: yes
  become_user: root
  tasks:
    - name: add kafka tls config
      include: "{{ playbook_dir }}/common/kafka-tls-enable.yml"
      when: kafka_tls_enable

    - name: add cassandra tls config
      include: "{{ playbook_dir }}/common/cassandra-tls-enable.yml"
      when: cassandra_tls_enable
  tags: dispatcher-manager

- name: tls enable for tools
  hosts: dispatcher-tools
  vars_files:
    - ./vars/dispatcher.yml
  vars:
    certs_store_path: "{{ tools_certs_dir }}"
    configure_file: "{{ dispatcher_installation_home }}/dispatcher/dispatcher-tools/cli/conf/cli.conf"
  become: yes
  become_user: root
  tasks:
    - name: add cassandra tls config
      include: "{{ playbook_dir }}/common/cassandra-tls-enable.yml"
      when: cassandra_tls_enable
  tags: dispatcher-tools




common/connector-mqtt-tls-enable.yml
---
- name: create certs store directory
  file:
    path: "{{ certs_store_path }}"
    owner: dispatcher
    group: dispatcher
    state: directory

- name: copy dispatcher-connector keystore certs
  copy:
    src: "{{ connector_mqtt_ssl_keystore_location[inventory_hostname] }}"
    dest: "{{ certs_store_path }}/connector-mqtt.server.keystore.jks"
    mode: 0644

- name: copy dispatcher-connector truststore certs
  copy:
    src: "{{ connector_mqtt_ssl_truststore_location[inventory_hostname] }}"
    dest: "{{ certs_store_path }}/connector-mqtt.server.truststore.jks"
    mode: 0644

- name: modify connector keystore path if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.key.store.path=\s*/?\w+'
    line: 'mqtt.ssl.key.store.path={{ certs_store_path }}/connector-mqtt.server.keystore.jks'
    backrefs: yes
    backup: yes
    state: present

- name: add connector keystore path if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.key.store.path=\s*/?\w+'
    line: 'mqtt.ssl.key.store.path={{ certs_store_path }}/connector-mqtt.server.keystore.jks'
    insertafter: '^mqtt.authentication.certificate.deviceId.key'
    state: present

- name: modify connector keystore password if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.key.store.password=\s*/?\w+'
    line: "mqtt.ssl.key.store.password={{ connector_mqtt_key_store_password_base64[inventory_hostname] }}"
    backrefs: yes
    backup: yes
    state: present

- name: add connector keystore password if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.key.store.password=\s*/?\w+'
    line: "mqtt.ssl.key.store.password={{ connector_mqtt_key_store_password_base64[inventory_hostname] }}"
    insertafter: '^mqtt.ssl.key.store.path'
    state: present

- name: modify connector key manager password if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.key.manager.password=\s*/?\w+'
    line: "mqtt.ssl.key.manager.password={{ connector_mqtt_key_manager_password_base64[inventory_hostname] }}"
    backrefs: yes
    backup: yes
    state: present

- name: add connector key manager password if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.key.manager.password=\s*/?\w+'
    line: "mqtt.ssl.key.manager.password={{ connector_mqtt_key_manager_password_base64[inventory_hostname] }}"
    insertafter: '^mqtt.ssl.key.store.password'
    state: present

- name: modify connector truststore path if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.trust.store.path=\s*/?\w+'
    line: 'mqtt.ssl.trust.store.path={{ certs_store_path }}/connector-mqtt.server.truststore.jks'
    backrefs: yes
    backup: yes
    state: present

- name: add connector truststore path if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.trust.store.path=\s*/?\w+'
    line: 'mqtt.ssl.trust.store.path={{ certs_store_path }}/connector-mqtt.server.truststore.jks'
    insertafter: '^mqtt.ssl.key.manager.password'
    state: present

- name: modify connector truststore password if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.trust.store.password=\s*/?\w+'
    line: "mqtt.ssl.trust.store.password={{ connector_mqtt_trust_store_password_base64[inventory_hostname] }}"
    backrefs: yes
    backup: yes
    state: present

- name: add connector truststore password if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*mqtt.ssl.trust.store.password=\s*/?\w+'
    line: "mqtt.ssl.trust.store.password={{ connector_mqtt_trust_store_password_base64[inventory_hostname] }}"
    insertafter: '^mqtt.ssl.trust.store.path'
    state: present




common/connector-http-tls-enable.yml

---
- name: create certs store directory
  file:
    path: "{{ certs_store_path }}"
    owner: dispatcher
    group: dispatcher
    state: directory

- name: copy dispatcher-connector keystore certs
  copy:
    src: "{{ connector_http_ssl_keystore_location[inventory_hostname] }}"
    dest: "{{ certs_store_path }}/connector-http.server.keystore.jks"
    mode: 0644

- name: copy dispatcher-connector truststore certs
  copy:
    src: "{{ connector_http_ssl_truststore_location[inventory_hostname] }}"
    dest: "{{ certs_store_path }}/connector-http.server.truststore.jks"
    mode: 0644

- name: modify connector keystore path if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.key.store.path=\s*/?\w+'
    line: 'http.ssl.key.store.path={{ certs_store_path }}/connector-http.server.keystore.jks'
    backrefs: yes
    backup: yes
    state: present

- name: add connector keystore path if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.key.store.path=\s*/?\w+'
    line: 'http.ssl.key.store.path={{ certs_store_path }}/connector-http.server.keystore.jks'
    insertafter: '^mqtt.ssl.trust.store.password'
    state: present

- name: modify connector keystore password if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.key.store.password=\s*/?\w+'
    line: "http.ssl.key.store.password={{ connector_http_key_store_password_base64[inventory_hostname] }}"
    backrefs: yes
    backup: yes
    state: present

- name: add connector keystore password  for http if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.key.store.password=\s*/?\w+'
    line: "http.ssl.key.store.password={{ connector_http_key_store_password_base64[inventory_hostname] }}"
    insertafter: '^http.ssl.key.store.path'
    state: present

- name: modify connector key manager password  for http if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.key.manager.password=\s*/?\w+'
    line: "http.ssl.key.manager.password={{ connector_http_key_manager_password_base64[inventory_hostname] }}"
    backrefs: yes
    backup: yes
    state: present

- name: add connector key manager password  for http if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.key.manager.password=\s*/?\w+'
    line: "http.ssl.key.manager.password={{ connector_http_key_manager_password_base64[inventory_hostname] }}"
    insertafter: '^http.ssl.key.store.password'
    state: present

- name: modify connector truststore path for http  if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.trust.store.path=\s*/?\w+'
    line: 'http.ssl.trust.store.path={{ certs_store_path }}/connector-http.server.truststore.jks'
    backrefs: yes
    backup: yes
    state: present

- name: add connector truststore path for http if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.trust.store.path=\s*/?\w+'
    line: 'http.ssl.trust.store.path={{ certs_store_path }}/connector-http.server.truststore.jks'
    insertafter: '^http.ssl.key.manager.password'
    state: present

- name: modify connector truststore password for http if exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.trust.store.password=\s*/?\w+'
    line: "http.ssl.trust.store.password={{ connector_http_trust_store_password_base64[inventory_hostname] }}"
    backrefs: yes
    backup: yes
    state: present

- name: add connector truststore password for http if not exists
  lineinfile:
    path: "{{ configure_file }}"
    regexp: '^\s*http.ssl.trust.store.password=\s*/?\w+'
    line: "http.ssl.trust.store.password={{ connector_http_trust_store_password_base64[inventory_hostname] }}"
    insertafter: '^http.ssl.trust.store.path'
    state: present



结果是一样的
  • 大小: 31.7 KB
分享到:
评论

相关推荐

    Python自动化运维之Ansible定义主机与组规则操作详解

    本文实例讲述了Python自动化运维之Ansible定义主机与组规则操作。分享给大家供大家参考,具体如下: 一 点睛 Ansible通过定义好的主机与组规则(Inventory)对匹配的目标主机进行远程操作,配置规则文件默认是/etc/...

    Ansible部署Mysql 5.7.28主从

    Ansible 主机: 10.4.0.57  Mysql Master: 10.4.0.17 Mysql Slave: 10.4.0.22 所有操作都在Ansible主机上进行 执行步骤: 1. 安装ansible 2.9  pip install ansible==2.9 2. 配置 Ansible到Master和Slave主机免密...

    Rancher-Ansible, 使用Ansible运行Rancher平台和 register 主机.zip

    Rancher-Ansible, 使用Ansible运行Rancher平台和 register 主机 rancher-ansible这个playbook使用Rancher自动安装平台和 register 主机,这个playbook可以使用cloudformation自动在AWS上创建主机,或者使用 static ...

    Ansible-ansible-ssh.zip

    Ansible-ansible-ssh.zip,使用ansible inventory和config.ansible-ssh连接到托管主机的脚本,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理、应用程序部署和任务自动化。

    Ansible-40ansible.zip

    Ansible-40ansible.zip,使用rest api40ansible的fortinet产品的ansible模块和示例,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理、应用程序部署和任务自动化。

    ansible离线安装包

    离线安装ansible 把安装包放到/data目录并解压 tar xvf ansible_packages.tar.gz rpm -ivh deltarpm-3.6-3.el7.x86_64.rpm rpm -ivh python-deltarpm-3.6-3.el7.x86_64.rpm rpm -ivh createrepo-0.9.9-28.el7....

    Ansible-Ansible-roles.zip

    Ansible-Ansible-roles.zip,责任角色责任角色?,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理、应用程序部署和任务自动化。

    Ansible-Ansible-WSL.zip

    Ansible-Ansible-WSL.zip,通过ansibleansible wsl从wsl内部设置窗口,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理、应用程序部署和任务自动化。

    Ansible-ansible-haproxy.zip

    Ansible-ansible-haproxy.zip,统一OpenStack安装程序的Ansible Haproxy角色Ansible Haproxy(OpenStack就绪),ansible是一个简单而强大的自动化引擎。它用于帮助配置管理、应用程序部署和任务自动化。

    Ansible-intellij-ansible.zip

    Ansible-intellij-ansible.zip,支持janja2标签的yaml/ansible/intellij ideayaml/ansible in intellij idea,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理、应用程序部署和任务自动化。

    Ansible-ansible-snippets.zip

    Ansible-ansible-snippets.zip,ansible vim片段sansible片段,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理、应用程序部署和任务自动化。

    红帽8系统ansible安装包及依赖包 ansible-rhel 8.zip

    ansible-2.8.0-1.el8ae.noarch.rpm python3-jmespath-0.9.0-11.el8.noarch.rpm sshpass-1.06-3.el8ae.x86_64.rpm 若RHEL 8版本的离线本地镜像中无法安装ansible,可使用以上压缩包中的rpm包安装; 安装后可直接使用...

    Ansible-k3s-ansible.zip

    Ansible-k3s-ansible.zip,ansible playbook部署k3s-kubernetes集群通过ansibe使用k3s构建kubernetes集群。,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理、应用程序部署和任务自动化。

    Ansible-ansible-makefile.zip

    Ansible-ansible-makefile.zip,makefile用作ansiblemakefile对ansible用户的简单接口,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理、应用程序部署和任务自动化。

    Ansible-ansible-nagios.zip

    Ansible-ansible-nagios.zip,Ansible Playbook,用于设置Nagios监视系统和客户端。,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理、应用程序部署和任务自动化。

    ansible部署gpmall商城

    ansible部署gpmall商城 云计算

    Ansible-wordpress-ansible.zip

    Ansible-wordpress-ansible.zip,在digitalocean.com上使用ansible在ubuntu 16.04上安装wordpress...wordpress ansible,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理、应用程序部署和任务自动化。

    Ansible-ansible-mac-install.zip

    Ansible-ansible-mac-install.zip,通过Ansible.Ansible Playbook for Mac安装和配置,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理、应用程序部署和任务自动化。

    Ansible-ansible-rclone.zip

    Ansible-ansible-rclone.zip,RClone的职责:https://galaxy.ansible.com/stefangweichinger/rcloneansible-rclone,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理、应用程序部署和任务自动化。

Global site tag (gtag.js) - Google Analytics