Guest User

Untitled

a guest
Apr 26th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. ## `tasks`
  2. ```
  3. - apt: pkg=vim state=present # task one-line
  4. ```
  5.  
  6. ```
  7. - apt:
  8. pkg: vim
  9. state: present
  10. ```
  11. ```
  12. - hosts:all
  13. user: root
  14. sudo: no
  15. vars:
  16. aaa: "bbb"
  17. tasks:
  18. -
  19. ```
  20. ## tasks `failures`
  21. ```
  22. - name: my task
  23. command: my_command
  24. register: result
  25. failed_when: "'FAILED' in result.stderr"
  26. ignore_errors: yes
  27. change_when: "result.rc != 2"
  28. ```
  29.  
  30. ## `include`
  31. ```
  32. tasks:
  33. - include: db.yml
  34.  
  35. handlers:
  36. - include: db.yml user=timo
  37. ```
  38.  
  39. ## `handlers`
  40. ```
  41. handlers:
  42. - name: start apache2
  43. action: service name=apache2 state=started
  44.  
  45. tasks:
  46. - namne: install apache
  47. action: apt pkg=apache2 state=latest
  48. notify: start apache2
  49. ```
  50.  
  51. ## `vars`
  52. ```
  53. - host: development
  54. vars_files:
  55. - vars.yml
  56. vars:
  57. project_root: /var/www/virtual
  58. tasks:
  59. - name: Create the SSH directory
  60. file:
  61. - state: directory
  62. - path: "{{project_root}}/home/.ssh"
  63. only_if: "$vm == 0"
  64. ```
  65. ## `Env vars`
  66. ```
  67. vars:
  68. local_name: "{{ lookup('env', 'HOME') }}"
  69. ```
  70.  
  71.  
  72. ## `roles`
  73. ```
  74. roles/
  75. common/
  76. tasks/
  77. handlers/
  78. files/ # `copy` will refer to this folder
  79. templates/ # `template` will refer to this folder
  80. meta/ # role dependencies here
  81. vars/
  82. defaults/
  83. main.yml
  84. ```
  85.  
  86. ```
  87. - host: xxx
  88. roles:
  89. - db
  90. - web
  91. # roles/db/tasks/*.yml
  92. # roles/web/handlers/*.yml
  93. ```
  94. ## `become`
  95. to become another user, the default value of `become_user` is `root`
  96. ```
  97. - name: ensure the nginx is running as the vagrant user
  98. service:
  99. name: nginx
  100. state: started
  101. become: true
  102. become_method: sudo
  103. become_user: vagrant
  104. ```
  105.  
  106. ## `user`
  107. ```
  108. # Add the user 'vagrant' with a specific uid and a primary group of 'admin'
  109. - user:
  110. name: vagrant
  111. comment: "John Doe"
  112. uid: 1040
  113. group: admin
  114.  
  115. # Add the user 'james' with a bash shell, appending the group 'admins' and 'developers' to the user's groups
  116. - user:
  117. name: james
  118. shell: /bin/bash
  119. groups: admins,developers
  120. append: yes
  121.  
  122. # Remove the user 'john'
  123. - user:
  124. name: john
  125. state: absent
  126. remove: yes
  127.  
  128. # Create a 2048-bit SSH key for user jsmith in ~jsmith/.ssh/id_rsa
  129. - user:
  130. name: jsmith
  131. generate_ssh_key: yes
  132. ssh_key_bits: 2048
  133. ssh_key_file: .ssh/id_rsa
  134.  
  135. # added a consultant whose account you want to expire
  136. - user:
  137. name: james18
  138. shell: /bin/zsh
  139. groups: developers
  140. expires: 1422403387
  141. ```
  142.  
  143. ## Common used `ansible` modules
  144.  
  145.  
  146.  
  147.  
  148. - pre_tasks:
  149. - register:
  150. - assert:
  151. - with_items:
  152.  
  153. - roles:
  154. - handlers:
  155. - service:
Add Comment
Please, Sign In to add comment