LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-17-2020, 11:24 AM   #1
elalexluna83
Member
 
Registered: Mar 2012
Posts: 55

Rep: Reputation: Disabled
Ansible - Update multipath.conf file


Hello There!
I have lot of servers that use multipath.
e.g.
Code:
multipath {
    wwid 369834349802938746554637382920111
    alias asm_disk1
}
multipath {
    wwid 369834349802938746554637382920112
    alias asm_disk2
}
I want an ansible playbook that add new entries for me. But it is not working right now. (new multipath entry inside a multipath entry)
Code:
multipath {
# BEGIN ANSIBLE MANAGED BLOCK
multipath {
     wwid 369834349802938746554637382920113
     alias asm_disk3
}
# END ANSIBLE MANAGED BLOCK
     wwid 369834349802938746554637382920112
     alias asm_disk2
}
This is my playbook. any ideas how to fix it?

Code:
---
- name: Update Multipath
  hosts: localhost
  become: yes

  tasks:
  - name:
    blockinfile:
      path: /etc/multipath.conf
      insertafter: 'multipath'
      block: |
        multipath {
            wwid 369834349802938746554637382920113
            alias asm_disk3
        }
      backup: yes
 
Old 08-25-2020, 11:45 PM   #2
malayo
Member
 
Registered: Dec 2010
Posts: 130

Rep: Reputation: 1
yaml semms valid, tried removing lines with "multipath {" and "}"
 
Old 08-26-2020, 12:58 PM   #3
sgrlscz
Member
 
Registered: Aug 2008
Posts: 123

Rep: Reputation: 84
I would change 'multipath' to 'multipaths'. That should then insert the new multipath at the top of the multipaths block.

The problem with the way it's written is that there are multiple lines that match 'multipath', and based on the behavior you're seeing, it looks like it's using the last match for where to do the insert. Since it's an 'insertafter', it sticks the new block into another multipath block.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Ansible Guide: Manage Files using Ansible LXer Syndicated Linux News 0 04-26-2019 10:32 AM
LXer: Ansible Guide: Create Ansible Playbook for LEMP Stack LXer Syndicated Linux News 0 04-13-2019 05:03 AM
LXer: Ansible Tutorial: Introduction to simple Ansible commands LXer Syndicated Linux News 0 05-21-2018 10:28 AM
LXer: Ansible Tutorial: Intorduction to simple Ansible commands LXer Syndicated Linux News 0 01-14-2018 05:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration