設定ファイルの文字列を置き換えることを楽しみにしている、つまり/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
手動で何をいつ行うのですか? – techraf
私の場合はホスト名を置き換えます 'vm-karn'は' regexp: '#Hostname "vl-karn01"' ' – rockypy17
の代わりに新しい名前になります。 – techraf