Ansible Quick Guidance On AIX
Ansible Quick Guidance On AIX
Environment
master_node:
External IP: 169.48.22.141
Internal IP: 192.168.143.141
managed_node1:
External IP: 169.48.22.138
internal IP: 192.168.143.138
Preparation
1- Checking /etc/ssh/sshd_config
LogLevel DEBUG
PermitRootLogin yes
AuthorizedKeysFile .ssh/authorized_keys
Subsystem sftp /usr/sbin/sftp-server
PasswordAuthentication yes
# stopsrc -s sshd
# startsrc -s sshd
You can also enable and install the python36 application stream (or the
python27 application stream).
[root@managed_node1]# yum module install python
[root@managed_node1]# yum module install python36
[..]
[db-servers]
db1.example.com
db2.example.com
Or nested nested groups like the below:
[usa]
washington1.example.com
washington2.example.com
[canada]
ontario01.example.com
ontario02.example.com
[north-america:children]
canada
usa
Or even a range in your master_node inventory:
[usa]
washington[1:2].example.com
[canada]
ontario[01:02].example.com
# ansible --version
ansible 2.9.10
config file = /ansible_project/ansible.cfg
configured module search path = ['/.ansible/plugins/modules',
'/usr/share/ansible/plugins/modules']
ansible python module location = /opt/freeware/lib/python3.7/site-
packages/ansible
executable location = /usr/bin/ansible
python version = 3.7.9 (default, Sep 14 2020, 06:09:55) [GCC 8.3.0]
Check ansible master_node hosts and attempt ad-hoc commands
# cd /etc/ansible_project
# ansible all --list-hosts
hosts (1):
managed_node1
# ansible AIX_HOSTS --list-hosts
hosts (1):
managed_node1
Modules are the tools that ad hoc commands use to accomplish tasks.
Ansible provides hundreds of modules which do different things.
You can usually find a tested, special-purpose module that does what
you need as part of the standard installation.
- Checking IP addresses:
# ansible all -m shell -a 'ifconfig -a'
managed_node1 | CHANGED | rc=0 >>
en0:
flags=1e084863,814c0<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLE
X,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),LARGESE
inet 192.168.143.138 netmask 0xfffffff8 broadcast 192.168.143.143
en1:
flags=1e084863,814c0<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLE
X,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),LARGESE
lo0:
flags=e08084b,c0<UP,BROADCAST,LOOPBACK,RUNNING,SIMPLEX,MUL
TICAST,GROUPRT,64BIT,LARGESEND,CHAIN>
inet 127.0.0.1 netmask 0xff000000 broadcast 127.255.255.255
- Copying /etc/hosts with another name:
# ansible all -m copy -a "src=/etc/hosts dest=/etc/hosts.$(date
+'%m%d')"
managed_node1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"checksum": "bbf3711f44da38c3326bf02a5f4ffabd89cafa85",
"dest": "/etc/hosts.1110", #####<<==========
"gid": 0,
"group": "system",
"md5sum": "b1ff6ce99b6047a18cc47168f71b1c5c",
"mode": "0644",
"owner": "root",
"size": 2101,
"src": "/.ansible/tmp/ansible-tmp-1605015730.7945442-5374244-
264973000993393/source",
"state": "file",
"uid": 0
}
https://docs.ansible.com/ansible/2.9/modules/net_ping_module.html
* Module win_ping
The official documentation on the win_ping module.
https://docs.ansible.com/ansible/2.9/modules/win_ping_module.html
AUTHOR: Ansible Core Team, Michael DeHaan
METADATA:
status:
- stableinterface
supported_by: core
EXAMPLES:
# Test we can logon to 'webservers' and execute python with json lib.
# ansible webservers -m ping
# Example from an Ansible Playbook
- ping:
# Induce an exception to see what happens
- ping:
data: crash
RETURN VALUES:
ping:
description: value provided with the data parameter
returned: success
type: str
sample: pong
YAML playbooks
##########################################################
WRITING_PLAY_BOOK_FOR_USER_CREATION
##########################################################
- name: Create user
hosts: all
tasks:
- name: Add the user 'mash' with a bash shell, appending the group
'staff' and 'security' to the user's groups
user:
name: mash
comment: Ahmed Mashhour
uid: 1040
shell: /usr/bin/bash
groups: staff,security
append: yes
password:
"{ssha512}06$cQR6AB1peJePClfd$1nPY3QfFkPMWR9iu2WXgxVmM8w
Oy/qQjBcX9awgwszDRDa7qtQpRB1N7v7iGsnO7.tTDF6you.FiLU2TUK5S.
."
<<Where the above password is an encryption of 123456, so the
password will be 123456>>
#####################RUNNING_THE_PLAY_BOOK##############
# ansible-playbook my_user.yml --syntax-check
playbook: user_create.yml
# ansible-playbook user_create.ym
PLAY [Create user]
**********************************************************
ok: [managed_node1]
TASK [Add the user 'mash' with a bash shell, appending the group 'staff'
and 'security' to the user's groups] ***
changed: [managed_node1]
PLAY RECAP
**********************************************************
managed_node1 : ok=2 changed=1 unreachable=0 failed=0
skipped=0 rescued=0 ignored=0
#####################RUNNING_THE_PLAY_BOOK##############
# ansible-playbook mksysb.yml --syntax-check
playbook: mksysb1.yml
# ansible-playbook flrt.yml
PLAY [FLRT]
ok: [managed_node1]
ok: [managed_node1]
[..]
managed_node1 : ok=2 changed=0 unreachable=0 failed=0
skipped=0 rescued=0 ignored=0
##########################################################
WRITING_PLAY_BOOK_FOR_MOUNTING_NFS
##########################################################
- name: Mount a file system
hosts: all
tasks:
- name: Mount NFS share
mount:
node: 192.168.143.141
mount_dir: /usr/sys/inst.images/installp/ppc
mount_over_dir: /my_nfs_dir
#####################RUNNING_THE_PLAY_BOOK##############
# ansible-playbook nfs_mount.yml --syntax-check
playbook: nfs_mount.yml
# ansible-playbook nfs_mount.yml
PLAY [Mount a file system]
ok: [managed_node1]
TASK [Mount NFS share]
changed: [managed_node1
managed_node1 : ok=2 changed=1 unreachable=0 failed=0
skipped=0 rescued=0 ignored=0
##########################################################
WRITING_PLAY_BOOK_FOR_INSTALLP
##########################################################
- name: Install filesets
hosts: all
tasks:
- name: Install selected Java filesets and expand file systems if
necessary
installp:
extend_fs: yes
agree_licenses: yes
# dependencies: yes
device: /my_nfs_dir
# updates_only: yes
force: yes
install_list: Java8_64.jre,Java8_64.sdk
#####################RUNNING_THE_PLAY_BOOK##############
# ansible-playbook installp.yml --syntax-check
playbook: installp.yml
# ansible-playbook installp.yml
[..]
managed_node1 : ok=2 changed=0 unreachable=0 failed=0
skipped=0 rescued=0 ignored=0
Dealing with a collective YAML playbooks
You can have one collective YML file, like the following example:
# cat collective1.yml
###################COLLECTIVE1.YML_FILE_START##############
- name: Collective1 Playbook
hosts: all
tasks:
- name: Add the user 'mash' with a bash shell, appending the group
'staff' and 'security' to the user's groups
user:
name: mash
comment: Ahmed Mashhour
uid: 1040
shell: /usr/bin/bash
groups: staff,security
append: yes
password:
"{ssha512}06$cQR6AB1peJePClfd$1nPY3QfFkPMWR9iu2WXgxVmM8w
Oy/qQjBcX9awgwszDRDa7qtQpRB1N7v7iGsnO7.tTDF6you
.FiLU2TUK5S.."
- name: Create a backupvg volume group
aix_lvg:
vg: backupvg
pp_size: 128
vg_type: scalable
pvs: "{{ hdisk }}"
state: present
- If you want to only run only a certain task inside a playbook, you can
use tags. See example below:
# cat collective2.yml
##################COLLECTIVE2.YML_FILE_START###############
- name: Collective2 Playbook
hosts: all
tasks:
- name: Add the user 'mash' with a bash shell, appending the group
'staff' and 'security' to the user's groups
user:
name: mash
comment: Ahmed Mashhour
uid: 1040
shell: /usr/bin/bash
groups: staff,security
append: yes
password:
"{ssha512}06$cQR6AB1peJePClfd$1nPY3QfFkPMWR9iu2WXgxVmM8w
Oy/qQjBcX9awgwszDRDa7qtQpRB1N7v7iGsnO7.tTDF6you.FiLU2TUK5S.
."
tags: mash user create