Showing posts with label ansible. Show all posts
Showing posts with label ansible. Show all posts

 Ansible.cfg Best Practice

                            

Ansible.cfg is the important parameters to control how Ansible and ansible-playbook behaves.

The following parameters are best practice, please put it to the same folder as ansible.cfg file.


Reference:  

https://www.ansible.com/blog/using-ansible-to-manage-rhel-5-yesterday-today-and-tomorrow

https://docs.ansible.com/ansible/latest/reference_appendices/config.html 


[ssh_connection]
ssh_args = '-o ControlMaster=auto -o ControlPersist=60s  -o ServerAliveInterval=60 -o ServerAliveCountMax=10 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
retries=5
pipelining = True

[defaults]
command_warnings=False
host_key_checking = false
timeout = 60
remote_tmp = /tmp

How to install ansible2.11 with python36 on RHEL7

                                  by Jephe Wu - http://linuxtechres.blogspot.com


Install python36 packages from subscription or RHEL7.9 ISO

[root@test ]# more /etc/yum.repos.d/local.repo
[localrepo]
name=Unixmen Repository
baseurl=file:///cdrom
gpgcheck=0
enabled=1

yum localinstall python3 python3-pip python3-rpm-generators python3-rpm-macros python3 python3-setuptools

    

Use EPEL

[root@test ]# grep proxy /etc/yum.conf
proxy=http://proxy.domain.com:8080

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

 

use pip3 to install ansible

pip3 install --upgrade pip

pip3 cache purge

export LANG=en_AU.UTF8

pip3 install ansible   ( or python3 -m pip install ansible )

pip3 install pywinrm

 

Check if win_ modules are there

run ansible-doc win_reboot

find /user/local/  -name "win_*"

 

 

[root@test unixadm]# pip3 install pywinrm
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Collecting pywinrm
Downloading pywinrm-0.4.2-py2.py3-none-any.whl (44 kB)
|████████████████████████████████| 44 kB 920 kB/s
Collecting requests>=2.9.1
Downloading requests-2.26.0-py2.py3-none-any.whl (62 kB)
|████████████████████████████████| 62 kB 1.2 MB/s
Collecting six
Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting xmltodict
Downloading xmltodict-0.12.0-py2.py3-none-any.whl (9.2 kB)
Collecting requests-ntlm>=0.3.0
Downloading requests_ntlm-1.1.0-py2.py3-none-any.whl (5.7 kB)
Collecting charset-normalizer~=2.0.0
Downloading charset_normalizer-2.0.9-py3-none-any.whl (39 kB)
Collecting certifi>=2017.4.17
Downloading certifi-2021.10.8-py2.py3-none-any.whl (149 kB)
|████████████████████████████████| 149 kB 28.9 MB/s
Collecting urllib3<1.27,>=1.21.1
Downloading urllib3-1.26.7-py2.py3-none-any.whl (138 kB)
|████████████████████████████████| 138 kB 37.7 MB/s
Collecting idna<4,>=2.5
Downloading idna-3.3-py3-none-any.whl (61 kB)
|████████████████████████████████| 61 kB 11.2 MB/s
Requirement already satisfied: cryptography>=1.3 in /usr/local/lib64/python3.6/site-packages (from requests-ntlm>=0.3.0->pywinrm) (36.0.0)
Collecting ntlm-auth>=1.0.2
Downloading ntlm_auth-1.5.0-py2.py3-none-any.whl (29 kB)
Requirement already satisfied: cffi>=1.12 in /usr/local/lib64/python3.6/site-packages (from cryptography>=1.3->requests-ntlm>=0.3.0->pywinrm) (1.15.0)
Requirement already satisfied: pycparser in /usr/local/lib/python3.6/site-packages (from cffi>=1.12->cryptography>=1.3->requests-ntlm>=0.3.0->pywinrm) (2.21)
Installing collected packages: urllib3, idna, charset-normalizer, certifi, requests, ntlm-auth, xmltodict, six, requests-ntlm, pywinrm
WARNING: The script normalizer is installed in '/usr/local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed certifi-2021.10.8 charset-normalizer-2.0.9 idna-3.3 ntlm-auth-1.5.0 pywinrm-0.4.2 requests-2.26.0 requests-ntlm-1.1.0 six-1.16.0 urllib3-1.26.7 xmltodict-0.12.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

 

Note: pip3 will download packages from site below

 

Installing Ansible with winrm module for Windows server automation

                    by Jephe Wu - http://linuxtechres.blogspot.com

Steps

set proxy for /etc/yum.conf

proxy= http://proxy.domain.com:8080

Disable redhat registration

[root@ansible01 pluginconf.d]# grep enabled /etc/yum/pluginconf.d/subscription-manager.conf

enabled=0

Install EPEL release for yum repo

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Download and install ansible packages from EPEL together with local RHEL7 ISO mount

yum localinstall *  => install all below packages



Testing playbook


[root@ansible01 ~]# more hosts.ini
[win:vars]
ansible_user='DOMAIN\jephe'
ansible_password=xxxxxxxxxxx
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore
#ansible_winrm_scheme=http
ansible_port=5985
#ansible_winrm_transport=kerberos
#ansible_winrm_transport=credssp
ansible_winrm_transport=ntlm

[win]
192.168.1.10

root@ansible01 ~]# ansible -i hosts.ini win  -m win_ping

192.168.1.10 | SUCCESS => {
    "changed": false,
    "ping": "pong"

}

[root@ansible01 ~]# more win_play.yml
---

- name: test
  hosts: all
  become_method: runas

  tasks:

    - name: whoami

      win_shell: mkdir c:\tmp\jewu2

[root@ansible01 ~]# ansible-playbook -i hosts.ini win_play.yml

PLAY [test] ****************************************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************************
ok: [192.168.1.10]

TASK [whoami] **************************************************************************************************************************************
changed: [192.168.1.10]

PLAY RECAP *****************************************************************************************************************************************

192.168.1.10              : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
===============