ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Ansible 2.4.2.0 on CentOS 7--ping module isn't working

    IT Discussion
    ansible
    6
    33
    3.3k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • wirestyle22W
      wirestyle22
      last edited by wirestyle22

      I have three test VM's setup for Ansible. All are CentOS 7 minimal VM's. Ansible is clientless, connects via ssh or winrm depending on the OS.

      1. controller (IP: 192.168.1.207)
      2. ansible-target1 (IP: 192.168.1.208)
      3. ansible-target2 (IP: 192.168.1.209)

      I installed nano on each VM.

      #Edited the hosts file of each VM

      1. controller
        nano /etc/hosts
        127.0.0.1 localhost controller
        ::1 localhost controller
        192.168.1.208 ansible-target1
        192.168.1.209 ansible-target2
        reboot

      2. ansible-target1
        nano /etc/hosts
        127.0.0.1 localhost ansible-target1
        ::1 localhost ansible-target1
        reboot

      3. ansible-target2
        nano /etc/hosts
        127.0.0.1 localhost ansible-target2
        ::1 localhost ansible-target2
        reboot

      #Install ansible on the controller
      yum -y install ansible

      #check that is it running
      ansible --version

      ansible 2.4.2.0
        config file = /etc/ansible/ansible.cfg
        configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
        ansible python module location = /usr/lib/python2.7/site-packages/ansible
        executable location = /usr/bin/ansible
        python version = 2.7.5 (default, Jul 13 2018, 13:06:57) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]
      

      #SSH into each target machine

      ssh 192.168.1.208 or hostname
      ssh 192.168.1.209 or hostname

      This succeeded.

      I need to setup my inventory file on the controller.
      cat > inventory
      ansible-target1 ansible_host=192.168.1.208 ansible_ssh_pass=sshpass

      #try to ping through Ansible
      ansible ansible-target1 ansible_host=192.168.1.208 -m ping -i inventory

      This should succeed, but it doesn't. Instead it says:

      [WARNING]: Unable to parse /etc/ansible/inventory as an inventory source
      
       [WARNING]: No inventory was parsed, only implicit localhost is available
      
       [WARNING]: Could not match supplied host pattern, ignoring: all
      
       [WARNING]: provided hosts list is empty, only localhost is available
      
       [WARNING]: Could not match supplied host pattern, ignoring: ansible-target1
      
       [WARNING]: No hosts matched, nothing to do
      

      Treating it like its in the wrong location but its not. ls -l shows it in /etc/ansible/

      1 Reply Last reply Reply Quote 0
      • black3dynamiteB
        black3dynamite
        last edited by

        In /etc/ansible/production

        [library]
        SL-LIBRARY # station 2
        

        This is what I do for pinging Windows clients
        ansible SL-LIBRARY -i production -m win_ping

        wirestyle22W 1 Reply Last reply Reply Quote 0
        • wirestyle22W
          wirestyle22 @black3dynamite
          last edited by wirestyle22

          @black3dynamite said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

          In /etc/ansible/production

          [library]
          SL-LIBRARY # station 2
          

          This is what I do for pinging Windows clients
          ansible SL-LIBRARY -i production -m win_ping

          I am pinging linux hosts.

          linux is ssh and windows is winrm

          1 Reply Last reply Reply Quote 0
          • black3dynamiteB
            black3dynamite
            last edited by

            You either have to change to the directory where your inventory file is or use this command instead.

            ansible <hostname> -i /etc/ansible/inventory -m ping

            wirestyle22W 1 Reply Last reply Reply Quote 0
            • wirestyle22W
              wirestyle22 @black3dynamite
              last edited by wirestyle22

              @black3dynamite That looks so weird to me

              shouldn't the host be ansible_host=hostname ? Did they change that?

              black3dynamiteB matteo nunziatiM 2 Replies Last reply Reply Quote 0
              • black3dynamiteB
                black3dynamite @wirestyle22
                last edited by

                @wirestyle22 said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                @black3dynamite That looks so weird to me

                shouldn't the host be ansible_host=hostname ? Did they change that?

                You are getting the error message about it not finding the inventory file.

                Try this:

                ansible ansible-target1 ansible_host=192.168.1.208 -m ping -i /etc/ansible/inventory

                1 Reply Last reply Reply Quote 0
                • ObsolesceO
                  Obsolesce
                  last edited by

                  You should give SaltStack a go as well. I think it's quite a bit easier to use.

                  1 Reply Last reply Reply Quote 1
                  • matteo nunziatiM
                    matteo nunziati @wirestyle22
                    last edited by

                    @wirestyle22 said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                    @black3dynamite That looks so weird to me

                    shouldn't the host be ansible_host=hostname ? Did they change that?

                    Please post your inventory well formatted as code. It should contain a list of targets and should be passed to ansible with the -i flag. Also check the docs: https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html

                    wirestyle22W 1 Reply Last reply Reply Quote 1
                    • stacksofplatesS
                      stacksofplates
                      last edited by stacksofplates

                      Dont' pass ansible_host= in the command line. That's defined in your inventory file. You also don't need to add that in your inventory file at all since you've defined it in your /etc/hosts file. I never add the password in the inventory. If I don't have a key on the other end I just pass -k in the command. So you would do this:

                      ansible -i inventory ansible-target1 -m ping -k
                      

                      Also make sure every host is on a separate line in your inventory. I noticed you only did > instead of >>. You could have only put one host in, but figured I'd mention it just in case.

                      wirestyle22W 1 Reply Last reply Reply Quote 3
                      • stacksofplatesS
                        stacksofplates
                        last edited by

                        Also 2.4.2 is kind of old. Some things are being deprecated soon, so you will want to either install from EPEL or use pip to pull in a newer version.

                        scottalanmillerS 1 Reply Last reply Reply Quote 0
                        • scottalanmillerS
                          scottalanmiller @stacksofplates
                          last edited by

                          @stacksofplates said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                          Also 2.4.2 is kind of old. Some things are being deprecated soon, so you will want to either install from EPEL or use pip to pull in a newer version.

                          Another "CentOS problem" that "doesn't exist" 😉

                          stacksofplatesS 1 Reply Last reply Reply Quote 0
                          • stacksofplatesS
                            stacksofplates @scottalanmiller
                            last edited by stacksofplates

                            @scottalanmiller said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                            @stacksofplates said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                            Also 2.4.2 is kind of old. Some things are being deprecated soon, so you will want to either install from EPEL or use pip to pull in a newer version.

                            Another "CentOS problem" that "doesn't exist" 😉

                            Well it's weird. Idk if CentOS hasn't caught up with RHEL yet or what's going on. Ansible is at 2.7 in RHEL. I have no idea why it's lagging so far behind in CentOS.

                            scottalanmillerS 1 Reply Last reply Reply Quote 0
                            • scottalanmillerS
                              scottalanmiller @stacksofplates
                              last edited by

                              @stacksofplates said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                              @scottalanmiller said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                              @stacksofplates said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                              Also 2.4.2 is kind of old. Some things are being deprecated soon, so you will want to either install from EPEL or use pip to pull in a newer version.

                              Another "CentOS problem" that "doesn't exist" 😉

                              Well it's weird. Idk if CentOS hasn't caught up with RHEL yet. Ansible is at 2.7 in RHEL. I have no idea why it's lagging so far behind in CentOS.

                              oh, weird.

                              stacksofplatesS 1 Reply Last reply Reply Quote 0
                              • stacksofplatesS
                                stacksofplates @scottalanmiller
                                last edited by

                                @scottalanmiller said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                                @stacksofplates said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                                @scottalanmiller said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                                @stacksofplates said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                                Also 2.4.2 is kind of old. Some things are being deprecated soon, so you will want to either install from EPEL or use pip to pull in a newer version.

                                Another "CentOS problem" that "doesn't exist" 😉

                                Well it's weird. Idk if CentOS hasn't caught up with RHEL yet. Ansible is at 2.7 in RHEL. I have no idea why it's lagging so far behind in CentOS.

                                oh, weird.

                                But even Fedora lags behind a little. It's getting better but I've seen it as far as 2 releases behind before.

                                matteo nunziatiM 1 Reply Last reply Reply Quote 0
                                • wirestyle22W
                                  wirestyle22 @matteo nunziati
                                  last edited by wirestyle22

                                  @matteo-nunziati said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                                  @wirestyle22 said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                                  @black3dynamite That looks so weird to me

                                  shouldn't the host be ansible_host=hostname ? Did they change that?

                                  Please post your inventory well formatted as code. It should contain a list of targets and should be passed to ansible with the -i flag. Also check the docs: https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html

                                  This is a basic ping check with a basic inventory file. Originally it was this but I have removed the ssh password portion.

                                  ansible-target1 ansible_host=192.168.1.208 ansible_ssh_pass=password
                                  ansible-target2 ansible_host=192.168.1.209 ansible_ssh_pass=password
                                  
                                  1 Reply Last reply Reply Quote 0
                                  • wirestyle22W
                                    wirestyle22 @stacksofplates
                                    last edited by wirestyle22

                                    @stacksofplates said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                                    Dont' pass ansible_host= in the command line. That's defined in your inventory file. You also don't need to add that in your inventory file at all since you've defined it in your /etc/hosts file. I never add the password in the inventory. If I don't have a key on the other end I just pass -k in the command. So you would do this:

                                    ansible -i inventory ansible-target1 -m ping -k
                                    

                                    Also make sure every host is on a separate line in your inventory. I noticed you only did > instead of >>. You could have only put one host in, but figured I'd mention it just in case.

                                    God you're handsome.

                                    0_1540659890758_ping.PNG

                                    Time to screw around with YAML.

                                    1 Reply Last reply Reply Quote 0
                                    • ObsolesceO
                                      Obsolesce
                                      last edited by

                                      Or in Salt:

                                      salt pcname test.ping

                                      stacksofplatesS 1 Reply Last reply Reply Quote 0
                                      • stacksofplatesS
                                        stacksofplates @Obsolesce
                                        last edited by stacksofplates

                                        @Obsolesce said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                                        Or in Salt:

                                        salt pcname test.ping

                                        It's much simpler if you have your ansible.cfg and keys set up. Then it's just ansible server -m ping.

                                        This is like trying to use Salt without having certs set up (or SSH keys in the case of salt-ssh)

                                        ObsolesceO 1 Reply Last reply Reply Quote 0
                                        • ObsolesceO
                                          Obsolesce @stacksofplates
                                          last edited by

                                          @stacksofplates said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                                          @Obsolesce said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                                          Or in Salt:

                                          salt pcname test.ping

                                          It's much simpler if you have your ansible.cfg and keys set up. Then it's just ansible server -m ping.

                                          This is like trying to use Salt without having certs set up (or SSH keys in the case of salt-ssh)

                                          If you want to use ssh as a transport, but not needed or why you'd choose Salt. If that's the case then I'd rather want to use Ansible.

                                          stacksofplatesS 1 Reply Last reply Reply Quote 0
                                          • stacksofplatesS
                                            stacksofplates @Obsolesce
                                            last edited by

                                            @Obsolesce said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                                            @stacksofplates said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                                            @Obsolesce said in Ansible 2.4.2.0 on CentOS 7--ping module isn't working:

                                            Or in Salt:

                                            salt pcname test.ping

                                            It's much simpler if you have your ansible.cfg and keys set up. Then it's just ansible server -m ping.

                                            This is like trying to use Salt without having certs set up (or SSH keys in the case of salt-ssh)

                                            If you want to use ssh as a transport, but not needed or why you'd choose Salt. If that's the case then I'd rather want to use Ansible.

                                            I want saying you should. Just once things are set up properly they are both (Ansible and Salt) very similar in ease of use.

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • First post
                                              Last post