0
votes

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 ..

3

3 Answers

1
votes

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
0
votes

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

0
votes

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