Discussion:
[ansible-project] run two command in one task
Roy
2015-07-13 14:58:13 UTC
Permalink
Hi,

I was trying to write simple task in ansible to create HDFS user hone
directory if it's not exist. So following is the task I wrote

- name: create user home dir in HDFS
shell: shell: "hadoop fs -test -d /user/{{ item.name }} || (hadoop fs
-mkdir /user/{{ item.name }} && hadoop fs -chown {{ item.name }} /user/{{
item.name }})"
when: "'hdfsuser' in {{ item.groups }} and '{{ inventory_hostname }}' in
['hadoop-client01.dev.abc.com']"
with_items: ssh_users
remote_user: hdfs
tags:
- hadoop


But I want to make it more simplified by breaking the shell command into
two.

so is it possible to have conditional dependent two commands in one single
task.

or is there better way to do this ?

Thanks
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/30983bf0-d5a5-44c1-a292-5d9af3dabdc6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Paul Markham
2015-07-19 04:27:50 UTC
Permalink
Maybe use register variables; something like:

- name: test user home dir in HDFS
shell: hadoop fs -test -d /user/{{ item.name }}
register: hadoop_dir

- name: create user home dir in HDFS
shell: hadoop fs -mkdir /user/{{ item.name }}
when: hadoop_dir|failed

- name: chown user home dir in HDFS
hadoop fs -chown {{ item.name }} /user/{{ item.name }})
when: hadoop_dir|failed
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c7eee9fa-26e8-4fc2-a719-19b14f33704f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...