It has become much more convenient (my writing style is older) than the old version, so a memo when I switched the management of my dot file to ansible and tried various things
Looking at various repositories, it seems that ansible is written with various directory structures, but the official document [Directory layout](http://docs.ansible.com/ansible/playbooks_best_practices.html#directory- Since it is described in layout), let's write (or aim) with a directory structure that refers to it
There are various problems that cannot be solved by modules alone.
Although described in
If it's a playbook you wrote, this is a changed you don't have to worry about. You can judge immediately by looking at the execution result of ansible, but if you get a changed when someone else executes this playbook, you will be wondering, "Oh, has something changed?" I think it is desirable that changed becomes changed only when the behavior of the target OS changes.
If you do not do so, changed will become scary, and you will not be able to write common tasks for production, staging, develop, etc., and you will enter the process of completing tasks according to each environment. At that point, the "secret sauce" should be quite advanced. I feel idempotent for what, but I don't know.
It's a speedy story, but from changed_when [when](http://docs.ansible. com / ansible / playbooks_error_handling.html # controlling-what-defines-failure) often feels faster to run playbooks, so use when (Maybe chaged_when feels like it's doing an action and then a when decision. I'm sorry if it's wrong.)
For example, if you limit the target OS to OS X when writing the task to install nkf, you would write like this
roles/nkf/install/tasks/main.yml
- name: Install the nkf from homebrew
homebrew: name=nkf state=present
But nkf is also necessary for guest OS, right? If you write this so that you do not create useless roles when it happens, you can guarantee the same operation to different OS with one role.
roles/nkf/install/tasks/main.yml
- name: Install the nkf from homebrew
homebrew: name=nkf state=present
when: "ansible_os_family == 'Darwin'"
- name: Install the nkf from yum
yum: pkg=nkf state=present
when: "ansible_os_family == 'RedHat'"
`fail_when: no`
rather than ignore_errosThere is ignore_errors because you can ignore it even if an error occurs.
"disgusting····"
Or rather, if ignore_errors occurs when running the playbook, failed is displayed on the display.
Something red appears on the console, even if it's not ansible.
What you want to do with ignore_errors is to ignore fail, so if you ignore it, don't cause fail
failed_when: no
Let's write. That way you won't get failed on the console.
For example, chrome is required when installing chrome-cli that operates chrome with CUI.
The way to write the task in that case is like this
roles/homebrew/brew/chrome-cli/tasks/main.yml
- name: Install the chrome-cli in the brew.
homebrew: name=chrome-cli state=present
when: "ansible_os_family == 'Darwin'"
Just install chrome-cli with homebrew
roles/homebrew/brew-cask/google-chrome/tasks/main.yml
- name: Install the google-chrome in the brew-cask
homebrew_cask: name=google-chrome state=present
when: "ansible_os_family == 'Darwin'"
Just install google-chrome with homebrew-cask
homebrew/brew/chrome-cli/meta/main.yml
dependencies:
- { role: homebrew/brew-cask/google-chrome }
chrome-cli
├── meta
│ └── main.yml
└── tasks
└── main.yml
google-chrome
└── tasks
└── main.yml
Write two roles and describe the dependencies in meta
As the title says. For personal notes
I often forget this and look at the documentation of the ansible module, so my memo
If you look at the above examples, you can do most of the things.
I will add it if there is an additional note.
Recommended Posts