Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rb:ansible [13/06/2019 12:07]
andrew [Installing Ansible]
rb:ansible [16/09/2019 18:11] (current)
andrew [Manipulate login shell]
Line 192: Line 192:
  
  
 +===== Conditional code =====
 +
 +<code yaml>
 +- name: Create home directory for cwagent (RedHat Linux)
 +  file:
 +    path:  /​home/​cwagent
 +    state: directory
 +    owner: cwagent
 +    group: cwagent
 +    mode:  0750
 +  when: ansible_distribution_file_variety == "​RedHat"​
 +  ​
 +</​code>​
 +
 +===== Manipulate login shell =====
 +
 +<code yaml>
 +- name: change user default shell to no-login
 +  user:
 +    name: cwdeviceuser
 +    shell: /​sbin/​nologin
 +</​code>​
 +
 +
 +
 +
 +
 +====== Examples ======
 +
 +Set up a hosts file for ansible with sections for each group of hosts
 +<​code>​
 +$ cat hosts-ansible.ans ​
 +[webServers]
 +amazonlinux02
 +amazonlinux03
 +
 +[databaseServers]
 +amazonlinux03 ​
 +</​code>​
 +
 +Run ansible directly (without playbook) to run remote command to install package:-
 +<​code>​
 +$ ansible -i hosts-ansible.ans -u ec2-user --sudo --private-key ansible_id_rsa webServers -a "rpm -q postfix"​
 +amazonlinux02 | SUCCESS | rc=0 >>
 +postfix-2.10.1-6.amzn2.0.1.x86_64
 +
 +amazonlinux03 | SUCCESS | rc=0 >>
 +postfix-2.10.1-6.amzn2.0.1.x86_64
 +
 +andrew@puppet:​~/​ansible$ ​
 +</​code>​

rb/ansible.1560424026.txt.gz ยท Last modified: 13/06/2019 12:07 by andrew