Ansible playbook - regexp / parantez ve tırnak içindeki veriler değiştirilemiyor

0

Soru

Yeni bir sunucu dağıtmak için bir oyun kitabını bitirmeye çalışıyordum. Tırnak işaretleri içeren parantez içindeki verileri değiştirmekle uğraşıyorum lineinfile ve bir regex:

- name: "Configuring: filebeat agent - configuring output to logstash"
  lineinfile:
    dest: "/etc/filebeat/filebeat.yml"
    regexp: '#hosts: ["localhost:5044"]'
    line: 'hosts: ["elk.home:5044"]'
  tags: application

Oyun kitabı çalıştırıldıktan sonra, istenen satır:

#hosts: ["localhost:5044"]

yansıtacak şekilde güncellenmiyor:

hosts: ["elk.home:5044"]

Elde etmek istediğim:

#hosts: ["localhost:5044"] ile değiştirilir hosts: ["elk.home:5044"]

Oluşturulan hiçbir hata yok. Değişmeyi denedim. " ve ' kaçışlarla birlikte \ Ama ifadeyi doğru anlayamıyorum. Herhangi bir öneri çok takdir edilecektir!

ansible filebeat regexp-replace
2021-11-23 04:50:20
1

En iyi cevabı

0

Teşekkürler seshadri_c ve β.εηοιτ.βε!

Aşağıdaki satırlarla bir çözüme ulaşabildim:

- name: "Configuring: filebeat agent - enabling logstash output hosts"
  lineinfile:
    dest: "/etc/filebeat/filebeat.yml"
    regexp: '#hosts: \["localhost:5044"\]'
    line: 'hosts: ["elk.home:5044"]'
  tags: 
    - configuration
    - application
    - filebeat

Senaryo tamamlandıktan sonra, boşluk ile bir sorunu vardı. Çizgiyi doğru şekilde değiştiren iki boşluk ekledim

- name: "Configuring: filebeat agent - enabling logstash output hosts"
  lineinfile:
    dest: "/etc/filebeat/filebeat.yml"
    regexp: '#hosts: \["localhost:5044"\]'
    line: '  hosts: ["elk.home:5044"]'
  tags: 
    - configuration
    - application
    - filebeat
2021-11-26 02:10:47

Diğer dillerde

Bu sayfa diğer dillerde

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................