0

I am runnning into this message when I do this :

ansible-playbook -i inventory junos_config_new.yml --check -vvv

ansible-playbook 2.9.9 config file = /etc/ansible/ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /root/.local/lib/python3.6/site-packages/ansible executable location = /usr/bin/ansible-playbook python version = 3.6.8 (default, Nov 21 2019, 19:31:34) [GCC 8.3.1 20190507 (Red Hat 8.3.1-4)] Using /etc/ansible/ansible.cfg as config file host_list declined parsing /home/gefela/ansible_junos/inventory as it did not pass its verify_file() method script declined parsing /home/gefela/ansible_junos/inventory as it did not pass its verify_file() method auto declined parsing /home/gefela/ansible_junos/inventory as it did not pass its verify_file() method Parsed /home/gefela/ansible_junos/inventory inventory source with ini plugin

PLAYBOOK: junos_config_new.yml ***************************************************************************************************************************** 1 plays in junos_config_new.yml

This is the playbook that I have ...

    name: Juniper SRX configuration compliance checks 
    hosts: juniper
    gather_facts: false
    connection: local
       tasks:
         - name: Syslog server checks 
           junos_config:
                 src: ~/ansible_junos/files/syslog_config.txt
             comment: Ensure that appropriate Syslog server configured 
           register: junos_output
         - debug:
             var: junos_output

         - name: success
             debug:
               msg: Syslog server check - This check has passed with the following output({{ junos_output }})
               when: not junos_output.changed 

         - name: failed
            debug:
              msg: Syslog server check - This check has failed with the following output({{ junos_output }})
             when: junos_output.changed 

         - name: Admin credentials check
            junos_config:
                   src: ~/ansible_junos/files/admin_user.txt
               comment: Ensure that Admin user havee been created
            register: junos_output
         - debug:
              var: junos_output

         - name: success
               debug:
                 msg: Admin credentials check - This check has passed with the following output({{ junos_output }})
                when: not junos_output.changed 

         - name: failed
              debug:
                msg: Admin credentials check - This check has failed with the following output({{ junos_output }})
               when: junos_output.changed 

The directory ~/ansible_junos/files/syslog_config.txt is in the right place Should ~/ansible_junos/files/ be the right place to place all the configuration to be compared against the firewall ?

Please let me know ..

tlo
  • 1,571
  • 1
  • 25
  • 38
user409817
  • 21
  • 6

3 Answers3

1

It's because ~ is a bash feature, and not an actual path component; your shell expands ~ to mean the home directory for the current user (or for the user named directly after the ~), however, ansible modules would have to go out of their way to use expanduser to behave like that.

You can try sending the filename through the | expanduser filter, or you may have to use gather_facts: true in order to have access to ansible_env.HOME

     - set_fact:
         config_directory: '{{ "~/ansible_junos/files" | expanduser }}'
     - name: Syslog server checks 
       junos_config:
         src: '{{ config_directory }}/syslog_config.txt'
         comment: Ensure that appropriate Syslog server configured 
       register: junos_output
mdaniel
  • 31,240
  • 5
  • 55
  • 58
  • [root@localhost ansible_junos]# ansible-playbook -i inventory junos_config_new.yml --check -vvv task path: /home/gefela/ansible_junos/junos_config_new.yml:10 fatal: [172.16.203.121]: FAILED! => { "changed": false, "msg": "path specified in src not found" } 172.16.203.121 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 – user409817 May 24 '20 at 19:11
  • - set_fact: config_directory: '{{ "home/gefela/ansible_junos/files" | expanduser }}' - name: Syslog server check junos_config: src: 'home/gefela/files/syslog_config.txt' comment: Ensure that appropriate Syslog server configured register: junos_output – user409817 May 24 '20 at 20:09
0

src jues need "admin_user.txt"

    - name: Admin credentials check
        junos_config:
               src: "admin_user.txt"
           comment: Ensure that Admin user havee been created
        register: junos_output

add you can add admin_user.txt in files/admin_user.txt

wangjin
  • 11
  • 1
  • It is still give me the same error message when I add src: "syslog.txt". When I make it junos_config: src: '{{ config_directory }}/syslog_config.txt' It gives me the error message "module_stdout": "\n{\"msg\": \"FileNotFoundError(2, 'No such file or directory')\", I have tried all these , no success yet – user409817 May 30 '20 at 10:48
0

I had to change the inventory file ( ansible_user and ansible_password ) and change this

  • set_fact: config_directory: '{{ "~/ansible_junos/files" | expanduser }}'
    • name: Syslog server checks junos_config: src: '{{ config_directory }}/syslog_config.txt' comment: Ensure that appropriate Syslog server configured register: junos_output

to

  • set_fact: config_directory: '{{ "/home/myfolder/ansible_junos/files" }}'
    • name: Syslog server checks junos_config: src: '{{ config_directory }}/syslog_config.txt' comment: Ensure that appropriate Syslog server configured register: junos_output
user409817
  • 21
  • 6