2017-06-29 7 views
0

設定ファイルの文字列を置き換えることを楽しみにしている、つまり/opt/collectd/etc/collectd.conf私は、私の脚本で述べた次のように正確に私は達成するために必要なものです:デフォルトホスト名をリモートホスト上の実際のホスト名に置き換える可能性のある遊び方

1)マイ/opt/collectd/etc/collectd.confファイルは、私がchnageする必要が以下のようなプリセット設定、&で#Hostname "vl-karn01"を交換していますリモートホスト名は、それを置き換える場合は、Hostname "vl-karn"に置き換えます。したがって、ハッシュ記号を削除してホスト名を置き換えます。私は手動でそれがreplaceモジュールを使用して脚本を実行している各リモートホストのための私のplayboookでホスト名を与えている。この時点でPrefix "collectd.gfpoll.

3)との# Prefix "collectd.unix."ため

############################################################################## 
# Global                  # 
#----------------------------------------------------------------------------# 
# Global settings for the daemon.           # 
############################################################################## 

#Hostname "vl-karn01" 
#FQDNLookup true 
#BaseDir  "${prefix}/var/lib/collectd" 
#PIDFile  "${prefix}/var/run/collectd.pid" 
#PluginDir "${exec_prefix}/lib/collectd" 
#TypesDB  "/opt/collectd/share/collectd/types.db" 
BaseDir "/var/lib/collectd" 
PIDFile "/var/run/collectd.pid" 
# Prefix "collectd.unix." 

2)Similarliy ...

ここで
--- 
- name: Playbook to Install CollectD 
    hosts: vm-karn 
    gather_facts: False 
    remote_user: root 
    become: true 
    tasks: 
    - name: Downloading collectd 
    get_url: 
     url="http://spot-dc/collectd-5.7.2.tar.gz" 
     dest="/opt/" 

    - name: Extracting collectd archive 
    unarchive: 
     src="/opt/collectd-5.7.2.tar.gz" 
     dest="/opt/" 
     remote_src=True 

    - name: Creating soft link to collectd Dir 
    file: 
     src: "/opt/collectd-5.7.2" 
     dest: "/opt/collectd" 
     state: link 
     owner: karn 
     group: ansible 

    - name: Replacing hostname entry 
    replace: 
     regexp: '#Hostname "vl-karn01"' 
     replace: 'Hostname "vm-karn"' 
     dest: /opt/collectd/etc/collectd.conf 
     backup: yes 

    - name: Replacing Prefix pattern 
    replace: 
     regexp: '# Prefix "collectd.unix."' 
     replace: ' Prefix "collectd.gfpoll."' 
     dest: /opt/collectd/etc/collectd.conf 

    - name: Copy the collectd Daemon to init .. 
    copy: 
     src: "/opt/collectd/startup/collectd" 
     dest: "/etc/init.d/" 
     remote_src: True 
     mode: 0755 
     owner: root 
     group: root 

    - name: starting collectd Service 
    service: 
     name: collectd 
     state: started 
     enabled: yes 
+0

手動で何をいつ行うのですか? – techraf

+0

私の場合はホスト名を置き換えます 'vm-karn'は' regexp: '#Hostname "vl-karn01"' ' – rockypy17

+0

の代わりに新しい名前になります。 – techraf

答えて

1

は、現在の1で設定ファイルにホスト名を置き換えます作業です。

- name: Replacing hostname entry 
    lineinfile: 
    regexp: Hostname 
    line: 'Hostname "{{ ansible_hostname }}"' 
    dest: /opt/collectd/etc/collectd.conf 
    backup: yes 
+0

あなたは何を意味するのか分かりません。私はあなたが答えの下にこれを書いた理由を知りません。私は関係がありません。 – techraf

関連する問題