Quick Reference

1) Command (module) – It is used to execute commands on remote server ( Eg:  Date, df –h, uptime…)

2) remote_user: the name of the user account used to log into the remote servers.

3) become_user : user name to become after logging in to the remote server. Eg: After logging into the remote server as root then we need to become oracle to run some programs

4) become : conrol flag to either activate or deactivate privilege escalation.

5) How to call variable : Use double curley braces to call variable {{ variable_name }}

6) filter=ansible_local" : To filter only local facts in setup module output

7) The format for retriving local fact is :
# ansible_local.<local fact file name>.<groupname>.<keyname>

8) with_file : Iterates over the content of a list of files, item will be set to the content of each file in sequence. 

9) with_fileglob : Matches all files in a single directory.
eg: with_fileglob:
        - "/playbooks/files/fooapp/*

10) Notify : Notify is something used to notify the handlers. In simple words I have done some changes now to which handlers task i need to inform about service restart

11) Handlers : Handlers are lists of tasks that will run only when it is notified by "notify" module. These names of handlers are unique. It will work like task only but the only difference is task will run on own but handlers will execute when it gets a notification. 

12) Lookup CSV file:  lookup('csvfile', 'key arg1=val1 arg2=val2 '). file - Name of the file to load. col – 1 The column to output, indexed by 0.

b) File - "{{ lookup('file', '/etc/one.txt') }}"

13) hostvars - To retrive variables from other host Syn: "{{ hostvars['HN']['VAR_NAME'] }}"; eg: "{{ hostvars['l0202']['ansible_distribution'] }}"

14) In debug module :  var - A variable name to debug. Mutually exclusive with the 'msg' option.

15) ansible-playbook -e Option is for: -e VARS, --extra-vars=VARS

Extra variables to inject into a playbook, in key=value key=value format

16) ansible {{group}} --list-hosts- List hosts belonging to a group

17) ansible-doc -l : - To List all the installed modules.

No comments:

Post a Comment