0

I need to enter a block of data on a remote host using ansible, i have tried "blockinfile" but was unsuccessful..

But when i run the same thing on omy local hosts it works fine dont know why

---
 - hosts: 1.1.0.1
   tasks:
   - name: putting /tmp/fire.txt File on all machine.
     blockinfile:
      dest: /tmp/fire.txt
      Block: | 


 *filter
    :INPUT   DROP   [0:0]
    :FORWARD DROP   [0:0]
    :OUTPUT  ACCEPT [0:0]
    -A INPUT -i lo -j ACCEPT
    -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
    -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
    -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
    -A INPUT -p udp --sport 53 -j ACCEPT
    -A INPUT -p tcp --dport 80   -j ACCEPT
    -A INPUT -p tcp --dport 443  -j ACCEPT
    -A INPUT -p tcp --dport 23   -j ACCEPT
    -A INPUT -p tcp --dport 22   -j ACCEPT
    -A INPUT -p tcp --dport 3260   -j ACCEPT --comment "Enable iscsi port"
    -A INPUT -p tcp --dport 119   -j ACCEPT --comment "Enable nfs TCP  port"
    -A INPUT -p tcp --dport 2049   -j ACCEPT --comment "Enable nfs UDP port"
    COMMIT
3

I see two (maybe three) issues with your playbook. The parameter Block does not exist, it is block with lower case b. Then the block is not correctly indented. You need to indent the block beyond the indentation of the block parameter. Also this will fail if the file /tmp/fire.txt doesn't exist.

Here is the playbook in a working form:

---
 - hosts: 1.1.0.1
   tasks:
   - name: putting /tmp/fire.txt File on all machine.
     blockinfile:
      dest: /tmp/fire.txt
      block: | 


       *filter
          :INPUT   DROP   [0:0]
          :FORWARD DROP   [0:0]
          :OUTPUT  ACCEPT [0:0]
          -A INPUT -i lo -j ACCEPT
          -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
          -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
          -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
          -A INPUT -p udp --sport 53 -j ACCEPT
          -A INPUT -p tcp --dport 80   -j ACCEPT
          -A INPUT -p tcp --dport 443  -j ACCEPT
          -A INPUT -p tcp --dport 23   -j ACCEPT
          -A INPUT -p tcp --dport 22   -j ACCEPT
          -A INPUT -p tcp --dport 3260   -j ACCEPT --comment "Enable iscsi port"
          -A INPUT -p tcp --dport 119   -j ACCEPT --comment "Enable nfs TCP  port"
          -A INPUT -p tcp --dport 2049   -j ACCEPT --comment "Enable nfs UDP port"
          COMMIT
  • D'oh, my mind completely filtered out the indentation for some reason,... – Rabban May 29 '17 at 7:08
0

Any specific reason you're using the blockinfile module as opposed to the saving the while file locally on your machine at /tmp/fire.txt and then using the copy module??

---
 - hosts: 1.1.0.1
   tasks:
    - name: putting /tmp/fire.txt File on all machine.
      copy:
          src: /tmp/fire.txt
          dest: /tmp/fire.txt

Otherwise, when you're using blockinfile, does the file actually exist on the destination?

  • i basically need to add this content on remote host,, but since it didnt work, so i tried it locally, but my goal is to add it at remote server /tmp/fire.txt file – Mohammed Ali May 29 '17 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.